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 v2 06/10] mm/damon/core: add damon_merge_regions_of() debug_sanity check
Date: Sun, 1 Mar 2026 09:43:21 -0800 [thread overview]
Message-ID: <20260301174327.76849-7-sj@kernel.org> (raw)
In-Reply-To: <20260301174327.76849-1-sj@kernel.org>
damon_merge_regions_of() should be called only after aggregation is
finished and therefore each region's nr_accesses and nr_accesses_bp
match. There were bugs that broke the assumption, during development of
online DAMON parameter updates and monitoring results handling changes.
Add a sanity check for that under CONFIG_DAMON_DEBUG_SANITY.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/core.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 8a3738a17cdd9..93d1577b1ae07 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2505,6 +2505,20 @@ static void damon_merge_two_regions(struct damon_target *t,
damon_destroy_region(r, t);
}
+#ifdef CONFIG_DAMON_DEBUG_SANITY
+static void damon_verify_merge_regions_of(struct damon_region *r)
+{
+ WARN_ONCE(r->nr_accesses != r->nr_accesses_bp / 10000,
+ "nr_accesses (%u) != nr_accesses_bp (%u)\n",
+ r->nr_accesses, r->nr_accesses_bp);
+}
+#else
+static void damon_verify_merge_regions_of(struct damon_region *r)
+{
+}
+#endif
+
+
/*
* Merge adjacent regions having similar access frequencies
*
@@ -2518,6 +2532,7 @@ static void damon_merge_regions_of(struct damon_target *t, unsigned int thres,
struct damon_region *r, *prev = NULL, *next;
damon_for_each_region_safe(r, next, t) {
+ damon_verify_merge_regions_of(r);
if (abs(r->nr_accesses - r->last_nr_accesses) > thres)
r->age = 0;
else if ((r->nr_accesses == 0) != (r->last_nr_accesses == 0))
--
2.47.3
next prev parent reply other threads:[~2026-03-01 17:43 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-01 17:43 [RFC PATCH v2 00/10] mm/damon: add optional debugging-purpose sanity checks SeongJae Park
2026-03-01 17:43 ` [RFC PATCH v2 01/10] mm/damon: add CONFIG_DAMON_DEBUG_SANITY SeongJae Park
2026-03-01 17:43 ` [RFC PATCH v2 02/10] mm/damon/core: add damon_new_region() debug_sanity check SeongJae Park
2026-03-01 17:43 ` [RFC PATCH v2 03/10] mm/damon/core: add damon_del_region() " SeongJae Park
2026-03-01 17:43 ` [RFC PATCH v2 04/10] mm/damon/core: add damon_nr_regions() " SeongJae Park
2026-03-01 17:43 ` [RFC PATCH v2 05/10] mm/damon/core: add damon_merge_two_regions() " SeongJae Park
2026-03-01 17:43 ` SeongJae Park [this message]
2026-03-01 17:43 ` [RFC PATCH v2 07/10] mm/damon/core: add damon_split_region_at() " SeongJae Park
2026-03-01 17:43 ` [RFC PATCH v2 08/10] mm/damon/core: add damon_reset_aggregated() " SeongJae Park
2026-03-01 17:43 ` [RFC PATCH v2 09/10] mm/damon/tests/.kunitconifg: enable DAMON_DEBUG_SANITY SeongJae Park
2026-03-01 17:43 ` [RFC PATCH v2 10/10] selftests/damon/config: " 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=20260301174327.76849-7-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