Skip to content

Commit

Permalink
z3fold: fix memory leak in kmem cache
Browse files Browse the repository at this point in the history
Currently there is a leak in init_z3fold_page() -- it allocates handles
from kmem cache even for headless pages, but then they are never used and
never freed, so eventually kmem cache may get exhausted.  This patch
provides a fix for that.

Link: http://lkml.kernel.org/r/20190917185352.44cf285d3ebd9e64548de5de@gmail.com
Signed-off-by: Vitaly Wool <vitalywool@gmail.com>
Reported-by: Markus Linnala <markus.linnala@gmail.com>
Tested-by: Markus Linnala <markus.linnala@gmail.com>
Cc: Dan Streetman <ddstreet@ieee.org>
Cc: Henry Burns <henrywolfeburns@gmail.com>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
vwool authored and torvalds committed Sep 24, 2019
1 parent b57a775 commit 6339841
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions mm/z3fold.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,21 +295,24 @@ static void z3fold_unregister_migration(struct z3fold_pool *pool)
}

/* Initializes the z3fold header of a newly allocated z3fold page */
static struct z3fold_header *init_z3fold_page(struct page *page,
static struct z3fold_header *init_z3fold_page(struct page *page, bool headless,
struct z3fold_pool *pool, gfp_t gfp)
{
struct z3fold_header *zhdr = page_address(page);
struct z3fold_buddy_slots *slots = alloc_slots(pool, gfp);

if (!slots)
return NULL;
struct z3fold_buddy_slots *slots;

INIT_LIST_HEAD(&page->lru);
clear_bit(PAGE_HEADLESS, &page->private);
clear_bit(MIDDLE_CHUNK_MAPPED, &page->private);
clear_bit(NEEDS_COMPACTING, &page->private);
clear_bit(PAGE_STALE, &page->private);
clear_bit(PAGE_CLAIMED, &page->private);
if (headless)
return zhdr;

slots = alloc_slots(pool, gfp);
if (!slots)
return NULL;

spin_lock_init(&zhdr->page_lock);
kref_init(&zhdr->refcount);
Expand Down Expand Up @@ -930,7 +933,7 @@ static int z3fold_alloc(struct z3fold_pool *pool, size_t size, gfp_t gfp,
if (!page)
return -ENOMEM;

zhdr = init_z3fold_page(page, pool, gfp);
zhdr = init_z3fold_page(page, bud == HEADLESS, pool, gfp);
if (!zhdr) {
__free_page(page);
return -ENOMEM;
Expand Down

0 comments on commit 6339841

Please sign in to comment.