|
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 |
|
@@ -235,38 +234,31 @@ static int damon_lru_sort_turn(bool on)
|
235 | 234 | return 0;
|
236 | 235 | }
|
237 | 236 |
|
238 |
| -static struct delayed_work damon_lru_sort_timer; |
239 |
| -static void damon_lru_sort_timer_fn(struct work_struct *work) |
240 |
| -{ |
241 |
| - static bool last_enabled; |
242 |
| - bool now_enabled; |
243 |
| - |
244 |
| - now_enabled = enabled; |
245 |
| - if (last_enabled != now_enabled) { |
246 |
| - if (!damon_lru_sort_turn(now_enabled)) |
247 |
| - last_enabled = now_enabled; |
248 |
| - else |
249 |
| - enabled = last_enabled; |
250 |
| - } |
251 |
| -} |
252 |
| -static DECLARE_DELAYED_WORK(damon_lru_sort_timer, damon_lru_sort_timer_fn); |
253 |
| - |
254 |
| -static bool damon_lru_sort_initialized; |
255 |
| - |
256 | 237 | static int damon_lru_sort_enabled_store(const char *val,
|
257 | 238 | const struct kernel_param *kp)
|
258 | 239 | {
|
259 |
| - int rc = param_set_bool(val, kp); |
| 240 | + bool is_enabled = enabled; |
| 241 | + bool enable; |
| 242 | + int err; |
| 243 | + |
| 244 | + err = strtobool(val, &enable); |
| 245 | + if (err) |
| 246 | + return err; |
260 | 247 |
|
261 |
| - if (rc < 0) |
262 |
| - return rc; |
| 248 | + if (is_enabled == enable) |
| 249 | + return 0; |
263 | 250 |
|
264 |
| - if (!damon_lru_sort_initialized) |
265 |
| - return rc; |
| 251 | + /* Called before init function. The function will handle this. */ |
| 252 | + if (!ctx) |
| 253 | + goto set_param_out; |
266 | 254 |
|
267 |
| - schedule_delayed_work(&damon_lru_sort_timer, 0); |
| 255 | + err = damon_lru_sort_turn(enable); |
| 256 | + if (err) |
| 257 | + return err; |
268 | 258 |
|
269 |
| - return 0; |
| 259 | +set_param_out: |
| 260 | + enabled = enable; |
| 261 | + return err; |
270 | 262 | }
|
271 | 263 |
|
272 | 264 | static const struct kernel_param_ops enabled_param_ops = {
|
@@ -320,10 +312,11 @@ static int __init damon_lru_sort_init(void)
|
320 | 312 | ctx->callback.after_wmarks_check = damon_lru_sort_after_wmarks_check;
|
321 | 313 | ctx->callback.after_aggregation = damon_lru_sort_after_aggregation;
|
322 | 314 |
|
323 |
| - schedule_delayed_work(&damon_lru_sort_timer, 0); |
| 315 | + /* 'enabled' has set before this function, probably via command line */ |
| 316 | + if (enabled) |
| 317 | + err = damon_lru_sort_turn(true); |
324 | 318 |
|
325 |
| - damon_lru_sort_initialized = true; |
326 |
| - return 0; |
| 319 | + return err; |
327 | 320 | }
|
328 | 321 |
|
329 | 322 | module_init(damon_lru_sort_init);
|
0 commit comments