1 From 66e0ea531f4975fed5899a2cbbfa3986fca40680 Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.com>
3 Date: Tue, 5 May 2020 15:23:32 +0100
4 Subject: [PATCH] zswap: Defer zswap initialisation
6 Enabling zswap support in the kernel configuration costs about 1.5MB
7 of RAM, even when zswap is not enabled at runtime. This cost can be
8 reduced significantly by deferring initialisation (including pool
9 creation) until the "enabled" parameter is set to true. There is a
10 small cost to this in that some initialisation code has to remain in
11 memory after the init phase, just in case they are needed later,
12 but the total size increase is negligible.
14 See: https://github.com/raspberrypi/linux/pull/3432
16 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
18 mm/zswap.c | 48 ++++++++++++++++++++++++++++--------------------
19 1 file changed, 28 insertions(+), 20 deletions(-)
23 @@ -564,8 +564,9 @@ error:
27 -static __init struct zswap_pool *__zswap_pool_create_fallback(void)
28 +static bool zswap_try_pool_create(void)
30 + struct zswap_pool *pool;
31 bool has_comp, has_zpool;
33 has_comp = crypto_has_comp(zswap_compressor, 0, 0);
34 @@ -599,9 +600,21 @@ static __init struct zswap_pool *__zswap
37 if (!has_comp || !has_zpool)
41 + pool = zswap_pool_create(zswap_zpool_type, zswap_compressor);
44 + pr_info("loaded using pool %s/%s\n", pool->tfm_name,
45 + zpool_get_type(pool->zpool));
46 + list_add(&pool->list, &zswap_pools);
47 + zswap_has_pool = true;
49 + pr_err("pool creation failed\n");
50 + zswap_enabled = false;
53 - return zswap_pool_create(zswap_zpool_type, zswap_compressor);
54 + return zswap_enabled;
57 static void zswap_pool_destroy(struct zswap_pool *pool)
58 @@ -773,16 +786,19 @@ static int zswap_zpool_param_set(const c
59 static int zswap_enabled_param_set(const char *val,
60 const struct kernel_param *kp)
64 if (zswap_init_failed) {
65 pr_err("can't enable, initialization failed\n");
68 - if (!zswap_has_pool && zswap_init_started) {
69 - pr_err("can't enable, no pool configured\n");
73 - return param_set_bool(val, kp);
74 + ret = param_set_bool(val, kp);
75 + if (!ret && zswap_enabled && zswap_init_started && !zswap_has_pool)
76 + if (!zswap_try_pool_create())
82 /*********************************
83 @@ -1297,7 +1313,6 @@ static void __exit zswap_debugfs_exit(vo
84 **********************************/
85 static int __init init_zswap(void)
87 - struct zswap_pool *pool;
90 zswap_init_started = true;
91 @@ -1321,20 +1336,13 @@ static int __init init_zswap(void)
95 - pool = __zswap_pool_create_fallback();
97 - pr_info("loaded using pool %s/%s\n", pool->tfm_name,
98 - zpool_get_type(pool->zpool));
99 - list_add(&pool->list, &zswap_pools);
100 - zswap_has_pool = true;
102 - pr_err("pool creation failed\n");
103 - zswap_enabled = false;
106 frontswap_register_ops(&zswap_frontswap_ops);
107 if (zswap_debugfs_init())
108 pr_warn("debugfs initialization failed\n");
111 + zswap_try_pool_create();