From: sashiko-bot@kernel.org
To: "Jiayuan Chen" <jiayuan.chen@linux.dev>
Cc: damon@lists.linux.dev
Subject: Re: [PATCH 1/2] mm/damon: introduce damon_rand_fast() for per-ctx PRNG
Date: Thu, 23 Apr 2026 19:08:40 +0000 [thread overview]
Message-ID: <20260423190841.821E4C2BCAF@smtp.kernel.org> (raw)
In-Reply-To: <20260423122340.138880-1-jiayuan.chen@linux.dev>
Sashiko AI review found 1 potential issue(s):
- [High] damon_rand_fast() truncates the sampling range to 32 bits, preventing DAMON from monitoring the upper parts of memory regions larger than 4GB.
--
commit 094f8506b34920335d2088d576411d78378a8a58
Author: Jiayuan Chen <jiayuan.chen@shopee.com>
mm/damon: introduce damon_rand_fast() for per-ctx PRNG
This commit introduces a lockless, per-ctx PRNG function for the DAMON
sampling address hot path. It replaces the heavier get_random_u32_below()
call to reduce kdamond CPU usage on workloads with many regions.
> diff --git a/include/linux/damon.h b/include/linux/damon.h
> index f2cdb7c3f5e6c..0afdc08119c8c 100644
> --- a/include/linux/damon.h
> +++ b/include/linux/damon.h
[ ... ]
> @@ -843,8 +844,35 @@ struct damon_ctx {
[ ... ]
> +static inline unsigned long damon_rand_fast(struct damon_ctx *ctx,
> + unsigned long l, unsigned long r)
> +{
> + u32 rnd = prandom_u32_state(&ctx->rnd_state);
> + u32 span = (u32)(r - l);
Does this cast truncate the memory region span to 32 bits, preventing the
sampling of addresses beyond the first 4GB of a region?
If a region is larger than 4GB (which can occur with large anonymous
mappings or physical memory ranges), the explicit cast to u32 will wrap
around. For example, a 5GB region would result in a span of 1GB, and an
exactly 4GB region would result in a span of 0.
This would cause the PRNG to only sample addresses within that truncated
span, leaving the rest of the memory region unmonitored. While the previous
damon_rand() implementation had a similar limitation by passing an unsigned
long to get_random_u32_below(), could this be updated to correctly handle
64-bit region spans?
> +
> + return l + (unsigned long)(((u64)rnd * span) >> 32);
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260423122340.138880-1-jiayuan.chen@linux.dev?part=1
next prev parent reply other threads:[~2026-04-23 19:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-23 12:23 [PATCH 1/2] mm/damon: introduce damon_rand_fast() for per-ctx PRNG Jiayuan Chen
2026-04-23 12:23 ` [PATCH 2/2] mm/damon/paddr: prefetch struct page of the next region Jiayuan Chen
2026-04-23 19:25 ` sashiko-bot
2026-04-24 1:42 ` SeongJae Park
2026-04-23 19:08 ` sashiko-bot [this message]
2026-04-24 1:36 ` [PATCH 1/2] mm/damon: introduce damon_rand_fast() for per-ctx PRNG SeongJae Park
2026-04-24 2:29 ` Jiayuan Chen
2026-04-24 15:11 ` SeongJae Park
2026-04-25 3:36 ` Jiayuan Chen
2026-04-25 15:59 ` SeongJae Park
2026-04-26 5:50 ` Jiayuan Chen
2026-04-26 17:33 ` 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=20260423190841.821E4C2BCAF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=damon@lists.linux.dev \
--cc=jiayuan.chen@linux.dev \
--cc=sashiko@lists.linux.dev \
/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