aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGanesh Mahendran <opensource.ganesh@gmail.com>2016-07-28 18:47:51 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-07-28 19:07:41 -0400
commit64d90465f01325653deb8503aec4ca48ca3e9580 (patch)
treee11e75ae92f8f4df349115af4c136c46e75de330
parentb4fd07a0864a06d7a8b20a624d851736330d6fd8 (diff)
mm/zsmalloc: avoid calculate max objects of zspage twice
Currently, if a class can not be merged, the max objects of zspage in that class may be calculated twice. This patch calculate max objects of zspage at the begin, and pass the value to can_merge() to decide whether the class can be merged. Also this patch remove function get_maxobj_per_zspage(), as there is no other place to call this function. Link: http://lkml.kernel.org/r/1467882338-4300-4-git-send-email-opensource.ganesh@gmail.com Signed-off-by: Ganesh Mahendran <opensource.ganesh@gmail.com> Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Acked-by: Minchan Kim <minchan@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--mm/zsmalloc.c26
1 files changed, 10 insertions, 16 deletions
diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 72e0b296984b..1ce774503fa1 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -467,11 +467,6 @@ static struct zpool_driver zs_zpool_driver = {
467MODULE_ALIAS("zpool-zsmalloc"); 467MODULE_ALIAS("zpool-zsmalloc");
468#endif /* CONFIG_ZPOOL */ 468#endif /* CONFIG_ZPOOL */
469 469
470static unsigned int get_maxobj_per_zspage(int size, int pages_per_zspage)
471{
472 return pages_per_zspage * PAGE_SIZE / size;
473}
474
475/* per-cpu VM mapping areas for zspage accesses that cross page boundaries */ 470/* per-cpu VM mapping areas for zspage accesses that cross page boundaries */
476static DEFINE_PER_CPU(struct mapping_area, zs_map_area); 471static DEFINE_PER_CPU(struct mapping_area, zs_map_area);
477 472
@@ -1359,16 +1354,14 @@ static void init_zs_size_classes(void)
1359 zs_size_classes = nr; 1354 zs_size_classes = nr;
1360} 1355}
1361 1356
1362static bool can_merge(struct size_class *prev, int size, int pages_per_zspage) 1357static bool can_merge(struct size_class *prev, int pages_per_zspage,
1358 int objs_per_zspage)
1363{ 1359{
1364 if (prev->pages_per_zspage != pages_per_zspage) 1360 if (prev->pages_per_zspage == pages_per_zspage &&
1365 return false; 1361 prev->objs_per_zspage == objs_per_zspage)
1362 return true;
1366 1363
1367 if (prev->objs_per_zspage 1364 return false;
1368 != get_maxobj_per_zspage(size, pages_per_zspage))
1369 return false;
1370
1371 return true;
1372} 1365}
1373 1366
1374static bool zspage_full(struct size_class *class, struct zspage *zspage) 1367static bool zspage_full(struct size_class *class, struct zspage *zspage)
@@ -2438,6 +2431,7 @@ struct zs_pool *zs_create_pool(const char *name)
2438 for (i = zs_size_classes - 1; i >= 0; i--) { 2431 for (i = zs_size_classes - 1; i >= 0; i--) {
2439 int size; 2432 int size;
2440 int pages_per_zspage; 2433 int pages_per_zspage;
2434 int objs_per_zspage;
2441 struct size_class *class; 2435 struct size_class *class;
2442 int fullness = 0; 2436 int fullness = 0;
2443 2437
@@ -2445,6 +2439,7 @@ struct zs_pool *zs_create_pool(const char *name)
2445 if (size > ZS_MAX_ALLOC_SIZE) 2439 if (size > ZS_MAX_ALLOC_SIZE)
2446 size = ZS_MAX_ALLOC_SIZE; 2440 size = ZS_MAX_ALLOC_SIZE;
2447 pages_per_zspage = get_pages_per_zspage(size); 2441 pages_per_zspage = get_pages_per_zspage(size);
2442 objs_per_zspage = pages_per_zspage * PAGE_SIZE / size;
2448 2443
2449 /* 2444 /*
2450 * size_class is used for normal zsmalloc operation such 2445 * size_class is used for normal zsmalloc operation such
@@ -2456,7 +2451,7 @@ struct zs_pool *zs_create_pool(const char *name)
2456 * previous size_class if possible. 2451 * previous size_class if possible.
2457 */ 2452 */
2458 if (prev_class) { 2453 if (prev_class) {
2459 if (can_merge(prev_class, size, pages_per_zspage)) { 2454 if (can_merge(prev_class, pages_per_zspage, objs_per_zspage)) {
2460 pool->size_class[i] = prev_class; 2455 pool->size_class[i] = prev_class;
2461 continue; 2456 continue;
2462 } 2457 }
@@ -2469,8 +2464,7 @@ struct zs_pool *zs_create_pool(const char *name)
2469 class->size = size; 2464 class->size = size;
2470 class->index = i; 2465 class->index = i;
2471 class->pages_per_zspage = pages_per_zspage; 2466 class->pages_per_zspage = pages_per_zspage;
2472 class->objs_per_zspage = get_maxobj_per_zspage(class->size, 2467 class->objs_per_zspage = objs_per_zspage;
2473 class->pages_per_zspage);
2474 spin_lock_init(&class->lock); 2468 spin_lock_init(&class->lock);
2475 pool->size_class[i] = class; 2469 pool->size_class[i] = class;
2476 for (fullness = ZS_EMPTY; fullness < NR_ZS_FULLNESS; 2470 for (fullness = ZS_EMPTY; fullness < NR_ZS_FULLNESS;