diff options
author | Ganesh Mahendran <opensource.ganesh@gmail.com> | 2014-12-12 19:57:07 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-12-13 15:42:50 -0500 |
commit | df8b5bb998f10cfc040ad30300f9a9ea4592ff82 (patch) | |
tree | 43d3c41069a79d68b507701aef4e9ffbb68c6a76 /mm/zsmalloc.c | |
parent | d49b1c254c997195872a9e8913660a788298921e (diff) |
mm/zsmalloc: avoid duplicate assignment of prev_class
In zs_create_pool(), prev_class is assigned (ZS_SIZE_CLASSES - 1) times.
And the prev_class only references to the previous size_class. So we do
not need unnecessary assignement.
This patch assigns *prev_class* when a new size_class structure is
allocated and uses prev_class to check whether the first class has been
allocated.
[akpm@linux-foundation.org: remove now-unused ZS_SIZE_CLASSES]
Signed-off-by: Ganesh Mahendran <opensource.ganesh@gmail.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Nitin Gupta <ngupta@vflare.org>
Reviewed-by: Dan Streetman <ddstreet@ieee.org>
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.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 61e180931ca8..2021df5eb891 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c | |||
@@ -155,8 +155,6 @@ | |||
155 | * (reason above) | 155 | * (reason above) |
156 | */ | 156 | */ |
157 | #define ZS_SIZE_CLASS_DELTA (PAGE_SIZE >> 8) | 157 | #define ZS_SIZE_CLASS_DELTA (PAGE_SIZE >> 8) |
158 | #define ZS_SIZE_CLASSES ((ZS_MAX_ALLOC_SIZE - ZS_MIN_ALLOC_SIZE) / \ | ||
159 | ZS_SIZE_CLASS_DELTA + 1) | ||
160 | 158 | ||
161 | /* | 159 | /* |
162 | * We do not maintain any list for completely empty or full pages | 160 | * We do not maintain any list for completely empty or full pages |
@@ -983,6 +981,7 @@ struct zs_pool *zs_create_pool(gfp_t flags) | |||
983 | { | 981 | { |
984 | int i, ovhd_size; | 982 | int i, ovhd_size; |
985 | struct zs_pool *pool; | 983 | struct zs_pool *pool; |
984 | struct size_class *prev_class = NULL; | ||
986 | 985 | ||
987 | ovhd_size = roundup(sizeof(*pool), PAGE_SIZE); | 986 | ovhd_size = roundup(sizeof(*pool), PAGE_SIZE); |
988 | pool = kzalloc(ovhd_size, GFP_KERNEL); | 987 | pool = kzalloc(ovhd_size, GFP_KERNEL); |
@@ -1004,7 +1003,6 @@ struct zs_pool *zs_create_pool(gfp_t flags) | |||
1004 | int size; | 1003 | int size; |
1005 | int pages_per_zspage; | 1004 | int pages_per_zspage; |
1006 | struct size_class *class; | 1005 | struct size_class *class; |
1007 | struct size_class *prev_class; | ||
1008 | 1006 | ||
1009 | size = ZS_MIN_ALLOC_SIZE + i * ZS_SIZE_CLASS_DELTA; | 1007 | size = ZS_MIN_ALLOC_SIZE + i * ZS_SIZE_CLASS_DELTA; |
1010 | if (size > ZS_MAX_ALLOC_SIZE) | 1008 | if (size > ZS_MAX_ALLOC_SIZE) |
@@ -1020,8 +1018,7 @@ struct zs_pool *zs_create_pool(gfp_t flags) | |||
1020 | * characteristics. So, we makes size_class point to | 1018 | * characteristics. So, we makes size_class point to |
1021 | * previous size_class if possible. | 1019 | * previous size_class if possible. |
1022 | */ | 1020 | */ |
1023 | if (i < ZS_SIZE_CLASSES - 1) { | 1021 | if (prev_class) { |
1024 | prev_class = pool->size_class[i + 1]; | ||
1025 | if (can_merge(prev_class, size, pages_per_zspage)) { | 1022 | if (can_merge(prev_class, size, pages_per_zspage)) { |
1026 | pool->size_class[i] = prev_class; | 1023 | pool->size_class[i] = prev_class; |
1027 | continue; | 1024 | continue; |
@@ -1037,6 +1034,8 @@ struct zs_pool *zs_create_pool(gfp_t flags) | |||
1037 | class->pages_per_zspage = pages_per_zspage; | 1034 | class->pages_per_zspage = pages_per_zspage; |
1038 | spin_lock_init(&class->lock); | 1035 | spin_lock_init(&class->lock); |
1039 | pool->size_class[i] = class; | 1036 | pool->size_class[i] = class; |
1037 | |||
1038 | prev_class = class; | ||
1040 | } | 1039 | } |
1041 | 1040 | ||
1042 | pool->flags = flags; | 1041 | pool->flags = flags; |