Skip to content

Commit 04e9876

Browse files
sjp38akpm00
authored andcommitted
mm/damon/reclaim: enable and disable synchronously
Patch series "mm/damon/reclaim,lru_sort: enable/disable synchronously". Writing a value to DAMON_RECLAIM and DAMON_LRU_SORT's 'enabled' parameters turns on or off DAMON in an ansychronous way. This means the parameter cannot be used to read the current status of them. '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. The first and second patches changes the behavior of the 'enabled' parameter for DAMON_RECLAIM and adds a selftest for the changed behavior, respectively. Following two patches make the same changes for DAMON_LRU_SORT. This patch (of 4): 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] 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 b0d3dbd commit 04e9876

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

mm/damon/reclaim.c

Lines changed: 23 additions & 30 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

@@ -181,38 +180,31 @@ static int damon_reclaim_turn(bool on)
181180
return 0;
182181
}
183182

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-
202183
static int damon_reclaim_enabled_store(const char *val,
203184
const struct kernel_param *kp)
204185
{
205-
int rc = param_set_bool(val, kp);
186+
bool is_enabled = enabled;
187+
bool enable;
188+
int err;
206189

207-
if (rc < 0)
208-
return rc;
190+
err = strtobool(val, &enable);
191+
if (err)
192+
return err;
209193

210-
/* system_wq might not initialized yet */
211-
if (!damon_reclaim_initialized)
212-
return rc;
194+
if (is_enabled == enable)
195+
return 0;
213196

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;
216208
}
217209

218210
static const struct kernel_param_ops enabled_param_ops = {
@@ -262,10 +254,11 @@ static int __init damon_reclaim_init(void)
262254
ctx->callback.after_wmarks_check = damon_reclaim_after_wmarks_check;
263255
ctx->callback.after_aggregation = damon_reclaim_after_aggregation;
264256

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

267-
damon_reclaim_initialized = true;
268-
return 0;
261+
return err;
269262
}
270263

271264
module_init(damon_reclaim_init);

0 commit comments

Comments
 (0)