All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aliaksei Karaliou <akaraliou.dev@gmail.com>
To: minchan@kernel.org, ngupta@vflare.org,
	sergey.senozhatsky.work@gmail.com, akpm@linux-foundation.org
Cc: Aliaksei Karaliou <akaraliou.dev@gmail.com>, linux-mm@kvack.org
Subject: [PATCH v3] mm/zsmalloc: simplify shrinker init/destroy
Date: Wed, 20 Dec 2017 13:21:49 +0300	[thread overview]
Message-ID: <1513765309-19500-1-git-send-email-akaraliou.dev@gmail.com> (raw)
In-Reply-To: <06247d4c-82a7-ccf1-ad42-4ef751081011@gmail.com>

Structure zs_pool has special flag to indicate success of shrinker
initialization. unregister_shrinker() has improved and can detect
by itself whether actual deinitialization should be performed or not,
so extra flag becomes redundant.

Signed-off-by: Aliaksei Karaliou <akaraliou.dev@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
 mm/zsmalloc.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

v2: Added include <linux/shrinker.h> as suggested by Sergey Senozhatsky.
v3: Improved comment regarding shrinker registration failure.
    Added patch from Andrew Morton to make zs_register_shrinker() void.

diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 685049a..bed387b 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -53,6 +53,7 @@
 #include <linux/mount.h>
 #include <linux/migrate.h>
 #include <linux/pagemap.h>
+#include <linux/shrinker.h>
 
 #define ZSPAGE_MAGIC	0x58
 
@@ -256,11 +257,7 @@ struct zs_pool {
 
 	/* Compact classes */
 	struct shrinker shrinker;
-	/*
-	 * To signify that register_shrinker() was successful
-	 * and unregister_shrinker() will not Oops.
-	 */
-	bool shrinker_enabled;
+
 #ifdef CONFIG_ZSMALLOC_STAT
 	struct dentry *stat_dentry;
 #endif
@@ -2323,20 +2320,23 @@ static unsigned long zs_shrinker_count(struct shrinker *shrinker,
 
 static void zs_unregister_shrinker(struct zs_pool *pool)
 {
-	if (pool->shrinker_enabled) {
-		unregister_shrinker(&pool->shrinker);
-		pool->shrinker_enabled = false;
-	}
+	unregister_shrinker(&pool->shrinker);
 }
 
-static int zs_register_shrinker(struct zs_pool *pool)
+static void zs_register_shrinker(struct zs_pool *pool)
 {
 	pool->shrinker.scan_objects = zs_shrinker_scan;
 	pool->shrinker.count_objects = zs_shrinker_count;
 	pool->shrinker.batch = 0;
 	pool->shrinker.seeks = DEFAULT_SEEKS;
 
-	return register_shrinker(&pool->shrinker);
+	/*
+	 * Not critical since shrinker is only used to trigger internal
+	 * defragmentation of the pool which is pretty optional thing.  If
+	 * registration fails we still can use the pool normally and user can
+	 * trigger compaction manually. Thus, ignore return code.
+	 */
+	register_shrinker(&pool->shrinker);
 }
 
 /**
@@ -2424,12 +2424,8 @@ struct zs_pool *zs_create_pool(const char *name)
 	if (zs_register_migration(pool))
 		goto err;
 
-	/*
-	 * Not critical, we still can use the pool
-	 * and user can trigger compaction manually.
-	 */
-	if (zs_register_shrinker(pool) == 0)
-		pool->shrinker_enabled = true;
+	zs_register_shrinker(pool);
+
 	return pool;
 
 err:
-- 
2.1.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2017-12-20 10:22 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-19  9:21 [PATCH] mm/zsmalloc: simplify shrinker init/destroy Aliaksei Karaliou
2017-12-19 10:22 ` Sergey Senozhatsky
2017-12-19 10:49   ` [PATCH v2] " Aliaksei Karaliou
2017-12-19 11:04     ` Sergey Senozhatsky
2017-12-19 11:56       ` Sergey Senozhatsky
2017-12-19 15:13     ` Michal Hocko
2017-12-19 15:25       ` Sergey Senozhatsky
2017-12-19 15:41         ` Aliaksei Karaliou
2017-12-19 15:58         ` Michal Hocko
2017-12-19 17:45           ` Aliaksei Karaliou
2017-12-19 23:27             ` Andrew Morton
2017-12-20  1:00               ` Sergey Senozhatsky
2017-12-20  1:00             ` Sergey Senozhatsky
2017-12-20  7:15           ` Sergey Senozhatsky
2017-12-20  8:29             ` A K
2017-12-20  8:34               ` Sergey Senozhatsky
2017-12-20  8:53                 ` A K
2017-12-20  9:08                 ` Michal Hocko
     [not found]                   ` <20171220091653.GE11774@jagdpanzerIV>
2017-12-20  9:25                     ` Michal Hocko
2017-12-20  9:30                       ` A K
2017-12-20 10:21                         ` Aliaksei Karaliou [this message]
2017-12-21  2:29                           ` [PATCH v3] " Minchan Kim
2017-12-20 11:05                       ` [PATCH v2] " Tetsuo Handa
2017-12-20 11:38                         ` Michal Hocko
2017-12-20 11:57                           ` Michal Hocko
2017-12-20 21:20                             ` Aliaksei Karaliou
2017-12-21  7:25                               ` Michal Hocko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1513765309-19500-1-git-send-email-akaraliou.dev@gmail.com \
    --to=akaraliou.dev@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=ngupta@vflare.org \
    --cc=sergey.senozhatsky.work@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.