From: SeongJae Park <sj@kernel.org>
Cc: SeongJae Park <sj@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
bijan311@gmail.com, damon@lists.linux.dev,
linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [RFC PATCH 2/5] mm/damon/sysfs: test commit input against realistic destination
Date: Thu, 16 Oct 2025 14:47:29 -0700 [thread overview]
Message-ID: <20251016214736.84286-3-sj@kernel.org> (raw)
In-Reply-To: <20251016214736.84286-1-sj@kernel.org>
DAMON sysfs interface tests if given online parameters update request is
valid, by committing those using the DAMON kernel API, to a test-purpose
destination context. The test-purpose destination context is
constructed using damon_new_ctx(), so it has no target, no scheme.
If a source target has obsolete field set, the test-purpose commit will
fail because damon_commit_targets() fails when there is a source
obsolete target that cannot find its matching destination target. DAMON
sysfs interface is not letting users set the field for now, so there is
no problem. However, a following commit will support that. Also there
could be similar future changes that making commit fails based on
current context structure.
Make the test purpose commit destination context similar to the current
running one, by committing the running one to the test purpose context,
before doing the real test-purpose commit.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/sysfs.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index dfdf69bdbbd3..6848437b86af 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -1680,6 +1680,26 @@ static int damon_sysfs_apply_inputs(struct damon_ctx *ctx,
static struct damon_ctx *damon_sysfs_build_ctx(
struct damon_sysfs_context *sys_ctx);
+/*
+ * Return a new damon_ctx for testing new parameters to commit.
+ */
+static struct damon_ctx *damon_sysfs_new_test_ctx(
+ struct damon_ctx *running_ctx)
+{
+ struct damon_ctx *test_ctx;
+ int err;
+
+ test_ctx = damon_new_ctx();
+ if (!test_ctx)
+ return NULL;
+ err = damon_commit_ctx(test_ctx, running_ctx);
+ if (err) {
+ damon_destroy_ctx(test_ctx);
+ return NULL;
+ }
+ return test_ctx;
+}
+
/*
* damon_sysfs_commit_input() - Commit user inputs to a running kdamond.
* @kdamond: The kobject wrapper for the associated kdamond.
@@ -1701,7 +1721,7 @@ static int damon_sysfs_commit_input(void *data)
param_ctx = damon_sysfs_build_ctx(kdamond->contexts->contexts_arr[0]);
if (IS_ERR(param_ctx))
return PTR_ERR(param_ctx);
- test_ctx = damon_new_ctx();
+ test_ctx = damon_sysfs_new_test_ctx(kdamond->damon_ctx);
if (!test_ctx)
return -ENOMEM;
err = damon_commit_ctx(test_ctx, param_ctx);
--
2.47.3
next prev parent reply other threads:[~2025-10-16 21:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-16 21:47 [RFC PATCH 0/5] mm/damon: support pin-point targets removal SeongJae Park
2025-10-16 21:47 ` [RFC PATCH 1/5] mm/damon/core: add damon_target->obsolete for pin-point removal SeongJae Park
2025-10-17 14:52 ` Bijan Tabatabai
2025-10-17 16:30 ` SeongJae Park
2025-10-16 21:47 ` SeongJae Park [this message]
2025-10-16 21:47 ` [RFC PATCH 3/5] mm/damon/sysfs: implement obsolete_target file SeongJae Park
2025-10-16 21:47 ` [RFC PATCH 4/5] Docs/admin-guide/mm/damon/usage: document " SeongJae Park
2025-10-16 21:47 ` [RFC PATCH 5/5] Docs/ABI/damon: document obsolete_target sysfs file SeongJae Park
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251016214736.84286-3-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=bijan311@gmail.com \
--cc=damon@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox