All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "SJ Park" <sj@kernel.org>
Cc: damon@lists.linux.dev
Subject: Re: [RFC PATCH 7/7] Docs/ABI/damon: update for quota goal metric complement sysfs file
Date: Fri, 18 Sep 2026 15:21:54 +0000	[thread overview]
Message-ID: <20260918152154.7CB701F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260918142827.85303-8-sj@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mm: damon: unsigned integer underflow in damos_set_quota_goal_current_value()
--

commit 94b0fa41235165f1d082ca5735dcefbf9f65199b
Author: SJ Park <sj@kernel.org>

mm/damon/core: introduce damos_quota_goal->complement

This commit introduces a complement flag for DAMOS quota auto-tuning goals.
It allows the system to target the complement value of a given metric by
updating the current metric value during retrieval.

> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index 2258b72da7a78..25a8221dd2a40 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c

[ ... ]

> @@ -3238,6 +3239,19 @@ static void damos_set_quota_goal_current_value(struct damon_ctx *c,
>  	default:
>  		break;
>  	}
> +	if (!goal->complement)
> +		return;
> +
> +	/* updte current_value to complemented value */
> +
> +	/* for user_input, users set complemented value on their own */
> +	if (goal->metric == DAMOS_QUOTA_USER_INPUT)
> +		return;
> +	if (goal->metric == DAMOS_QUOTA_SOME_MEM_PSI_US)
> +		goal->current_value = s->quota.reset_interval * 1000 -
> +			goal->current_value;

[Severity: High]
Can this underflow in damos_set_quota_goal_current_value() if
goal->current_value exceeds s->quota.reset_interval * 1000?

For DAMOS_QUOTA_SOME_MEM_PSI_US, the background kdamond thread calculates the
elapsed PSI time in microseconds. Due to scheduler delays or heavy system
load, the actual elapsed time between evaluations can slightly exceed
reset_interval milliseconds, meaning goal->current_value can legitimately
exceed s->quota.reset_interval * 1000.

An underflow would wrap goal->current_value to a massive positive number near
ULONG_MAX. The DAMON auto-tuning loop would interpret this as the goal being
severely over-achieved, causing it to erroneously throttle its aggressiveness
to the minimum precisely when memory pressure is highly severe.

> +	else
> +		goal->current_value = 10000 - goal->current_value;

[Severity: High]
Similarly, can this also underflow for BP metrics like
DAMOS_QUOTA_HUGEPAGE_MEM_BP?

Per-CPU counter drift can cause the calculated ratio to exceed 10000,
triggering an underflow here that similarly inverts the DAMON logic.

>  }
>  
>  /* Return the highest score since it makes schemes least aggressive */

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

      reply	other threads:[~2026-09-18 15:21 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 14:28 [RFC PATCH 0/7] mm/damon: introduce damos quota goal target metric complement flag SJ Park
2026-09-18 14:28 ` [RFC PATCH 1/7] mm/damon/core: introduce damos_quota_goal->complement SJ Park
2026-09-18 14:48   ` sashiko-bot
2026-09-18 15:08     ` SJ Park
2026-09-18 14:28 ` [RFC PATCH 2/7] mm/damon: add complement argument to damos_new_quota_goal() SJ Park
2026-09-18 14:56   ` sashiko-bot
2026-09-18 14:28 ` [RFC PATCH 3/7] mm/damon/sysfs-schemes: support quota goal complement flag SJ Park
2026-09-18 15:05   ` sashiko-bot
2026-09-18 15:09     ` SJ Park
2026-09-18 14:28 ` [RFC PATCH 4/7] mm/damon/tests/core-kunit: test quota_goal->complement commit SJ Park
2026-09-18 15:07   ` sashiko-bot
2026-09-18 14:28 ` [RFC PATCH 5/7] Docs/mm/damon/design: document damos quota goal complement flag SJ Park
2026-09-18 15:07   ` sashiko-bot
2026-09-18 14:28 ` [RFC PATCH 6/7] Docs/admin-guide/mm/damon/usage: update for quota goal complement file SJ Park
2026-09-18 15:09   ` sashiko-bot
2026-09-18 15:11     ` SJ Park
2026-09-18 14:28 ` [RFC PATCH 7/7] Docs/ABI/damon: update for quota goal metric complement sysfs file SJ Park
2026-09-18 15:21   ` sashiko-bot [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=20260918152154.7CB701F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=damon@lists.linux.dev \
    --cc=sashiko-reviews@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 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.