linux-mm.kvack.org archive mirror
 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 08/10] mm/damon/core: add damon_reset_aggregated() debug_sanity check
Date: Sat, 21 Feb 2026 11:36:25 -0800	[thread overview]
Message-ID: <20260221193629.19332-9-sj@kernel.org> (raw)
In-Reply-To: <20260221193629.19332-1-sj@kernel.org>

At time of damon_reset_aggregated(), aggregation of the interval should
be completed, and hence nr_accesses and nr_accesses_bp should match.  I
found a few bugs caused it to be broken in the past, from online
parameters update and complicated nr_accesses 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 | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 16f7994903d6d..4efe732e76c69 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1681,6 +1681,28 @@ static void damon_warn_fix_nr_accesses_corruption(struct damon_region *r)
 	r->nr_accesses_bp = r->nr_accesses * 10000;
 }
 
+#ifdef CONFIG_DAMON_DEBUG_SANITY
+static void damon_verify_reset_aggregated(struct damon_region *r,
+		struct damon_ctx *c)
+{
+	if (r->nr_accesses_bp == r->last_nr_accesses * 10000)
+		return;
+	pr_err("reset time invalid region found!\n");
+	pr_err("nr_accesses_bp %u last_nr_acceses %u\n",
+			r->nr_accesses_bp, r->last_nr_accesses);
+	pr_err("passed_sis %lu next_aggregation_sis %lu\n",
+			c->passed_sample_intervals,
+			c->next_aggregation_sis);
+	WARN_ONCE();
+}
+#else
+static void damon_verify_reset_aggregated(struct damon_region *r,
+		struct damon_ctx *c)
+{
+}
+#endif
+
+
 /*
  * Reset the aggregated monitoring results ('nr_accesses' of each region).
  */
@@ -1697,6 +1719,7 @@ static void kdamond_reset_aggregated(struct damon_ctx *c)
 			damon_warn_fix_nr_accesses_corruption(r);
 			r->last_nr_accesses = r->nr_accesses;
 			r->nr_accesses = 0;
+			damon_verify_reset_aggregated(r, c);
 		}
 		ti++;
 	}
-- 
2.47.3


  parent reply	other threads:[~2026-02-21 19:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-21 19:36 [RFC PATCH 00/10] mm/damon: add optional debugging-purpose sanity checks SeongJae Park
2026-02-21 19:36 ` [RFC PATCH 01/10] mm/damon: add CONFIG_DAMON_DEBUG_SANITY SeongJae Park
2026-02-21 19:36 ` [RFC PATCH 02/10] mm/damon/core: add damon_new_region() debug_sanity check SeongJae Park
2026-02-21 19:36 ` [RFC PATCH 03/10] mm/damon/core: add damon_del_region() " SeongJae Park
2026-02-21 19:36 ` [RFC PATCH 04/10] mm/damon/core: add damon_nr_regions() " SeongJae Park
2026-02-21 19:36 ` [RFC PATCH 05/10] mm/damon/core: add damon_merge_two_regions() " SeongJae Park
2026-02-21 19:36 ` [RFC PATCH 06/10] mm/damon/core: add damon_merge_regions_of() " SeongJae Park
2026-02-21 19:36 ` [RFC PATCH 07/10] mm/damon/core: add damon_split_region_at() " SeongJae Park
2026-02-21 19:36 ` SeongJae Park [this message]
2026-02-21 19:36 ` [RFC PATCH 09/10] mm/damon/tests/.kunitconifg: enable DAMON_DEBUG_SANITY SeongJae Park
2026-02-21 20:15   ` SeongJae Park
2026-02-21 19:36 ` [RFC PATCH 10/10] tools/testing/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=20260221193629.19332-9-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