From: SJ Park <sj@kernel.org>
Cc: SJ 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 v1.3 1/7] mm/damon/core: remove comment and test for nr_to_bp() divide-by-zero
Date: Tue, 7 Jul 2026 19:48:47 -0700 [thread overview]
Message-ID: <20260708024855.116614-2-sj@kernel.org> (raw)
In-Reply-To: <20260708024855.116614-1-sj@kernel.org>
The comments on damon_nr_accesses_to_accesses_bp() and its unit test
warn it can trigger division-by-zero when the aggregation interval is
zero. Commit 35d4a3cf70a8 ("mm/damon/ops-common: handle extreme
intervals in damon_hot_score()") modified damon_nr_samples_per_aggr() to
always return non-zero. Hence no division-by-zero of the note can
happen. Remove the obsolete comment on the function. The test code was
written to test the division-by-zero case, which cannot happen anymore.
Having it makes no sense. Entirely remove the test code and its
comment.
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/core.c | 8 +-------
mm/damon/tests/core-kunit.h | 23 -----------------------
2 files changed, 1 insertion(+), 30 deletions(-)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 390e00b3685ef..a15005db82899 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -883,13 +883,7 @@ static unsigned int damon_accesses_bp_to_nr_accesses(
return accesses_bp * damon_max_nr_accesses(attrs) / 10000;
}
-/*
- * Convert nr_accesses to access ratio in bp (per 10,000).
- *
- * Callers should ensure attrs.aggr_interval is not zero, like
- * damon_update_monitoring_results() does . Otherwise, divide-by-zero would
- * happen.
- */
+/* Convert nr_accesses to access ratio in bp (per 10,000) */
static unsigned int damon_nr_accesses_to_accesses_bp(
unsigned int nr_accesses, struct damon_attrs *attrs)
{
diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index 0124f83b39b83..278d46632eff4 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -575,28 +575,6 @@ static void damon_test_set_regions(struct kunit *test)
}, 3);
}
-static void damon_test_nr_accesses_to_accesses_bp(struct kunit *test)
-{
- struct damon_attrs attrs = {
- .sample_interval = 10,
- .aggr_interval = ((unsigned long)UINT_MAX + 1) * 10
- };
-
- /*
- * In some cases such as 32bit architectures where UINT_MAX is
- * ULONG_MAX, attrs.aggr_interval becomes zero. Calling
- * damon_nr_accesses_to_accesses_bp() in the case will cause
- * divide-by-zero. Such case is prohibited in normal execution since
- * the caution is documented on the comment for the function, and
- * damon_update_monitoring_results() does the check. Skip the test in
- * the case.
- */
- if (!attrs.aggr_interval)
- kunit_skip(test, "aggr_interval is zero.");
-
- KUNIT_EXPECT_EQ(test, damon_nr_accesses_to_accesses_bp(123, &attrs), 0);
-}
-
static void damon_test_update_monitoring_result(struct kunit *test)
{
struct damon_attrs old_attrs = {
@@ -1572,7 +1550,6 @@ static struct kunit_case damon_test_cases[] = {
KUNIT_CASE(damon_test_split_above_half_progresses),
KUNIT_CASE(damon_test_ops_registration),
KUNIT_CASE(damon_test_set_regions),
- KUNIT_CASE(damon_test_nr_accesses_to_accesses_bp),
KUNIT_CASE(damon_test_update_monitoring_result),
KUNIT_CASE(damon_test_set_attrs),
KUNIT_CASE(damon_test_mvsum),
--
2.47.3
next prev parent reply other threads:[~2026-07-08 2:49 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 2:48 [RFC PATCH v1.3 0/7] mm/damon: update probe hits for runtime parameter commits SJ Park
2026-07-08 2:48 ` SJ Park [this message]
2026-07-08 2:48 ` [RFC PATCH v1.3 2/7] mm/damon/core: s/damon_max_nr_accesses()/damon_nr_samples_per_aggr()/ SJ Park
2026-07-08 2:58 ` sashiko-bot
2026-07-08 3:52 ` SJ Park
2026-07-08 2:48 ` [RFC PATCH v1.3 3/7] mm/damon/core: s/accesses_bp_to_nr_accesses/sample_bp_to_count/ SJ Park
2026-07-08 2:48 ` [RFC PATCH v1.3 4/7] mm/damon/core: s/nr_accesses_to_accesses_bp/sample_count_to_bp/ SJ Park
2026-07-08 2:48 ` [RFC PATCH v1.3 5/7] mm/damon/core: s/nr_accesses_for_new_attrs/nr_samples_for_new_attrs/ SJ Park
2026-07-08 3:01 ` sashiko-bot
2026-07-08 3:53 ` SJ Park
2026-07-08 2:48 ` [RFC PATCH v1.3 6/7] mm/damon/core: update probe hits for new parameter commit SJ Park
2026-07-08 3:05 ` sashiko-bot
2026-07-08 3:56 ` SJ Park
2026-07-08 2:48 ` [RFC PATCH v1.3 7/7] mm/damon/core: handle unreset probe_hits in probe_hits_mvsum() SJ 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=20260708024855.116614-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