Skip to content

Commit 7a034fb

Browse files
sjp38akpm00
authored andcommitted
mm/damon/lru_sort: enable and disable synchronously
Writing a value to DAMON_RECLAIM's 'enabled' parameter turns on or off DAMON in an ansychronous way. This means the parameter cannot be used to read the current status of DAMON_RECLAIM. 'kdamond_pid' parameter should be used instead for the purpose. The documentation is easy to be read as it works in a synchronous way, so it is a little bit confusing. It also makes the user space tooling dirty. There's no real reason to have the asynchronous behavior, though. Simply make the parameter works synchronously, rather than updating the document. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: SeongJae Park <[email protected]> Cc: Shuah Khan <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 4cc0ee7 commit 7a034fb

File tree

1 file changed

+22
-29
lines changed

1 file changed

+22
-29
lines changed

mm/damon/lru_sort.c

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include <linux/damon.h>
1111
#include <linux/module.h>
12-
#include <linux/workqueue.h>
1312

1413
#include "modules-common.h"
1514

@@ -235,38 +234,31 @@ static int damon_lru_sort_turn(bool on)
235234
return 0;
236235
}
237236

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-
256237
static int damon_lru_sort_enabled_store(const char *val,
257238
const struct kernel_param *kp)
258239
{
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;
260247

261-
if (rc < 0)
262-
return rc;
248+
if (is_enabled == enable)
249+
return 0;
263250

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;
266254

267-
schedule_delayed_work(&damon_lru_sort_timer, 0);
255+
err = damon_lru_sort_turn(enable);
256+
if (err)
257+
return err;
268258

269-
return 0;
259+
set_param_out:
260+
enabled = enable;
261+
return err;
270262
}
271263

272264
static const struct kernel_param_ops enabled_param_ops = {
@@ -320,10 +312,11 @@ static int __init damon_lru_sort_init(void)
320312
ctx->callback.after_wmarks_check = damon_lru_sort_after_wmarks_check;
321313
ctx->callback.after_aggregation = damon_lru_sort_after_aggregation;
322314

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);
324318

325-
damon_lru_sort_initialized = true;
326-
return 0;
319+
return err;
327320
}
328321

329322
module_init(damon_lru_sort_init);

0 commit comments

Comments
 (0)