#define ZSWAP_PARAM_UNSET ""
+static int zswap_setup(void);
+
/* Enable/disable zswap */
static bool zswap_enabled = IS_ENABLED(CONFIG_ZSWAP_DEFAULT_ON);
static int zswap_enabled_param_set(const char *,
/* 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 */
static bool zswap_has_pool;
**********************************/
static struct kmem_cache *zswap_entry_cache;
-static int __init zswap_entry_cache_create(void)
+static int zswap_entry_cache_create(void)
{
zswap_entry_cache = KMEM_CACHE(zswap_entry, 0);
return zswap_entry_cache == NULL;
}
-static void __init zswap_entry_cache_destroy(void)
+static void zswap_entry_cache_destroy(void)
{
kmem_cache_destroy(zswap_entry_cache);
}
return NULL;
}
-static __init struct zswap_pool *__zswap_pool_create_fallback(void)
+static struct zswap_pool *__zswap_pool_create_fallback(void)
{
bool has_comp, has_zpool;
if (!strcmp(s, *(char **)kp->arg) && zswap_has_pool)
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.
*/
- if (zswap_init_state == ZSWAP_UNINIT)
- return param_set_charp(s, kp);
+ mutex_lock(&zswap_init_lock);
+ 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 (!zpool_has_pool(s)) {
static int zswap_enabled_param_set(const char *val,
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) {
pr_err("can't enable, initialization failed\n");
return -ENODEV;
static struct dentry *zswap_debugfs_root;
-static int __init zswap_debugfs_init(void)
+static int zswap_debugfs_init(void)
{
if (!debugfs_initialized())
return -ENODEV;
return 0;
}
#else
-static int __init zswap_debugfs_init(void)
+static int zswap_debugfs_init(void)
{
return 0;
}
/*********************************
* module init and exit
**********************************/
-static int __init init_zswap(void)
+static int zswap_setup(void)
{
struct zswap_pool *pool;
int ret;
+ if (zswap_init_state != ZSWAP_UNINIT)
+ return 0;
+
if (zswap_entry_cache_create()) {
pr_err("entry cache creation failed\n");
goto cache_fail;
zswap_enabled = false;
return -ENOMEM;
}
+
+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 */
late_initcall(init_zswap);