bcm27xx: switch to kernel v6.1
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.15 / 950-0235-zswap-Defer-zswap-initialisation.patch
1 From 42487c7c83a14fd00b69038932baf6373d422b59 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 | 53 +++++++++++++++++++++++++++++------------------------
19 1 file changed, 29 insertions(+), 24 deletions(-)
20
21 --- a/mm/zswap.c
22 +++ b/mm/zswap.c
23 @@ -648,8 +648,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_acomp(zswap_compressor, 0, 0);
34 @@ -685,9 +686,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 - return zswap_pool_create(zswap_zpool_type, zswap_compressor);
44 + if (pool) {
45 + pr_info("loaded using pool %s/%s\n", pool->tfm_name,
46 + zpool_get_type(pool->zpool));
47 + list_add(&pool->list, &zswap_pools);
48 + zswap_has_pool = true;
49 + } else {
50 + pr_err("pool creation failed\n");
51 + zswap_enabled = false;
52 + }
53 +
54 + return zswap_enabled;
55 }
56
57 static void zswap_pool_destroy(struct zswap_pool *pool)
58 @@ -860,16 +873,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 @@ -1436,7 +1452,6 @@ static int __init zswap_debugfs_init(voi
84 **********************************/
85 static int __init init_zswap(void)
86 {
87 - struct zswap_pool *pool;
88 int ret;
89
90 zswap_init_started = true;
91 @@ -1460,29 +1475,19 @@ 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 shrink_wq = create_workqueue("zswap-shrink");
107 if (!shrink_wq)
108 - goto fallback_fail;
109 + goto hp_fail;
110
111 frontswap_register_ops(&zswap_frontswap_ops);
112 if (zswap_debugfs_init())
113 pr_warn("debugfs initialization failed\n");
114 +
115 + if (zswap_enabled)
116 + zswap_try_pool_create();
117 +
118 return 0;
119
120 -fallback_fail:
121 - if (pool)
122 - zswap_pool_destroy(pool);
123 hp_fail:
124 cpuhp_remove_state(CPUHP_MM_ZSWP_MEM_PREPARE);
125 dstmem_fail: