From: SeongJae Park <sj@kernel.org>
Cc: SeongJae Park <sj@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Brendan Higgins <brendan.higgins@linux.dev>,
David Gow <davidgow@davidgow.net>,
damon@lists.linux.dev, kunit-dev@googlegroups.com,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-mm@kvack.org
Subject: [RFC PATCH 03/11] mm/damon/tests/core-kunit: test damon_rand()
Date: Wed, 24 Jun 2026 07:19:59 -0700 [thread overview]
Message-ID: <20260624142008.87180-4-sj@kernel.org> (raw)
In-Reply-To: <20260624142008.87180-1-sj@kernel.org>
Commit 9012c4e647df ("mm/damon: replace damon_rand() with a per-ctx
lockless PRNG") optimized DAMON for better performance. Add a kunit
test for ensuring the pseudo randomness quality.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/tests/core-kunit.h | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index df16cc070eeb0..a1ba807d59a13 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -1488,6 +1488,26 @@ static void damon_test_walk_control_obsolete(struct kunit *test)
damon_destroy_ctx(ctx);
}
+static void damon_test_rand(struct kunit *test)
+{
+ struct damon_ctx ctx;
+ int counts[10] = {};
+ int i;
+
+ prandom_seed_state(&ctx.rnd_state, get_random_u64());
+ for (i = 0; i < 10000; i++) {
+ unsigned long rnd = damon_rand(&ctx, 0, 10);
+
+ KUNIT_EXPECT_GE(test, rnd, 0);
+ KUNIT_EXPECT_LE(test, rnd, 9);
+ counts[rnd]++;
+ }
+ for (i = 0; i < 10; i++) {
+ KUNIT_EXPECT_GE(test, counts[i], 900);
+ KUNIT_EXPECT_LE(test, counts[i], 1100);
+ }
+}
+
static struct kunit_case damon_test_cases[] = {
KUNIT_CASE(damon_test_target),
KUNIT_CASE(damon_test_regions),
@@ -1518,6 +1538,7 @@ static struct kunit_case damon_test_cases[] = {
KUNIT_CASE(damon_test_apply_min_nr_regions),
KUNIT_CASE(damon_test_is_last_region),
KUNIT_CASE(damon_test_walk_control_obsolete),
+ KUNIT_CASE(damon_test_rand),
{},
};
--
2.47.3
next prev parent reply other threads:[~2026-06-24 14:20 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-24 14:19 [RFC PATCH 00/11] mm/damon: update, optimize, and clean up doc, tests, and code SeongJae Park
2026-06-24 14:19 ` [RFC PATCH 01/11] Docs/mm/damon/design: update for DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP SeongJae Park
2026-06-24 14:19 ` [RFC PATCH 02/11] Docs/ABI/damon: document probe files SeongJae Park
2026-06-24 14:19 ` SeongJae Park [this message]
2026-06-24 14:20 ` [RFC PATCH 04/11] selftests/damon/sysfs.sh: test multiple probe dirs creation SeongJae Park
2026-06-24 14:20 ` [RFC PATCH 05/11] selftests/damon/sysfs.sh: test {core,ops}_filters/ directories SeongJae Park
2026-06-24 14:20 ` [RFC PATCH 06/11] selftests/damon/sysfs.sh: test dests dir SeongJae Park
2026-06-24 14:20 ` [RFC PATCH 07/11] selftests/damon/sysfs.sh: test all files in quota goal dir SeongJae Park
2026-06-24 14:20 ` [RFC PATCH 08/11] mm/damon/core: reduce range setup in damon_commit_target_regions() SeongJae Park
2026-06-24 14:20 ` [RFC PATCH 09/11] mm/damon/sysfs: split probe setup function out SeongJae Park
2026-06-24 14:20 ` [RFC PATCH 10/11] mm/damon/sysfs: split out filters setup function SeongJae Park
2026-06-24 14:20 ` [RFC PATCH 11/11] mm/damon/sysfs: fix typos in probe_{add,rm}_dirs: s/attr/probe/ 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=20260624142008.87180-4-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=brendan.higgins@linux.dev \
--cc=damon@lists.linux.dev \
--cc=davidgow@davidgow.net \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.