From: SeongJae Park <sj@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: SeongJae Park <sj@kernel.org>,
damon@lists.linux.dev, kernel-team@meta.com,
linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH 1/6] mm/damon/core: warn and fix nr_accesses[_bp] corruption
Date: Mon, 12 May 2025 17:27:10 -0700 [thread overview]
Message-ID: <20250513002715.40126-2-sj@kernel.org> (raw)
In-Reply-To: <20250513002715.40126-1-sj@kernel.org>
For a bug such as double aggregation reset[1], ->nr_accesses and/or
->nr_accesses_bp of damon_region could be corrupted. Such corruption
can make monitoring results pretty inaccurate, so the root causing bug
should be investigated. Meanwhile, the corruption itself can easily be
fixed but silently fixing it will hide the bug.
Fix the corruption as soon as found, but WARN_ONCE() so that we can be
aware of the existence of the bug while keeping the system running in a
more sane way.
[1] https://lore.kernel.org/20250302214145.356806-1-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/core.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 587fb9a4fef8..0bb71e2ab713 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1391,6 +1391,19 @@ int damos_walk(struct damon_ctx *ctx, struct damos_walk_control *control)
return 0;
}
+/*
+ * Warn and fix corrupted ->nr_accesses[_bp] for investigations and preventing
+ * the problem being propagated.
+ */
+static void damon_warn_fix_nr_accesses_corruption(struct damon_region *r)
+{
+ if (r->nr_accesses_bp == r->nr_accesses * 10000)
+ return;
+ WARN_ONCE(true, "invalid nr_accesses_bp at reset: %u %u\n",
+ r->nr_accesses_bp, r->nr_accesses);
+ r->nr_accesses_bp = r->nr_accesses * 10000;
+}
+
/*
* Reset the aggregated monitoring results ('nr_accesses' of each region).
*/
@@ -1404,6 +1417,7 @@ static void kdamond_reset_aggregated(struct damon_ctx *c)
damon_for_each_region(r, t) {
trace_damon_aggregated(ti, r, damon_nr_regions(t));
+ damon_warn_fix_nr_accesses_corruption(r);
r->last_nr_accesses = r->nr_accesses;
r->nr_accesses = 0;
}
--
2.39.5
next prev parent reply other threads:[~2025-05-13 0:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-13 0:27 [PATCH 0/6] mm/damon: minor fixups and improvements for code, tests, and documents SeongJae Park
2025-05-13 0:27 ` SeongJae Park [this message]
2025-05-13 0:27 ` [PATCH 2/6] mm/damon/sysfs-schemes: fix wrong comment on damons_sysfs_quota_goal_metric_strs SeongJae Park
2025-05-13 0:27 ` [PATCH 3/6] mm/damon/paddr: remove unused variable, folio_list, in damon_pa_stat() SeongJae Park
2025-05-13 0:27 ` [PATCH 4/6] mm/damon/tests/core-kunit: add a test for damos_set_filters_default_reject() SeongJae Park
2025-05-13 0:27 ` [PATCH 5/6] selftests/damon/_damon_sysfs: read tried regions directories in order SeongJae Park
2025-05-13 0:27 ` [PATCH 6/6] Docs/damon: update titles and brief introductions to explain DAMOS 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=20250513002715.40126-2-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=kernel-team@meta.com \
--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