* [RFC PATCH v2 0/4] mm/damon/sysfs: refactor state input matching
@ 2026-11-28 22:29 SJ Park
2026-11-28 22:29 ` [RFC PATCH v2 1/4] mm/damon/sysfs: define damon_sysfs_cmd_name type and array SJ Park
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: SJ Park @ 2026-11-28 22:29 UTC (permalink / raw)
Cc: SJ Park, Andrew Morton, damon, linux-mm
DAMON sysfs interface uses an array of strings, damon_sysfs_cmd_strs,
for kdamond state file input matching. The array has expected input
strings in an order that matches that of enum damon_sysfs_cmd.
It is easy to mistakenly make the order broken. Other file input
handling functions use dedicated structs for such matching. Use the
pattern for kdamond state file.
Define a dedicated struct for the matching, and an array of the structs
for the existing inputs, via patch 1. Change kdamond state file write
and read handling functions to use the array of the new struct, via
patches 2 and 3. Finally, remove the input string array,
damon_sysfs_cmd_strs, which is no more being used, via patch 4.
Changes from RFC
- RFC: https://lore.kernel.org/20261126210619.97634-1-sj@kernel.org
- Collect R-b: from Lian.
- Remove unused NR_DAMON_SYSFS_CMDS.
- Rebase to the latest mm-new.
SJ Park (4):
mm/damon/sysfs: define damon_sysfs_cmd_name type and array
mm/damon/sysfs: use damon_sysfs_cmd_names in state_store()
mm/damon/sysfs: use damon_sysfs_cmd_names in state_show()
mm/damon/sysfs: remove damon_sysfs_cmd_strs and NR_DAMON_SYSFS_CMDS
mm/damon/sysfs.c | 87 +++++++++++++++++++++++++++++++++++-------------
1 file changed, 64 insertions(+), 23 deletions(-)
base-commit: 23cd682622886800b912219e307cf46a99f69c10
--
2.47.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* [RFC PATCH v2 1/4] mm/damon/sysfs: define damon_sysfs_cmd_name type and array
2026-11-28 22:29 [RFC PATCH v2 0/4] mm/damon/sysfs: refactor state input matching SJ Park
@ 2026-11-28 22:29 ` SJ Park
2026-11-28 22:29 ` [RFC PATCH v2 2/4] mm/damon/sysfs: use damon_sysfs_cmd_names in state_store() SJ Park
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: SJ Park @ 2026-11-28 22:29 UTC (permalink / raw)
Cc: SJ Park, Andrew Morton, damon, linux-mm, Lian Wang
Define a new struct for kdamond state file user input handling. The
struct explains what user inputs are for what kdamond commands Define
an array of the structs for all existing inputs.
Reviewed-by: Lian Wang <lianux.mm@gmail.com>
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/sysfs.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index 0049aac6ab97..c76063b703a4 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -2254,6 +2254,54 @@ static const char * const damon_sysfs_cmd_strs[] = {
"update_tuned_intervals",
};
+struct damon_sysfs_cmd_name {
+ enum damon_sysfs_cmd cmd;
+ char *name;
+};
+
+static const struct damon_sysfs_cmd_name damon_sysfs_cmd_names[] = {
+ {
+ .cmd = DAMON_SYSFS_CMD_ON,
+ .name = "on",
+ },
+ {
+ .cmd = DAMON_SYSFS_CMD_OFF,
+ .name = "off",
+ },
+ {
+ .cmd = DAMON_SYSFS_CMD_COMMIT,
+ .name = "commit",
+ },
+ {
+ .cmd = DAMON_SYSFS_CMD_COMMIT_SCHEMES_QUOTA_GOALS,
+ .name = "commit_schemes_quota_goals",
+ },
+ {
+ .cmd = DAMON_SYSFS_CMD_UPDATE_SCHEMES_STATS,
+ .name = "update_schemes_stats",
+ },
+ {
+ .cmd = DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_BYTES,
+ .name = "update_schemes_tried_bytes",
+ },
+ {
+ .cmd = DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS,
+ .name = "update_schemes_tried_regions",
+ },
+ {
+ .cmd = DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS,
+ .name = "clear_schemes_tried_regions",
+ },
+ {
+ .cmd = DAMON_SYSFS_CMD_UPDATE_SCHEMES_EFFECTIVE_QUOTAS,
+ .name = "update_schemes_effective_quotas",
+ },
+ {
+ .cmd = DAMON_SYSFS_CMD_UPDATE_TUNED_INTERVALS,
+ .name = "update_tuned_intervals",
+ },
+};
+
static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [RFC PATCH v2 2/4] mm/damon/sysfs: use damon_sysfs_cmd_names in state_store()
2026-11-28 22:29 [RFC PATCH v2 0/4] mm/damon/sysfs: refactor state input matching SJ Park
2026-11-28 22:29 ` [RFC PATCH v2 1/4] mm/damon/sysfs: define damon_sysfs_cmd_name type and array SJ Park
@ 2026-11-28 22:29 ` SJ Park
2026-11-28 22:29 ` [RFC PATCH v2 3/4] mm/damon/sysfs: use damon_sysfs_cmd_names in state_show() SJ Park
2026-11-28 22:29 ` [RFC PATCH v2 4/4] mm/damon/sysfs: remove damon_sysfs_cmd_strs and NR_DAMON_SYSFS_CMDS SJ Park
3 siblings, 0 replies; 5+ messages in thread
From: SJ Park @ 2026-11-28 22:29 UTC (permalink / raw)
Cc: SJ Park, Andrew Morton, damon, linux-mm, Lian Wang
Update kdamond state file write handling function to use
damon_sysfs_cmd_names instead of damon_sysfs_strs.
Reviewed-by: Lian Wang <lianux.mm@gmail.com>
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/sysfs.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index c76063b703a4..e0ddf4ed5dbb 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -2848,14 +2848,17 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr,
{
struct damon_sysfs_kdamond *kdamond = container_of(kobj,
struct damon_sysfs_kdamond, kobj);
- enum damon_sysfs_cmd cmd;
ssize_t ret = -EINVAL;
+ int i;
if (!mutex_trylock(&damon_sysfs_lock))
return -EBUSY;
- for (cmd = 0; cmd < NR_DAMON_SYSFS_CMDS; cmd++) {
- if (sysfs_streq(buf, damon_sysfs_cmd_strs[cmd])) {
- ret = damon_sysfs_handle_cmd(cmd, kdamond);
+ for (i = 0; i < ARRAY_SIZE(damon_sysfs_cmd_names); i++) {
+ const struct damon_sysfs_cmd_name *cmd_name;
+
+ cmd_name = &damon_sysfs_cmd_names[i];
+ if (sysfs_streq(buf, cmd_name->name)) {
+ ret = damon_sysfs_handle_cmd(cmd_name->cmd, kdamond);
break;
}
}
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [RFC PATCH v2 3/4] mm/damon/sysfs: use damon_sysfs_cmd_names in state_show()
2026-11-28 22:29 [RFC PATCH v2 0/4] mm/damon/sysfs: refactor state input matching SJ Park
2026-11-28 22:29 ` [RFC PATCH v2 1/4] mm/damon/sysfs: define damon_sysfs_cmd_name type and array SJ Park
2026-11-28 22:29 ` [RFC PATCH v2 2/4] mm/damon/sysfs: use damon_sysfs_cmd_names in state_store() SJ Park
@ 2026-11-28 22:29 ` SJ Park
2026-11-28 22:29 ` [RFC PATCH v2 4/4] mm/damon/sysfs: remove damon_sysfs_cmd_strs and NR_DAMON_SYSFS_CMDS SJ Park
3 siblings, 0 replies; 5+ messages in thread
From: SJ Park @ 2026-11-28 22:29 UTC (permalink / raw)
Cc: SJ Park, Andrew Morton, damon, linux-mm, Lian Wang
Update kdamond state file read handling function to use
damon_sysfs_cmd_names instead of damon_sysfs_cmd_strs.
Reviewed-by: Lian Wang <lianux.mm@gmail.com>
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/sysfs.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index e0ddf4ed5dbb..5a91a1c3e438 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -2309,6 +2309,8 @@ static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,
struct damon_sysfs_kdamond, kobj);
struct damon_ctx *ctx;
bool running = false;
+ enum damon_sysfs_cmd cmd;
+ int i;
if (!mutex_trylock(&damon_sysfs_lock))
return -EBUSY;
@@ -2319,9 +2321,15 @@ static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,
mutex_unlock(&damon_sysfs_lock);
- return sysfs_emit(buf, "%s\n", running ?
- damon_sysfs_cmd_strs[DAMON_SYSFS_CMD_ON] :
- damon_sysfs_cmd_strs[DAMON_SYSFS_CMD_OFF]);
+ cmd = running ? DAMON_SYSFS_CMD_ON : DAMON_SYSFS_CMD_OFF;
+ for (i = 0; i < ARRAY_SIZE(damon_sysfs_cmd_names); i++) {
+ const struct damon_sysfs_cmd_name *cmd_name;
+
+ cmd_name = &damon_sysfs_cmd_names[i];
+ if (cmd_name->cmd == cmd)
+ return sysfs_emit(buf, "%s\n", cmd_name->name);
+ }
+ return -EINVAL;
}
static int damon_sysfs_set_attrs(struct damon_ctx *ctx,
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [RFC PATCH v2 4/4] mm/damon/sysfs: remove damon_sysfs_cmd_strs and NR_DAMON_SYSFS_CMDS
2026-11-28 22:29 [RFC PATCH v2 0/4] mm/damon/sysfs: refactor state input matching SJ Park
` (2 preceding siblings ...)
2026-11-28 22:29 ` [RFC PATCH v2 3/4] mm/damon/sysfs: use damon_sysfs_cmd_names in state_show() SJ Park
@ 2026-11-28 22:29 ` SJ Park
3 siblings, 0 replies; 5+ messages in thread
From: SJ Park @ 2026-11-28 22:29 UTC (permalink / raw)
Cc: SJ Park, Andrew Morton, damon, linux-mm, Lian Wang
Remove damon_sysfs_cmd_strs and NR_DAMON_SYSFS_CMDS, which are not being
used.
Reviewed-by: Lian Wang <lianux.mm@gmail.com>
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/sysfs.c | 18 ------------------
1 file changed, 18 deletions(-)
diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index 5a91a1c3e438..1ae072675ba3 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -2234,24 +2234,6 @@ enum damon_sysfs_cmd {
* intervals.
*/
DAMON_SYSFS_CMD_UPDATE_TUNED_INTERVALS,
- /*
- * @NR_DAMON_SYSFS_CMDS: Total number of DAMON sysfs commands.
- */
- NR_DAMON_SYSFS_CMDS,
-};
-
-/* Should match with enum damon_sysfs_cmd */
-static const char * const damon_sysfs_cmd_strs[] = {
- "on",
- "off",
- "commit",
- "commit_schemes_quota_goals",
- "update_schemes_stats",
- "update_schemes_tried_bytes",
- "update_schemes_tried_regions",
- "clear_schemes_tried_regions",
- "update_schemes_effective_quotas",
- "update_tuned_intervals",
};
struct damon_sysfs_cmd_name {
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-28 22:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28 22:29 [RFC PATCH v2 0/4] mm/damon/sysfs: refactor state input matching SJ Park
2026-11-28 22:29 ` [RFC PATCH v2 1/4] mm/damon/sysfs: define damon_sysfs_cmd_name type and array SJ Park
2026-11-28 22:29 ` [RFC PATCH v2 2/4] mm/damon/sysfs: use damon_sysfs_cmd_names in state_store() SJ Park
2026-11-28 22:29 ` [RFC PATCH v2 3/4] mm/damon/sysfs: use damon_sysfs_cmd_names in state_show() SJ Park
2026-11-28 22:29 ` [RFC PATCH v2 4/4] mm/damon/sysfs: remove damon_sysfs_cmd_strs and NR_DAMON_SYSFS_CMDS SJ Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox