DAMON development mailing list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "SeongJae Park" <sj@kernel.org>
Cc: damon@lists.linux.dev
Subject: Re: [PATCH 1/7] mm/damon: introduce damon_set_region_system_rams_default()
Date: Wed, 29 Apr 2026 04:39:02 +0000	[thread overview]
Message-ID: <20260429043902.E8FFDC19425@smtp.kernel.org> (raw)
In-Reply-To: <20260429041232.90257-2-sj@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The default region setup creates a single contiguous bounding box encompassing all System RAM resources, incorrectly including unpopulated memory holes.
- [High] Integer overflow during physical address boundary calculation (`arg.res.end + 1`) can cause DAMON initialization to fail.
--

commit cd855b0d7d334ccf9a13e1331105a3281e5b0aeb
Author: SeongJae Park <sj@kernel.org>

mm/damon: introduce damon_set_region_system_rams_default()

Introduces a default target setup for DAMON that sets a physical address
range covering all System RAM resources when the caller doesn't specify
a region.

> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index 05e4bef367db..980a31cd3498 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
[ ... ]
> +static bool damon_find_system_rams_range(unsigned long *start,
> +		unsigned long *end, unsigned long addr_unit)
> +{
> +	struct damon_system_ram_range_walk_arg arg = {};
> +
> +	walk_system_ram_res(0, -1, &arg, damon_system_ram_walk_fn);
> +	if (!arg.walked)
> +		return false;
> +	*start = damon_res_to_core_addr(arg.res.start, addr_unit);
> +	*end = damon_res_to_core_addr(arg.res.end + 1, addr_unit);

Can arg.res.end + 1 overflow here?

If a 32-bit system has physical memory extending to the end of the address
space, arg.res.end will be the maximum representable value. Adding 1 would
overflow to 0, making *end 0. The subsequent check if (*end <= *start)
would then evaluate to true, causing the function to silently return false
and abort initialization with -EINVAL.

> +	if (*end <= *start)
> +		return false;
> +	return true;
> +}
[ ... ]
> +int damon_set_region_system_rams_default(struct damon_target *t,
> +			unsigned long *start, unsigned long *end,
> +			unsigned long addr_unit, unsigned long min_region_sz)
> +{
> +	struct damon_addr_range addr_range;
> +
> +	if (*start > *end)
> +		return -EINVAL;
> +
> +	if (!*start && !*end &&
> +		!damon_find_system_rams_range(start, end, addr_unit))
> +		return -EINVAL;
> +
> +	addr_range.start = *start;
> +	addr_range.end = *end;
> +	return damon_set_regions(t, &addr_range, 1, min_region_sz);

Does this create a single bounding box encompassing all System RAM resources,
including unpopulated memory holes?

On systems with sparse physical memory layouts, this combined range will
encompass massive memory holes. Because DAMON uses uniform random sampling
within a region to estimate access frequencies, samples landing in the gaps
will inherently register as unaccessed, diluting the perceived access rates
and preventing effective adaptive region splitting and merging.

Could the implementation instead construct an array of multiple ranges,
one for each distinct System RAM resource, and pass them to
damon_set_regions()?

> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260429041232.90257-1-sj@kernel.org?part=1

  reply	other threads:[~2026-04-29  4:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-29  4:12 [PATCH 0/7] mm/damon/reclaim,lru_sort: monitor all system rams by default SeongJae Park
2026-04-29  4:12 ` [PATCH 1/7] mm/damon: introduce damon_set_region_system_rams_default() SeongJae Park
2026-04-29  4:39   ` sashiko-bot [this message]
2026-04-29  5:22     ` SeongJae Park
2026-04-29  4:12 ` [PATCH 2/7] mm/damon/reclaim: cover all system rams SeongJae Park
2026-04-29  5:23   ` sashiko-bot
2026-04-29  5:41     ` SeongJae Park
2026-04-29  4:12 ` [PATCH 3/7] mm/damon/lru_sort: " SeongJae Park
2026-04-29  6:03   ` sashiko-bot
2026-04-29  6:06     ` SeongJae Park
2026-04-29  4:12 ` [PATCH 4/7] mm/damon/core: remove damon_set_region_biggest_system_ram_default() SeongJae Park
2026-04-29  4:12 ` [PATCH 5/7] mm/damon/stat: use damon_set_region_system_rams_default() SeongJae Park
2026-04-29  4:12 ` [PATCH 6/7] Docs/admin-guide/mm/damon/reclaim: update for entire memory monitoring SeongJae Park
2026-04-29  7:02   ` sashiko-bot
2026-04-29 14:27     ` SeongJae Park
2026-04-29  4:12 ` [PATCH 7/7] Docs/admin-guide/mm/damon/lru_sort: " SeongJae Park
2026-04-29 14:30 ` [PATCH 0/7] mm/damon/reclaim,lru_sort: monitor all system rams by default 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=20260429043902.E8FFDC19425@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=damon@lists.linux.dev \
    --cc=sashiko@lists.linux.dev \
    --cc=sj@kernel.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