staging: zsmalloc: fix memory leak
diff mbox series

Message ID 1333376036-9841-1-git-send-email-sjenning@linux.vnet.ibm.com
State New, archived
Headers show
Series
  • staging: zsmalloc: fix memory leak
Related show

Commit Message

Seth Jennings April 2, 2012, 2:13 p.m. UTC
From: Nitin Gupta <ngupta@vflare.org>

This patch fixes a memory leak in zsmalloc where the first
subpage of each zspage is leaked when the zspage is freed.

Based on 3.4-rc1.

Signed-off-by: Nitin Gupta <ngupta@vflare.org>
Acked-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
---
 drivers/staging/zsmalloc/zsmalloc-main.c |   30 ++++++++++++++++++------------
 1 files changed, 18 insertions(+), 12 deletions(-)

Comments

Greg Kroah-Hartman April 9, 2012, 9:43 p.m. UTC | #1
A: No.
Q: Should I include quotations after my reply?

http://daringfireball.net/2007/07/on_top

On Mon, Apr 09, 2012 at 03:23:38PM -0500, Seth Jennings wrote:
> Hey Greg,
> 
> Haven't heard back from you on this patch and it needs to
> get into the 3.4 -rc releases ASAP.  It fixes a substantial
> memory leak when frontswap/zcache are enabled.
> 
> Let me know if you need me to repost.
> 
> The patch was sent on 4/2.

5 meager days ago, with a major holliday in the middle, not to mention a
conference as well.  That's bold.

It is not lost, is in my queue, and will get to Linus before 3.4-final
comes out, don't worry.

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Seth Jennings April 9, 2012, 10:06 p.m. UTC | #2
On 04/09/2012 04:43 PM, Greg Kroah-Hartman wrote:
> A: No.
> Q: Should I include quotations after my reply?
> 
> http://daringfireball.net/2007/07/on_top

Noted. I only included what I did to keep the Ack chain in the
message, which I guess was unnecessary.

> On Mon, Apr 09, 2012 at 03:23:38PM -0500, Seth Jennings wrote:
>> Hey Greg,
>>
>> Haven't heard back from you on this patch and it needs to
>> get into the 3.4 -rc releases ASAP.  It fixes a substantial
>> memory leak when frontswap/zcache are enabled.
>>
>> Let me know if you need me to repost.
>>
>> The patch was sent on 4/2.
> 
> 5 meager days ago, with a major holliday in the middle, not to mention a
> conference as well.  That's bold.

Sorry about that.  Forgot about the summit and the holiday :-/

The date was not to convey "It's been a whole week! Why the delay?",
but to help you find the original patch in your stack of emails.

> It is not lost, is in my queue, and will get to Linus before 3.4-final
> comes out, don't worry.

I'll be more patient (and take into account summits/holiday) for replies.

Thanks Greg!

--
Seth

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Patch
diff mbox series

diff --git a/drivers/staging/zsmalloc/zsmalloc-main.c b/drivers/staging/zsmalloc/zsmalloc-main.c
index 09caa4f..917461c 100644
--- a/drivers/staging/zsmalloc/zsmalloc-main.c
+++ b/drivers/staging/zsmalloc/zsmalloc-main.c
@@ -267,33 +267,39 @@  static unsigned long obj_idx_to_offset(struct page *page,
 	return off + obj_idx * class_size;
 }
 
+static void reset_page(struct page *page)
+{
+	clear_bit(PG_private, &page->flags);
+	clear_bit(PG_private_2, &page->flags);
+	set_page_private(page, 0);
+	page->mapping = NULL;
+	page->freelist = NULL;
+	reset_page_mapcount(page);
+}
+
 static void free_zspage(struct page *first_page)
 {
-	struct page *nextp, *tmp;
+	struct page *nextp, *tmp, *head_extra;
 
 	BUG_ON(!is_first_page(first_page));
 	BUG_ON(first_page->inuse);
 
-	nextp = (struct page *)page_private(first_page);
+	head_extra = (struct page *)page_private(first_page);
 
-	clear_bit(PG_private, &first_page->flags);
-	clear_bit(PG_private_2, &first_page->flags);
-	set_page_private(first_page, 0);
-	first_page->mapping = NULL;
-	first_page->freelist = NULL;
-	reset_page_mapcount(first_page);
+	reset_page(first_page);
 	__free_page(first_page);
 
 	/* zspage with only 1 system page */
-	if (!nextp)
+	if (!head_extra)
 		return;
 
-	list_for_each_entry_safe(nextp, tmp, &nextp->lru, lru) {
+	list_for_each_entry_safe(nextp, tmp, &head_extra->lru, lru) {
 		list_del(&nextp->lru);
-		clear_bit(PG_private_2, &nextp->flags);
-		nextp->index = 0;
+		reset_page(nextp);
 		__free_page(nextp);
 	}
+	reset_page(head_extra);
+	__free_page(head_extra);
 }
 
 /* Initialize a newly allocated zspage */