summaryrefslogtreecommitdiffstats
path: root/mm/zsmalloc.c
diff options
context:
space:
mode:
authorMinchan Kim <minchan@kernel.org>2016-07-26 18:23:11 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-07-26 19:19:19 -0400
commit1fc6e27d7b8613afe6e5c1b8cdf94339a1bce640 (patch)
tree452e7eac7baca0961ada0cb078ced79683e0fd7c /mm/zsmalloc.c
parentb1123ea6d3b3da25af5c8a9d843bd07ab63213f4 (diff)
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.org Signed-off-by: Minchan Kim <minchan@kernel.org> Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/zsmalloc.c')
-rw-r--r--mm/zsmalloc.c32
1 files changed, 15 insertions, 17 deletions
diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index b6d4f258cb53..79295c73dc9f 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -32,8 +32,6 @@
32 * page->freelist: points to the first free object in zspage. 32 * page->freelist: points to the first free object in zspage.
33 * Free objects are linked together using in-place 33 * Free objects are linked together using in-place
34 * metadata. 34 * metadata.
35 * page->objects: maximum number of objects we can store in this
36 * zspage (class->zspage_order * PAGE_SIZE / class->size)
37 * page->lru: links together first pages of various zspages. 35 * page->lru: links together first pages of various zspages.
38 * Basically forming list of zspages in a fullness group. 36 * Basically forming list of zspages in a fullness group.
39 * page->mapping: class index and fullness group of the zspage 37 * page->mapping: class index and fullness group of the zspage
@@ -213,6 +211,7 @@ struct size_class {
213 * of ZS_ALIGN. 211 * of ZS_ALIGN.
214 */ 212 */
215 int size; 213 int size;
214 int objs_per_zspage;
216 unsigned int index; 215 unsigned int index;
217 216
218 struct zs_size_stat stats; 217 struct zs_size_stat stats;
@@ -631,21 +630,22 @@ static inline void zs_pool_stat_destroy(struct zs_pool *pool)
631 * the pool (not yet implemented). This function returns fullness 630 * the pool (not yet implemented). This function returns fullness
632 * status of the given page. 631 * status of the given page.
633 */ 632 */
634static enum fullness_group get_fullness_group(struct page *first_page) 633static enum fullness_group get_fullness_group(struct size_class *class,
634 struct page *first_page)
635{ 635{
636 int inuse, max_objects; 636 int inuse, objs_per_zspage;
637 enum fullness_group fg; 637 enum fullness_group fg;
638 638
639 VM_BUG_ON_PAGE(!is_first_page(first_page), first_page); 639 VM_BUG_ON_PAGE(!is_first_page(first_page), first_page);
640 640
641 inuse = first_page->inuse; 641 inuse = first_page->inuse;
642 max_objects = first_page->objects; 642 objs_per_zspage = class->objs_per_zspage;
643 643
644 if (inuse == 0) 644 if (inuse == 0)
645 fg = ZS_EMPTY; 645 fg = ZS_EMPTY;
646 else if (inuse == max_objects) 646 else if (inuse == objs_per_zspage)
647 fg = ZS_FULL; 647 fg = ZS_FULL;
648 else if (inuse <= 3 * max_objects / fullness_threshold_frac) 648 else if (inuse <= 3 * objs_per_zspage / fullness_threshold_frac)
649 fg = ZS_ALMOST_EMPTY; 649 fg = ZS_ALMOST_EMPTY;
650 else 650 else
651 fg = ZS_ALMOST_FULL; 651 fg = ZS_ALMOST_FULL;
@@ -732,7 +732,7 @@ static enum fullness_group fix_fullness_group(struct size_class *class,
732 enum fullness_group currfg, newfg; 732 enum fullness_group currfg, newfg;
733 733
734 get_zspage_mapping(first_page, &class_idx, &currfg); 734 get_zspage_mapping(first_page, &class_idx, &currfg);
735 newfg = get_fullness_group(first_page); 735 newfg = get_fullness_group(class, first_page);
736 if (newfg == currfg) 736 if (newfg == currfg)
737 goto out; 737 goto out;
738 738
@@ -1012,9 +1012,6 @@ static struct page *alloc_zspage(struct size_class *class, gfp_t flags)
1012 init_zspage(class, first_page); 1012 init_zspage(class, first_page);
1013 1013
1014 first_page->freelist = location_to_obj(first_page, 0); 1014 first_page->freelist = location_to_obj(first_page, 0);
1015 /* Maximum number of objects we can store in this zspage */
1016 first_page->objects = class->pages_per_zspage * PAGE_SIZE / class->size;
1017
1018 error = 0; /* Success */ 1015 error = 0; /* Success */
1019 1016
1020cleanup: 1017cleanup:
@@ -1242,11 +1239,11 @@ static bool can_merge(struct size_class *prev, int size, int pages_per_zspage)
1242 return true; 1239 return true;
1243} 1240}
1244 1241
1245static bool zspage_full(struct page *first_page) 1242static bool zspage_full(struct size_class *class, struct page *first_page)
1246{ 1243{
1247 VM_BUG_ON_PAGE(!is_first_page(first_page), first_page); 1244 VM_BUG_ON_PAGE(!is_first_page(first_page), first_page);
1248 1245
1249 return first_page->inuse == first_page->objects; 1246 return first_page->inuse == class->objs_per_zspage;
1250} 1247}
1251 1248
1252unsigned long zs_get_total_pages(struct zs_pool *pool) 1249unsigned 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 } 1629 }
1633 1630
1634 /* Stop if there is no more space */ 1631 /* Stop if there is no more space */
1635 if (zspage_full(d_page)) { 1632 if (zspage_full(class, d_page)) {
1636 unpin_tag(handle); 1633 unpin_tag(handle);
1637 ret = -ENOMEM; 1634 ret = -ENOMEM;
1638 break; 1635 break;
@@ -1691,7 +1688,7 @@ static enum fullness_group putback_zspage(struct zs_pool *pool,
1691{ 1688{
1692 enum fullness_group fullness; 1689 enum fullness_group fullness;
1693 1690
1694 fullness = get_fullness_group(first_page); 1691 fullness = get_fullness_group(class, first_page);
1695 insert_zspage(class, fullness, first_page); 1692 insert_zspage(class, fullness, first_page);
1696 set_zspage_mapping(first_page, class->index, fullness); 1693 set_zspage_mapping(first_page, class->index, fullness);
1697 1694
@@ -1943,8 +1940,9 @@ struct zs_pool *zs_create_pool(const char *name)
1943 class->size = size; 1940 class->size = size;
1944 class->index = i; 1941 class->index = i;
1945 class->pages_per_zspage = pages_per_zspage; 1942 class->pages_per_zspage = pages_per_zspage;
1946 if (pages_per_zspage == 1 && 1943 class->objs_per_zspage = class->pages_per_zspage *
1947 get_maxobj_per_zspage(size, pages_per_zspage) == 1) 1944 PAGE_SIZE / class->size;
1945 if (pages_per_zspage == 1 && class->objs_per_zspage == 1)
1948 class->huge = true; 1946 class->huge = true;
1949 spin_lock_init(&class->lock); 1947 spin_lock_init(&class->lock);
1950 pool->size_class[i] = class; 1948 pool->size_class[i] = class;