firmware-utils: bump to git HEAD
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0742-zswap-Defer-zswap-initialisation.patch
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
5
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.
13
14 See: https://github.com/raspberrypi/linux/pull/3432
15
16 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
17 ---
18 mm/zswap.c | 48 ++++++++++++++++++++++++++++--------------------
19 1 file changed, 28 insertions(+), 20 deletions(-)
20
21 --- a/mm/zswap.c
22 +++ b/mm/zswap.c
23 @@ -564,8 +564,9 @@ error:
24 return NULL;
25 }
26
27 -static __init struct zswap_pool *__zswap_pool_create_fallback(void)
28 +static bool zswap_try_pool_create(void)
29 {
30 + struct zswap_pool *pool;
31 bool has_comp, has_zpool;
32
33 has_comp = crypto_has_comp(zswap_compressor, 0, 0);
34 @@ -599,9 +600,21 @@ static __init struct zswap_pool *__zswap
35 }
36
37 if (!has_comp || !has_zpool)
38 - return NULL;
39 + return false;
40 +
41 + pool = zswap_pool_create(zswap_zpool_type, zswap_compressor);
42 +
43 + if (pool) {
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;
48 + } else {
49 + pr_err("pool creation failed\n");
50 + zswap_enabled = false;
51 + }
52
53 - return zswap_pool_create(zswap_zpool_type, zswap_compressor);
54 + return zswap_enabled;
55 }
56
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)
61 {
62 + int ret;
63 +
64 if (zswap_init_failed) {
65 pr_err("can't enable, initialization failed\n");
66 return -ENODEV;
67 }
68 - if (!zswap_has_pool && zswap_init_started) {
69 - pr_err("can't enable, no pool configured\n");
70 - return -ENODEV;
71 - }
72
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())
77 + ret = -ENODEV;
78 +
79 + return ret;
80 }
81
82 /*********************************
83 @@ -1297,7 +1313,6 @@ static void __exit zswap_debugfs_exit(vo
84 **********************************/
85 static int __init init_zswap(void)
86 {
87 - struct zswap_pool *pool;
88 int ret;
89
90 zswap_init_started = true;
91 @@ -1321,20 +1336,13 @@ static int __init init_zswap(void)
92 if (ret)
93 goto hp_fail;
94
95 - pool = __zswap_pool_create_fallback();
96 - if (pool) {
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;
101 - } else {
102 - pr_err("pool creation failed\n");
103 - zswap_enabled = false;
104 - }
105 -
106 frontswap_register_ops(&zswap_frontswap_ops);
107 if (zswap_debugfs_init())
108 pr_warn("debugfs initialization failed\n");
109 +
110 + if (zswap_enabled)
111 + zswap_try_pool_create();
112 +
113 return 0;
114
115 hp_fail: