Re: [PATCH v2 1/2] mm/damon/core: preserve the quota passed to damon_new_scheme()

From: SJ Park

Date: Fri Sep 25 2026 - 04:50:23 EST


On Thu, 24 Sep 2026 22:16:13 +0200 Karl Mehltretter <kmehltretter@xxxxxxxxx> wrote:

> damon_commit_ctx() first commits the running context's parameters to a
> temporary context for validating proposed updates. When
> damon_commit_schemes() creates the temporary schemes, it passes the
> running scheme's quota as the quota parameter of damon_new_scheme().
>
> damon_new_scheme() calls damos_quota_init() on that quota before copying
> it to the new scheme. This clears the running scheme's effective quota,
> feedback input and charging state. Even an update rejected with -EINVAL
> loses the running quota state.
>
> For a size quota, this discards the bytes already charged and allows the
> scheme to use a fresh quota before the reset interval has elapsed. For a
> goal-driven quota, the consist tuner loses its accumulated input and
> restarts from its minimum input. A time quota loses its throughput
> estimate and falls back to the initial estimate.

The end users will show DAMOS works more or less aggressively than expected for
online-commit updates of quotas. DAMON provides best efforts by detault.
DAMON parameters online commit is supposed to be executed only occationally.
Hence, the issue wouldn't be critical on sane setups. For user_input type
quota goals, online commit of the user input score is expected to be frequent.
But, for the case commit_schemes_quota_goals command is recommended for optimal
execution, and it doesn't have this bug.

Karl, if you don't mind, I will add the above user impact detail to the commit
message when I apply this to damon/next.

>
> Commit 60bd24f272d0 ("mm/damon/sysfs: test commit input against realistic
> destination") introduced this problem in v6.19 when sysfs validation
> began committing the running context's parameters to a temporary context.
> Commit b90408ef1163 ("mm/damon/core: safely validate src on
> damon_commit_ctx()") later moved that validation into the core API,
> exposing other callers including DAMON_RECLAIM and DAMON_LRU_SORT.
>
> Sashiko reported the same side effect [1] on the RFC of the core API
> change.
>
> Copy the quota to the new scheme first, then initialize that copy. Make
> damos_quota_init() return void, since its return value is no longer needed.

Looks good to me. Thank you for finding and fixing this, Karl.

>
> Fixes: 60bd24f272d0 ("mm/damon/sysfs: test commit input against realistic destination")
> Cc: <stable@xxxxxxxxxxxxxxx>
> Link: https://lore.kernel.org/r/20260702212143.0CB6D1F00A3D@xxxxxxxxxxxxxxx/ [1]
> Assisted-by: LLM
> Signed-off-by: Karl Mehltretter <kmehltretter@xxxxxxxxx>

Reviewed-by: SJ Park <sj@xxxxxxxxxx>


Thanks,
SJ

[...]