* [RFC v3] mm/damon: add synchronous commit for commit_inputs
@ 2026-03-22 23:15 Liew Rui Yan
2026-03-23 14:22 ` SeongJae Park
0 siblings, 1 reply; 2+ messages in thread
From: Liew Rui Yan @ 2026-03-22 23:15 UTC (permalink / raw)
To: sj; +Cc: damon, linux-mm, Liew Rui Yan
Problem
=======
Writing invalid parameters to sysfs followed by 'commit_inputs=Y' fails
silently (no error returned to shell), because the validation happens
asynchronously in the kdamond.
Solution
========
To fix this, the commit_inputs_store() callback now uses damon_call() to
synchronously commit parameters in the kdamond thread's safe context.
This ensures that validation errors are returned immediately to
userspace, following the pattern used by DAMON_SYSFS.
Changes
=======
1. Added commit_inputs_store() and commit_inputs_fn() to commit
synchronously.
This change is motivated from another discussion [1].
[1] https://lore.kernel.org/20260318153731.97470-1-aethernet65535@gmail.com
Signed-off-by: Liew Rui Yan <aethernet65535@gmail.com>
---
Changes from RFC-v2:
- Removed damon_validate_attrs(), now using damon_commit_ctx() for
synchronous validation in the kdamond context.
- Following DAMON_SYSFS pattern for synchronous commit via damon_call().
- Link to RFC-v2: https://lore.kernel.org/20260321140926.22163-1-aethernet65535@gmail.com
Changes from RFC-v1:
- Remove question from commit message area.
- Added synchronous validation for DAMON_RECLAIM.
- Rename damon_valid_attrs() -> damon_validate_attrs().
- Exported a new function damon_validate_attrs() and declared it in
damon.h.
- Link to RFC-v1: https://lore.kernel.org/20260321002642.22712-1-aethernet65535@gmail.com
mm/damon/lru_sort.c | 42 +++++++++++++++++++++++++++++++++++++++++-
mm/damon/reclaim.c | 42 +++++++++++++++++++++++++++++++++++++++++-
2 files changed, 82 insertions(+), 2 deletions(-)
diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c
index 554559d72976..445e7aa19366 100644
--- a/mm/damon/lru_sort.c
+++ b/mm/damon/lru_sort.c
@@ -39,7 +39,6 @@ static bool enabled __read_mostly;
* the re-reading, DAMON_LRU_SORT will be disabled.
*/
static bool commit_inputs __read_mostly;
-module_param(commit_inputs, bool, 0600);
/*
* Desired active to [in]active memory ratio in bp (1/10,000).
@@ -361,6 +360,47 @@ static int damon_lru_sort_handle_commit_inputs(void)
return err;
}
+static int damon_lru_sort_commit_inputs_fn(void *arg)
+{
+ return damon_lru_sort_apply_parameters();
+}
+
+static int damon_lru_sort_commit_inputs_store(const char *val,
+ const struct kernel_param *kp)
+{
+ bool yes;
+ int err;
+ struct damon_call_control control = {
+ .fn = damon_lru_sort_commit_inputs_fn,
+ .data = ctx,
+ .repeat = false,
+ };
+
+ err = kstrtobool(val, &yes);
+ if (err)
+ return err;
+
+ if (commit_inputs == yes)
+ return 0;
+
+ if (!yes) {
+ commit_inputs = false;
+ return 0;
+ }
+
+ err = damon_call(ctx, &control);
+ if (err)
+ return err;
+ return control.return_code;
+}
+
+static const struct kernel_param_ops commit_inputs_param_ops = {
+ .set = damon_lru_sort_commit_inputs_store,
+ .get = param_get_bool,
+};
+
+module_param_cb(commit_inputs, &commit_inputs_param_ops, &commit_inputs, 0600);
+
static int damon_lru_sort_damon_call_fn(void *arg)
{
struct damon_ctx *c = arg;
diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c
index 86da14778658..5d0c02d4ff74 100644
--- a/mm/damon/reclaim.c
+++ b/mm/damon/reclaim.c
@@ -39,7 +39,6 @@ static bool enabled __read_mostly;
* re-reading, DAMON_RECLAIM will be disabled.
*/
static bool commit_inputs __read_mostly;
-module_param(commit_inputs, bool, 0600);
/*
* Time threshold for cold memory regions identification in microseconds.
@@ -267,6 +266,47 @@ static int damon_reclaim_handle_commit_inputs(void)
return err;
}
+static int damon_reclaim_commit_inputs_fn(void *arg)
+{
+ return damon_reclaim_apply_parameters();
+}
+
+static int damon_reclaim_commit_inputs_store(const char *val,
+ const struct kernel_param *kp)
+{
+ bool yes;
+ int err;
+ struct damon_call_control control = {
+ .fn = damon_reclaim_commit_inputs_fn,
+ .data = ctx,
+ .repeat = false,
+ };
+
+ err = kstrtobool(val, &yes);
+ if (err)
+ return err;
+
+ if (commit_inputs == yes)
+ return 0;
+
+ if (!yes) {
+ commit_inputs = false;
+ return 0;
+ }
+
+ err = damon_call(ctx, &control);
+ if (err)
+ return err;
+ return control.return_code;
+}
+
+static const struct kernel_param_ops commit_inputs_param_ops = {
+ .set = damon_reclaim_commit_inputs_store,
+ .get = param_get_bool,
+};
+
+module_param_cb(commit_inputs, &commit_inputs_param_ops, &commit_inputs, 0600);
+
static int damon_reclaim_damon_call_fn(void *arg)
{
struct damon_ctx *c = arg;
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [RFC v3] mm/damon: add synchronous commit for commit_inputs
2026-03-22 23:15 [RFC v3] mm/damon: add synchronous commit for commit_inputs Liew Rui Yan
@ 2026-03-23 14:22 ` SeongJae Park
0 siblings, 0 replies; 2+ messages in thread
From: SeongJae Park @ 2026-03-23 14:22 UTC (permalink / raw)
To: Liew Rui Yan; +Cc: SeongJae Park, damon, linux-mm
Hello Liew,
I show you posted rfc v4 of this patch [1]. So I'm skipping this.
[1] https://lore.kernel.org/20260323021648.6590-1-aethernet65535@gmail.com
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-23 14:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-22 23:15 [RFC v3] mm/damon: add synchronous commit for commit_inputs Liew Rui Yan
2026-03-23 14:22 ` SeongJae Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox