提交 699bb9e8 编写于 作者: L Liu Shixin 提交者: Ma Wupeng

mm/zswap: delay the initializaton of zswap until the first enablement

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

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

The zswap initialization consumes some memory. If we don't use zswap,
there's no need to initial it. So delay the initializaton of zswap until
the first enablement.
Signed-off-by: NLiu Shixin <liushixin2@huawei.com>
上级 3286455e
...@@ -79,6 +79,8 @@ static bool zswap_pool_reached_full; ...@@ -79,6 +79,8 @@ static bool zswap_pool_reached_full;
#define ZSWAP_PARAM_UNSET "" #define ZSWAP_PARAM_UNSET ""
static int zswap_setup(void);
/* Enable/disable zswap */ /* Enable/disable zswap */
static bool zswap_enabled = IS_ENABLED(CONFIG_ZSWAP_DEFAULT_ON); static bool zswap_enabled = IS_ENABLED(CONFIG_ZSWAP_DEFAULT_ON);
static int zswap_enabled_param_set(const char *, static int zswap_enabled_param_set(const char *,
...@@ -209,6 +211,8 @@ static atomic_t zswap_pools_count = ATOMIC_INIT(0); ...@@ -209,6 +211,8 @@ static atomic_t zswap_pools_count = ATOMIC_INIT(0);
/* init state */ /* init state */
static int zswap_init_state; static int zswap_init_state;
/* used to ensure the integrity of initialization */
static DEFINE_MUTEX(zswap_init_lock);
/* 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;
...@@ -767,11 +771,17 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp, ...@@ -767,11 +771,17 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp,
if (!strcmp(s, *(char **)kp->arg) && zswap_has_pool) if (!strcmp(s, *(char **)kp->arg) && zswap_has_pool)
return 0; return 0;
/* if this is load-time (pre-init) param setting, /*
* if zswap has not been initialized,
* don't create a pool; that's done during init. * don't create a pool; that's done during init.
*/ */
if (zswap_init_state == ZSWAP_UNINIT) mutex_lock(&zswap_init_lock);
return param_set_charp(s, kp); if (zswap_init_state == ZSWAP_UNINIT) {
ret = param_set_charp(s, kp);
mutex_unlock(&zswap_init_lock);
return ret;
}
mutex_unlock(&zswap_init_lock);
if (!type) { if (!type) {
if (!zpool_has_pool(s)) { if (!zpool_has_pool(s)) {
...@@ -861,6 +871,14 @@ static int zswap_zpool_param_set(const char *val, ...@@ -861,6 +871,14 @@ 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 (system_state == SYSTEM_RUNNING) {
mutex_lock(&zswap_init_lock);
if (zswap_setup()) {
mutex_unlock(&zswap_init_lock);
return -ENODEV;
}
mutex_unlock(&zswap_init_lock);
}
if (zswap_init_state == 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;
...@@ -1435,14 +1453,14 @@ static int __init zswap_debugfs_init(void) ...@@ -1435,14 +1453,14 @@ static int __init zswap_debugfs_init(void)
static void __exit zswap_debugfs_exit(void) { } static void __exit zswap_debugfs_exit(void) { }
#endif #endif
/********************************* static int zswap_setup(void)
* module init and exit
**********************************/
static int __init init_zswap(void)
{ {
struct zswap_pool *pool; struct zswap_pool *pool;
int ret; int ret;
if (zswap_init_state != ZSWAP_UNINIT)
return 0;
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;
...@@ -1496,6 +1514,18 @@ static int __init init_zswap(void) ...@@ -1496,6 +1514,18 @@ static int __init init_zswap(void)
zswap_enabled = false; zswap_enabled = false;
return -ENOMEM; return -ENOMEM;
} }
/*********************************
* module init and exit
**********************************/
static int __init init_zswap(void)
{
/* skip init if zswap is disabled when system startup */
if (!zswap_enabled)
return 0;
return zswap_setup();
}
/* must be late so crypto has time to come up */ /* must be late so crypto has time to come up */
late_initcall(init_zswap); late_initcall(init_zswap);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册