提交 1fc6e27d 编写于 作者: M Minchan Kim 提交者: Linus Torvalds

zsmalloc: keep max_object in size_class

Every zspage in a size_class has same number of max objects so we could
move it to a size_class.

Link: http://lkml.kernel.org/r/1464736881-24886-5-git-send-email-minchan@kernel.orgSigned-off-by: NMinchan Kim <minchan@kernel.org>
Reviewed-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 b1123ea6
...@@ -32,8 +32,6 @@ ...@@ -32,8 +32,6 @@
* page->freelist: points to the first free object in zspage. * page->freelist: points to the first free object in zspage.
* Free objects are linked together using in-place * Free objects are linked together using in-place
* metadata. * metadata.
* page->objects: maximum number of objects we can store in this
* zspage (class->zspage_order * PAGE_SIZE / class->size)
* page->lru: links together first pages of various zspages. * page->lru: links together first pages of various zspages.
* Basically forming list of zspages in a fullness group. * Basically forming list of zspages in a fullness group.
* page->mapping: class index and fullness group of the zspage * page->mapping: class index and fullness group of the zspage
...@@ -213,6 +211,7 @@ struct size_class { ...@@ -213,6 +211,7 @@ struct size_class {
* of ZS_ALIGN. * of ZS_ALIGN.
*/ */
int size; int size;
int objs_per_zspage;
unsigned int index; unsigned int index;
struct zs_size_stat stats; struct zs_size_stat stats;
...@@ -631,21 +630,22 @@ static inline void zs_pool_stat_destroy(struct zs_pool *pool) ...@@ -631,21 +630,22 @@ static inline void zs_pool_stat_destroy(struct zs_pool *pool)
* the pool (not yet implemented). This function returns fullness * the pool (not yet implemented). This function returns fullness
* status of the given page. * status of the given page.
*/ */
static enum fullness_group get_fullness_group(struct page *first_page) static enum fullness_group get_fullness_group(struct size_class *class,
struct page *first_page)
{ {
int inuse, max_objects; int inuse, objs_per_zspage;
enum fullness_group fg; enum fullness_group fg;
VM_BUG_ON_PAGE(!is_first_page(first_page), first_page); VM_BUG_ON_PAGE(!is_first_page(first_page), first_page);
inuse = first_page->inuse; inuse = first_page->inuse;
max_objects = first_page->objects; objs_per_zspage = class->objs_per_zspage;
if (inuse == 0) if (inuse == 0)
fg = ZS_EMPTY; fg = ZS_EMPTY;
else if (inuse == max_objects) else if (inuse == objs_per_zspage)
fg = ZS_FULL; fg = ZS_FULL;
else if (inuse <= 3 * max_objects / fullness_threshold_frac) else if (inuse <= 3 * objs_per_zspage / fullness_threshold_frac)
fg = ZS_ALMOST_EMPTY; fg = ZS_ALMOST_EMPTY;
else else
fg = ZS_ALMOST_FULL; fg = ZS_ALMOST_FULL;
...@@ -732,7 +732,7 @@ static enum fullness_group fix_fullness_group(struct size_class *class, ...@@ -732,7 +732,7 @@ static enum fullness_group fix_fullness_group(struct size_class *class,
enum fullness_group currfg, newfg; enum fullness_group currfg, newfg;
get_zspage_mapping(first_page, &class_idx, &currfg); get_zspage_mapping(first_page, &class_idx, &currfg);
newfg = get_fullness_group(first_page); newfg = get_fullness_group(class, first_page);
if (newfg == currfg) if (newfg == currfg)
goto out; goto out;
...@@ -1012,9 +1012,6 @@ static struct page *alloc_zspage(struct size_class *class, gfp_t flags) ...@@ -1012,9 +1012,6 @@ static struct page *alloc_zspage(struct size_class *class, gfp_t flags)
init_zspage(class, first_page); init_zspage(class, first_page);
first_page->freelist = location_to_obj(first_page, 0); first_page->freelist = location_to_obj(first_page, 0);
/* Maximum number of objects we can store in this zspage */
first_page->objects = class->pages_per_zspage * PAGE_SIZE / class->size;
error = 0; /* Success */ error = 0; /* Success */
cleanup: cleanup:
...@@ -1242,11 +1239,11 @@ static bool can_merge(struct size_class *prev, int size, int pages_per_zspage) ...@@ -1242,11 +1239,11 @@ static bool can_merge(struct size_class *prev, int size, int pages_per_zspage)
return true; return true;
} }
static bool zspage_full(struct page *first_page) static bool zspage_full(struct size_class *class, struct page *first_page)
{ {
VM_BUG_ON_PAGE(!is_first_page(first_page), first_page); VM_BUG_ON_PAGE(!is_first_page(first_page), first_page);
return first_page->inuse == first_page->objects; return first_page->inuse == class->objs_per_zspage;
} }
unsigned long zs_get_total_pages(struct zs_pool *pool) unsigned long zs_get_total_pages(struct zs_pool *pool)
...@@ -1632,7 +1629,7 @@ static int migrate_zspage(struct zs_pool *pool, struct size_class *class, ...@@ -1632,7 +1629,7 @@ static int migrate_zspage(struct zs_pool *pool, struct size_class *class,
} }
/* Stop if there is no more space */ /* Stop if there is no more space */
if (zspage_full(d_page)) { if (zspage_full(class, d_page)) {
unpin_tag(handle); unpin_tag(handle);
ret = -ENOMEM; ret = -ENOMEM;
break; break;
...@@ -1691,7 +1688,7 @@ static enum fullness_group putback_zspage(struct zs_pool *pool, ...@@ -1691,7 +1688,7 @@ static enum fullness_group putback_zspage(struct zs_pool *pool,
{ {
enum fullness_group fullness; enum fullness_group fullness;
fullness = get_fullness_group(first_page); fullness = get_fullness_group(class, first_page);
insert_zspage(class, fullness, first_page); insert_zspage(class, fullness, first_page);
set_zspage_mapping(first_page, class->index, fullness); set_zspage_mapping(first_page, class->index, fullness);
...@@ -1943,8 +1940,9 @@ struct zs_pool *zs_create_pool(const char *name) ...@@ -1943,8 +1940,9 @@ struct zs_pool *zs_create_pool(const char *name)
class->size = size; class->size = size;
class->index = i; class->index = i;
class->pages_per_zspage = pages_per_zspage; class->pages_per_zspage = pages_per_zspage;
if (pages_per_zspage == 1 && class->objs_per_zspage = class->pages_per_zspage *
get_maxobj_per_zspage(size, pages_per_zspage) == 1) PAGE_SIZE / class->size;
if (pages_per_zspage == 1 && class->objs_per_zspage == 1)
class->huge = true; class->huge = true;
spin_lock_init(&class->lock); spin_lock_init(&class->lock);
pool->size_class[i] = class; pool->size_class[i] = class;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册