From: SeongJae Park <sj@kernel.org>
To: Liew Rui Yan <aethernet65535@gmail.com>
Cc: SeongJae Park <sj@kernel.org>, damon@lists.linux.dev, linux-mm@kvack.org
Subject: Re: [PATCH] mm/damon: validate addr_unit to be power of 2
Date: Mon, 30 Mar 2026 16:33:42 -0700 [thread overview]
Message-ID: <20260330233343.4083-1-sj@kernel.org> (raw)
In-Reply-To: <20260330060851.4659-1-aethernet65535@gmail.com>
On Mon, 30 Mar 2026 14:08:51 +0800 Liew Rui Yan <aethernet65535@gmail.com> wrote:
> Hi SeongJae,
>
> On Sun, 29 Mar 2026 08:15:07 -0700 SeongJae Park <sj@kernel.org> wrote:
>
> > On Sun, 29 Mar 2026 15:51:07 +0800 Liew Rui Yan <aethernet65535@gmail.com> wrote:
> > [...]
> > > To confirm, are you suggesting something like the first approach [1]?
> > >
> > > if (input_addr_unit < PAGE_SIZE && !is_power_of_2(input_addr_unit))
> > > return -EINVAL;
> >
> > Yes. But the real constraint is min_region_sz, so testing it would be more
> > simple and effective. E.g.,
> >
> > if (!is_power_of_2(param_ctx->min_region_sz))
> > return -EINVAL;
> > >
> > > [1] https://lore.kernel.org/20260325071709.9699-1-aethernet65535@gmail.com
>
> Thank you for the example.
>
> The 'param_ctx' you mentioned confused me for a moment, as it doesn't
> exist in the current addr_unit_store().
I'd suggest to do the validation in commit_inputs handling path
(damon_{lru_sort,reclaim}_apply_parameters()), rather than addr_unit_store().
And param_ctx is in the path.
> But I assume you are suggesting
> that we should validate the result of 'min_region_sz' rather than the
> 'addr_unit' itself, and this check should happen within the
> addr_unit_store() callback.
That's correct.
>
> So, would something like this in addr_uint_store() be what you expect?
>
> if (!input_addr_unit)
> return -EINVAL;
>
> min_region_sz = max(PAGE_SIZE / input_addr_unit, 1);
damon_{lru_sort,reclaim}_apply_parameters() does this already. And that's why
I suggest to put the validation there.
> if (!is_power_of_2(min_region_sz))
> return -EINVAL;
Yes, this kind of validation, but in
damon_{lru_sort,reclaim}_apply_parameters(), please.
Someone might argue it is better to return the error as early as possible (when
writing addr_unit). But in my humble opinion, the benefit from the user
experience is not that big, while it could make code unnecessarily complicated.
Then someone could ask if we should also move the zero addr_unit input check in
addr_unit_store() into apply_parameters(). Yes, I think we should have done
that in the way, and I made a wrong decision at the time. But, I think that's
not a big problem, so I would prefer keeping the code and behavior as is,
unless it turns out to be a real problem.
>
> This keeps the fix local to the modules, and directly enforces the
> power-of-2 constraint on the actual monitoring granularity.
Yes. But again, I'd prefer doing that in apply_parameters().
Thanks,
SJ
[...]
prev parent reply other threads:[~2026-03-30 23:33 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-27 6:26 [PATCH] mm/damon: validate addr_unit to be power of 2 Liew Rui Yan
2026-03-27 6:45 ` Liew Rui Yan
2026-03-27 12:10 ` Liew Rui Yan
2026-03-27 8:11 ` (sashiko review) " Liew Rui Yan
2026-03-27 8:27 ` Liew Rui Yan
2026-03-27 14:14 ` SeongJae Park
2026-03-27 14:56 ` Liew Rui Yan
2026-03-28 0:14 ` SeongJae Park
2026-03-28 2:26 ` Liew Rui Yan
2026-03-28 13:29 ` SeongJae Park
2026-03-28 14:13 ` SeongJae Park
2026-03-28 17:44 ` Liew Rui Yan
2026-03-28 18:06 ` SeongJae Park
2026-03-28 18:43 ` Liew Rui Yan
2026-03-29 3:20 ` SeongJae Park
2026-03-29 7:51 ` Liew Rui Yan
2026-03-29 15:15 ` SeongJae Park
2026-03-30 6:08 ` Liew Rui Yan
2026-03-30 7:17 ` Liew Rui Yan
2026-03-30 23:34 ` SeongJae Park
2026-03-30 23:33 ` SeongJae Park [this message]
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=20260330233343.4083-1-sj@kernel.org \
--to=sj@kernel.org \
--cc=aethernet65535@gmail.com \
--cc=damon@lists.linux.dev \
--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