Commit 93144ca3 authored by Aliaksei Karaliou's avatar Aliaksei Karaliou Committed by Linus Torvalds

mm/zsmalloc: simplify shrinker init/destroy

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.

[akpm@linux-foundation.org: update comment (Aliaksei), remove unneeded cast]
Link: http://lkml.kernel.org/r/1513680552-9798-1-git-send-email-akaraliou.dev@gmail.comSigned-off-by: default avatarAliaksei Karaliou <akaraliou.dev@gmail.com>
Reviewed-by: default avatarSergey Senozhatsky <sergey.senozhatsky@gmail.com>
Acked-by: default avatarMinchan Kim <minchan@kernel.org>
Cc: Michal Hocko <mhocko@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent f340ff82
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include <linux/vmalloc.h> #include <linux/vmalloc.h>
#include <linux/preempt.h> #include <linux/preempt.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/shrinker.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/debugfs.h> #include <linux/debugfs.h>
#include <linux/zsmalloc.h> #include <linux/zsmalloc.h>
...@@ -257,11 +258,7 @@ struct zs_pool { ...@@ -257,11 +258,7 @@ struct zs_pool {
/* Compact classes */ /* Compact classes */
struct shrinker shrinker; struct shrinker shrinker;
/*
* To signify that register_shrinker() was successful
* and unregister_shrinker() will not Oops.
*/
bool shrinker_enabled;
#ifdef CONFIG_ZSMALLOC_STAT #ifdef CONFIG_ZSMALLOC_STAT
struct dentry *stat_dentry; struct dentry *stat_dentry;
#endif #endif
...@@ -2324,10 +2321,7 @@ static unsigned long zs_shrinker_count(struct shrinker *shrinker, ...@@ -2324,10 +2321,7 @@ static unsigned long zs_shrinker_count(struct shrinker *shrinker,
static void zs_unregister_shrinker(struct zs_pool *pool) static void zs_unregister_shrinker(struct zs_pool *pool)
{ {
if (pool->shrinker_enabled) { unregister_shrinker(&pool->shrinker);
unregister_shrinker(&pool->shrinker);
pool->shrinker_enabled = false;
}
} }
static int zs_register_shrinker(struct zs_pool *pool) static int zs_register_shrinker(struct zs_pool *pool)
...@@ -2426,11 +2420,13 @@ struct zs_pool *zs_create_pool(const char *name) ...@@ -2426,11 +2420,13 @@ struct zs_pool *zs_create_pool(const char *name)
goto err; goto err;
/* /*
* Not critical, we still can use the pool * Not critical since shrinker is only used to trigger internal
* and user can trigger compaction manually. * 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.
*/ */
if (zs_register_shrinker(pool) == 0) zs_register_shrinker(pool);
pool->shrinker_enabled = true;
return pool; return pool;
err: err:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment