public inbox for linux-mm@kvack.org
 help / color / mirror / Atom feed
From: SeongJae Park <sj@kernel.org>
Cc: SeongJae Park <sj@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	damon@lists.linux.dev, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org
Subject: [RFC PATCH v5 01/10] mm/damon/core: introduce damon_ctx->paused
Date: Mon, 23 Mar 2026 16:15:26 -0700	[thread overview]
Message-ID: <20260323231538.84452-2-sj@kernel.org> (raw)
In-Reply-To: <20260323231538.84452-1-sj@kernel.org>

DAMON supports only start and stop of the execution.  When it is
stopped, its internal data that it self-trained goes away.  It will be
useful if the execution can be paused and resumed with the previous
self-trained data.

Introduce per-context API parameter, 'paused', for the purpose.  The
parameter can be set and unset while DAMON is running and paused, using
the online parameters commit helper functions (damon_commit_ctx() and
damon_call()).  Once 'paused' is set, the kdamond_fn() main loop does
only limited works with sampling interval sleep during the works.  The
limited works include the handling of the online parameters update, so
that users can unset the 'pause' and resume the execution when they
want.  It also keep checking DAMON stop conditions and handling of it,
so that DAMON can be stopped while paused if needed.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 include/linux/damon.h | 2 ++
 mm/damon/core.c       | 9 +++++++++
 2 files changed, 11 insertions(+)

diff --git a/include/linux/damon.h b/include/linux/damon.h
index 04c8a052fcfbe..65c8d5ef510fe 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -787,6 +787,7 @@ struct damon_attrs {
  * @ops:	Set of monitoring operations for given use cases.
  * @addr_unit:	Scale factor for core to ops address conversion.
  * @min_region_sz:	Minimum region size.
+ * @pause:	Pause kdamond main loop.
  * @adaptive_targets:	Head of monitoring targets (&damon_target) list.
  * @schemes:		Head of schemes (&damos) list.
  */
@@ -838,6 +839,7 @@ struct damon_ctx {
 	struct damon_operations ops;
 	unsigned long addr_unit;
 	unsigned long min_region_sz;
+	bool pause;
 
 	struct list_head adaptive_targets;
 	struct list_head schemes;
diff --git a/mm/damon/core.c b/mm/damon/core.c
index db6c67e52d2b8..0ab2cfa848e69 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1349,6 +1349,7 @@ int damon_commit_ctx(struct damon_ctx *dst, struct damon_ctx *src)
 		if (err)
 			return err;
 	}
+	dst->pause = src->pause;
 	dst->ops = src->ops;
 	dst->addr_unit = src->addr_unit;
 	dst->min_region_sz = src->min_region_sz;
@@ -3003,6 +3004,14 @@ static int kdamond_fn(void *data)
 		kdamond_call(ctx, false);
 		if (ctx->maybe_corrupted)
 			break;
+		while (ctx->pause) {
+			damos_walk_cancel(ctx);
+			kdamond_usleep(ctx->attrs.sample_interval);
+			/* allow caller unset pause via damon_call() */
+			kdamond_call(ctx, false);
+			if (kdamond_need_stop(ctx) || ctx->maybe_corrupted)
+				goto done;
+		}
 		if (!list_empty(&ctx->schemes))
 			kdamond_apply_schemes(ctx);
 		else
-- 
2.47.3


  reply	other threads:[~2026-03-23 23:15 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-23 23:15 [RFC PATCH v5 00/10] mm/damon: let DAMON be paused and resumed SeongJae Park
2026-03-23 23:15 ` SeongJae Park [this message]
2026-03-24  1:28   ` (sashiko review) [RFC PATCH v5 01/10] mm/damon/core: introduce damon_ctx->paused SeongJae Park
2026-03-24  4:07     ` SeongJae Park
2026-03-23 23:15 ` [RFC PATCH v5 02/10] mm/damon/sysfs: add pause file under context dir SeongJae Park
2026-03-23 23:15 ` [RFC PATCH v5 03/10] Docs/mm/damon/design: update for context pause/resume feature SeongJae Park
2026-03-23 23:15 ` [RFC PATCH v5 04/10] Docs/admin-guide/mm/damon/usage: update for pause file SeongJae Park
2026-03-23 23:15 ` [RFC PATCH v5 05/10] Docs/ABI/damon: update for pause sysfs file SeongJae Park
2026-03-23 23:15 ` [RFC PATCH v5 06/10] mm/damon/tests/core-kunit: test pause commitment SeongJae Park
2026-03-23 23:15 ` [RFC PATCH v5 07/10] selftests/damon/_damon_sysfs: support pause file staging SeongJae Park
2026-03-24  1:28   ` (sashiko review) " SeongJae Park
2026-03-24  4:08     ` SeongJae Park
2026-03-23 23:15 ` [RFC PATCH v5 08/10] selftests/damon/drgn_dump_damon_status: dump pause SeongJae Park
2026-03-23 23:15 ` [RFC PATCH v5 09/10] selftests/damon/sysfs.py: check pause on assert_ctx_committed() SeongJae Park
2026-03-23 23:15 ` [RFC PATCH v5 10/10] selftests/damon/sysfs.py: pause DAMON before dumping status SeongJae Park
2026-03-24  1:27 ` (sashiko status) [RFC PATCH v5 00/10] mm/damon: let DAMON be paused and resumed 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=20260323231538.84452-2-sj@kernel.org \
    --to=sj@kernel.org \
    --cc=akpm@linux-foundation.org \
    --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