Commit 1a87aa03 authored by Henry Burns's avatar Henry Burns Committed by Linus Torvalds
Browse files

mm/zsmalloc.c: migration can leave pages in ZS_EMPTY indefinitely

In zs_page_migrate() we call putback_zspage() after we have finished
migrating all pages in this zspage.  However, the return value is
ignored.  If a zs_free() races in between zs_page_isolate() and
zs_page_migrate(), freeing the last object in the zspage,
putback_zspage() will leave the page in ZS_EMPTY for potentially an
unbounded amount of time.

To fix this, we need to do the same thing as zs_page_putback() does:
schedule free_work to occur.

To avoid duplicated code, move the sequence to a new
putback_zspage_deferred() function which both zs_page_migrate() and
zs_page_putback() call.

Fixes: 48b4800a

 ("zsmalloc: page migration support")
Signed-off-by: default avatarHenry Burns <>
Reviewed-by: default avatarSergey Senozhatsky <>
Cc: Henry Burns <>
Cc: Minchan Kim <>
Cc: Shakeel Butt <>
Cc: Jonathan Adams <>
Cc: <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent f7da677b
......@@ -1862,6 +1862,18 @@ static void dec_zspage_isolation(struct zspage *zspage)
static void putback_zspage_deferred(struct zs_pool *pool,
struct size_class *class,
struct zspage *zspage)
enum fullness_group fg;
fg = putback_zspage(class, zspage);
if (fg == ZS_EMPTY)
static void replace_sub_page(struct size_class *class, struct zspage *zspage,
struct page *newpage, struct page *oldpage)
......@@ -2031,7 +2043,7 @@ static int zs_page_migrate(struct address_space *mapping, struct page *newpage,
* the list if @page is final isolated subpage in the zspage.
if (!is_zspage_isolated(zspage))
putback_zspage(class, zspage);
putback_zspage_deferred(pool, class, zspage);
......@@ -2077,14 +2089,13 @@ static void zs_page_putback(struct page *page)
if (!is_zspage_isolated(zspage)) {
fg = putback_zspage(class, zspage);
* Due to page_lock, we cannot free zspage immediately
* so let's defer.
if (fg == ZS_EMPTY)
putback_zspage_deferred(pool, class, zspage);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment