提交 3286455e 编写于 作者: L Liu Shixin 提交者: Ma Wupeng

mm/zswap: replace zswap_init_{started/failed} with zswap_init_state

hulk inclusion
category: performance
bugzilla: 187468, https://gitee.com/openeuler/kernel/issues/I61HSG

--------------------------------

zswap_init_started indicates that the initialization is started. And
zswap_init_failed indicates that the initialization is failed. As we will
support to init zswap after system startup, it's necessary to add a state
to indicate the initialization is complete and succeed to avoid
concurrency issues. Since we don't care about the difference between
init started with init completion. We only need three states:
uninitialized, initial failed, initial succeed.
Signed-off-by: NLiu Shixin <liushixin2@huawei.com>
上级 1b709179
...@@ -203,11 +203,12 @@ static DEFINE_SPINLOCK(zswap_pools_lock); ...@@ -203,11 +203,12 @@ static DEFINE_SPINLOCK(zswap_pools_lock);
/* pool counter to provide unique names to zpool */ /* pool counter to provide unique names to zpool */
static atomic_t zswap_pools_count = ATOMIC_INIT(0); static atomic_t zswap_pools_count = ATOMIC_INIT(0);
/* used by param callback function */ #define ZSWAP_UNINIT 0
static bool zswap_init_started; #define ZSWAP_INIT_SUCCEED 1
#define ZSWAP_INIT_FAILED 2
/* fatal error during init */ /* init state */
static bool zswap_init_failed; static int zswap_init_state;
/* init completed, but couldn't create the initial pool */ /* init completed, but couldn't create the initial pool */
static bool zswap_has_pool; static bool zswap_has_pool;
...@@ -757,7 +758,7 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp, ...@@ -757,7 +758,7 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp,
char *s = strstrip((char *)val); char *s = strstrip((char *)val);
int ret; int ret;
if (zswap_init_failed) { if (zswap_init_state == ZSWAP_INIT_FAILED) {
pr_err("can't set param, initialization failed\n"); pr_err("can't set param, initialization failed\n");
return -ENODEV; return -ENODEV;
} }
...@@ -769,7 +770,7 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp, ...@@ -769,7 +770,7 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp,
/* if this is load-time (pre-init) param setting, /* if this is load-time (pre-init) param setting,
* don't create a pool; that's done during init. * don't create a pool; that's done during init.
*/ */
if (!zswap_init_started) if (zswap_init_state == ZSWAP_UNINIT)
return param_set_charp(s, kp); return param_set_charp(s, kp);
if (!type) { if (!type) {
...@@ -860,11 +861,11 @@ static int zswap_zpool_param_set(const char *val, ...@@ -860,11 +861,11 @@ static int zswap_zpool_param_set(const char *val,
static int zswap_enabled_param_set(const char *val, static int zswap_enabled_param_set(const char *val,
const struct kernel_param *kp) const struct kernel_param *kp)
{ {
if (zswap_init_failed) { if (zswap_init_state == ZSWAP_INIT_FAILED) {
pr_err("can't enable, initialization failed\n"); pr_err("can't enable, initialization failed\n");
return -ENODEV; return -ENODEV;
} }
if (!zswap_has_pool && zswap_init_started) { if (!zswap_has_pool && zswap_init_state == ZSWAP_INIT_SUCCEED) {
pr_err("can't enable, no pool configured\n"); pr_err("can't enable, no pool configured\n");
return -ENODEV; return -ENODEV;
} }
...@@ -1442,8 +1443,6 @@ static int __init init_zswap(void) ...@@ -1442,8 +1443,6 @@ static int __init init_zswap(void)
struct zswap_pool *pool; struct zswap_pool *pool;
int ret; int ret;
zswap_init_started = true;
if (zswap_entry_cache_create()) { if (zswap_entry_cache_create()) {
pr_err("entry cache creation failed\n"); pr_err("entry cache creation failed\n");
goto cache_fail; goto cache_fail;
...@@ -1481,6 +1480,7 @@ static int __init init_zswap(void) ...@@ -1481,6 +1480,7 @@ static int __init init_zswap(void)
frontswap_register_ops(&zswap_frontswap_ops); frontswap_register_ops(&zswap_frontswap_ops);
if (zswap_debugfs_init()) if (zswap_debugfs_init())
pr_warn("debugfs initialization failed\n"); pr_warn("debugfs initialization failed\n");
zswap_init_state = ZSWAP_INIT_SUCCEED;
return 0; return 0;
fallback_fail: fallback_fail:
...@@ -1492,7 +1492,7 @@ static int __init init_zswap(void) ...@@ -1492,7 +1492,7 @@ static int __init init_zswap(void)
zswap_entry_cache_destroy(); zswap_entry_cache_destroy();
cache_fail: cache_fail:
/* if built-in, we aren't unloaded on failure; don't allow use */ /* if built-in, we aren't unloaded on failure; don't allow use */
zswap_init_failed = true; zswap_init_state = ZSWAP_INIT_FAILED;
zswap_enabled = false; zswap_enabled = false;
return -ENOMEM; return -ENOMEM;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册