Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit df8b5bb9 authored by Ganesh Mahendran's avatar Ganesh Mahendran Committed by Linus Torvalds
Browse files

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: default avatarGanesh Mahendran <opensource.ganesh@gmail.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Nitin Gupta <ngupta@vflare.org>
Reviewed-by: default avatarDan Streetman <ddstreet@ieee.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d49b1c25
Loading
Loading
Loading
Loading
+4 −5
Original line number Original line Diff line number Diff line
@@ -155,8 +155,6 @@
 *  (reason above)
 *  (reason above)
 */
 */
#define ZS_SIZE_CLASS_DELTA	(PAGE_SIZE >> 8)
#define ZS_SIZE_CLASS_DELTA	(PAGE_SIZE >> 8)
#define ZS_SIZE_CLASSES		((ZS_MAX_ALLOC_SIZE - ZS_MIN_ALLOC_SIZE) / \
					ZS_SIZE_CLASS_DELTA + 1)


/*
/*
 * We do not maintain any list for completely empty or full pages
 * 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)
{
{
	int i, ovhd_size;
	int i, ovhd_size;
	struct zs_pool *pool;
	struct zs_pool *pool;
	struct size_class *prev_class = NULL;


	ovhd_size = roundup(sizeof(*pool), PAGE_SIZE);
	ovhd_size = roundup(sizeof(*pool), PAGE_SIZE);
	pool = kzalloc(ovhd_size, GFP_KERNEL);
	pool = kzalloc(ovhd_size, GFP_KERNEL);
@@ -1004,7 +1003,6 @@ struct zs_pool *zs_create_pool(gfp_t flags)
		int size;
		int size;
		int pages_per_zspage;
		int pages_per_zspage;
		struct size_class *class;
		struct size_class *class;
		struct size_class *prev_class;


		size = ZS_MIN_ALLOC_SIZE + i * ZS_SIZE_CLASS_DELTA;
		size = ZS_MIN_ALLOC_SIZE + i * ZS_SIZE_CLASS_DELTA;
		if (size > ZS_MAX_ALLOC_SIZE)
		if (size > ZS_MAX_ALLOC_SIZE)
@@ -1020,8 +1018,7 @@ struct zs_pool *zs_create_pool(gfp_t flags)
		 * characteristics. So, we makes size_class point to
		 * characteristics. So, we makes size_class point to
		 * previous size_class if possible.
		 * previous size_class if possible.
		 */
		 */
		if (i < ZS_SIZE_CLASSES - 1) {
		if (prev_class) {
			prev_class = pool->size_class[i + 1];
			if (can_merge(prev_class, size, pages_per_zspage)) {
			if (can_merge(prev_class, size, pages_per_zspage)) {
				pool->size_class[i] = prev_class;
				pool->size_class[i] = prev_class;
				continue;
				continue;
@@ -1037,6 +1034,8 @@ struct zs_pool *zs_create_pool(gfp_t flags)
		class->pages_per_zspage = pages_per_zspage;
		class->pages_per_zspage = pages_per_zspage;
		spin_lock_init(&class->lock);
		spin_lock_init(&class->lock);
		pool->size_class[i] = class;
		pool->size_class[i] = class;

		prev_class = class;
	}
	}


	pool->flags = flags;
	pool->flags = flags;