|
9 | 9 |
|
10 | 10 | #include <linux/damon.h>
|
11 | 11 | #include <linux/module.h>
|
12 |
| -#include <linux/workqueue.h> |
13 | 12 |
|
14 | 13 | #include "modules-common.h"
|
15 | 14 |
|
@@ -181,38 +180,31 @@ static int damon_reclaim_turn(bool on)
|
181 | 180 | return 0;
|
182 | 181 | }
|
183 | 182 |
|
184 |
| -static struct delayed_work damon_reclaim_timer; |
185 |
| -static void damon_reclaim_timer_fn(struct work_struct *work) |
186 |
| -{ |
187 |
| - static bool last_enabled; |
188 |
| - bool now_enabled; |
189 |
| - |
190 |
| - now_enabled = enabled; |
191 |
| - if (last_enabled != now_enabled) { |
192 |
| - if (!damon_reclaim_turn(now_enabled)) |
193 |
| - last_enabled = now_enabled; |
194 |
| - else |
195 |
| - enabled = last_enabled; |
196 |
| - } |
197 |
| -} |
198 |
| -static DECLARE_DELAYED_WORK(damon_reclaim_timer, damon_reclaim_timer_fn); |
199 |
| - |
200 |
| -static bool damon_reclaim_initialized; |
201 |
| - |
202 | 183 | static int damon_reclaim_enabled_store(const char *val,
|
203 | 184 | const struct kernel_param *kp)
|
204 | 185 | {
|
205 |
| - int rc = param_set_bool(val, kp); |
| 186 | + bool is_enabled = enabled; |
| 187 | + bool enable; |
| 188 | + int err; |
206 | 189 |
|
207 |
| - if (rc < 0) |
208 |
| - return rc; |
| 190 | + err = strtobool(val, &enable); |
| 191 | + if (err) |
| 192 | + return err; |
209 | 193 |
|
210 |
| - /* system_wq might not initialized yet */ |
211 |
| - if (!damon_reclaim_initialized) |
212 |
| - return rc; |
| 194 | + if (is_enabled == enable) |
| 195 | + return 0; |
213 | 196 |
|
214 |
| - schedule_delayed_work(&damon_reclaim_timer, 0); |
215 |
| - return 0; |
| 197 | + /* Called before init function. The function will handle this. */ |
| 198 | + if (!ctx) |
| 199 | + goto set_param_out; |
| 200 | + |
| 201 | + err = damon_reclaim_turn(enable); |
| 202 | + if (err) |
| 203 | + return err; |
| 204 | + |
| 205 | +set_param_out: |
| 206 | + enabled = enable; |
| 207 | + return err; |
216 | 208 | }
|
217 | 209 |
|
218 | 210 | static const struct kernel_param_ops enabled_param_ops = {
|
@@ -262,10 +254,11 @@ static int __init damon_reclaim_init(void)
|
262 | 254 | ctx->callback.after_wmarks_check = damon_reclaim_after_wmarks_check;
|
263 | 255 | ctx->callback.after_aggregation = damon_reclaim_after_aggregation;
|
264 | 256 |
|
265 |
| - schedule_delayed_work(&damon_reclaim_timer, 0); |
| 257 | + /* 'enabled' has set before this function, probably via command line */ |
| 258 | + if (enabled) |
| 259 | + err = damon_reclaim_turn(true); |
266 | 260 |
|
267 |
| - damon_reclaim_initialized = true; |
268 |
| - return 0; |
| 261 | + return err; |
269 | 262 | }
|
270 | 263 |
|
271 | 264 | module_init(damon_reclaim_init);
|
0 commit comments