* [RFC PATCH v2 1/7] mm/damon/core: introduce damos_quota_goal->complement
2026-09-19 1:13 [RFC PATCH v2 0/7] mm/damon: introduce damos quota goal target metric complement flag SJ Park
@ 2026-09-19 1:13 ` SJ Park
2026-09-19 1:25 ` sashiko-bot
2026-09-19 1:13 ` [RFC PATCH v2 2/7] mm/damon: add complement argument to damos_new_quota_goal() SJ Park
` (5 subsequent siblings)
6 siblings, 1 reply; 19+ messages in thread
From: SJ Park @ 2026-09-19 1:13 UTC (permalink / raw)
Cc: SJ Park, Andrew Morton, damon, linux-kernel, linux-mm
Introduce damos_quota_goal->complement for specifying whether to use a
complemented value of the given goal target metric. Add the field to
the data structure and implement essential core support. Handle the
flag in the quota goal commit and current quota goal metric value
retrieval.
Signed-off-by: SJ Park <sj@kernel.org>
---
include/linux/damon.h | 2 ++
mm/damon/core.c | 18 ++++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/include/linux/damon.h b/include/linux/damon.h
index 844b175120f09..78b227875287d 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -175,6 +175,7 @@ enum damos_quota_goal_metric {
/**
* struct damos_quota_goal - DAMOS scheme quota auto-tuning goal.
* @metric: Metric to be used for representing the goal.
+ * @complement: Use the complement of the metric.
* @target_value: Target value of @metric to achieve with the tuning.
* @current_value: Current value of @metric.
* @nid: Node id.
@@ -197,6 +198,7 @@ enum damos_quota_goal_metric {
*/
struct damos_quota_goal {
enum damos_quota_goal_metric metric;
+ bool complement;
unsigned long target_value;
unsigned long current_value;
/* metric-dependent fields */
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 4687b909d42c9..05d1df3746e83 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1224,6 +1224,7 @@ static int damos_commit_quota_goal(
if (!src->target_value)
return -EINVAL;
dst->metric = src->metric;
+ dst->complement = src->complement;
dst->target_value = src->target_value;
if (dst->metric == DAMOS_QUOTA_USER_INPUT)
dst->current_value = src->current_value;
@@ -3239,6 +3240,23 @@ 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;
+ return;
+ }
+ if (goal->current_value < 10000)
+ goal->current_value = 10000 - goal->current_value;
+ else
+ goal->current_value = 0;
}
/* Return the highest score since it makes schemes least aggressive */
--
2.47.3
^ permalink raw reply related [flat|nested] 19+ messages in thread* Re: [RFC PATCH v2 1/7] mm/damon/core: introduce damos_quota_goal->complement
2026-09-19 1:13 ` [RFC PATCH v2 1/7] mm/damon/core: introduce damos_quota_goal->complement SJ Park
@ 2026-09-19 1:25 ` sashiko-bot
2026-09-19 1:27 ` SJ Park
0 siblings, 1 reply; 19+ messages in thread
From: sashiko-bot @ 2026-09-19 1:25 UTC (permalink / raw)
To: SJ Park; +Cc: damon
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mm: Integer underflow in DAMOS_QUOTA_SOME_MEM_PSI_US complement calculation
--
commit f2de2d4493473c2c847f3ad213eaef640f0e1600
Author: SJ Park <sj@kernel.org>
mm/damon/core: introduce damos_quota_goal->complement
Introduce damos_quota_goal->complement for specifying whether to use a
complemented value of the given goal target metric. Add the field to
the data structure and implement essential core support. Handle the
flag in the quota goal commit and current quota goal metric value
retrieval.
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index 2258b72da7a78..9fd08cbfacd8c 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
[ ... ]
> @@ -3238,6 +3239,23 @@ 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]
Does this unsigned subtraction underflow if goal->current_value exceeds
s->quota.reset_interval * 1000?
If goal->current_value exceeds the nominal reset interval, which can happen on
the first iteration when initialized to an arbitrarily large user-provided
target_value, or on subsequent iterations if kernel scheduling delays cause the
actual elapsed time between callbacks to exceed the nominal reset_interval,
this subtraction will underflow and produce a massive current_value near
ULONG_MAX.
This large value is then passed to damos_quota_score(), which computes a
normalized score that maxes out the feedback loop, forcing the tuned quota
limit to drop aggressively.
> + return;
> + }
> + if (goal->current_value < 10000)
> + goal->current_value = 10000 - goal->current_value;
> + else
> + goal->current_value = 0;
> }
>
> /* Return the highest score since it makes schemes least aggressive */
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260919011359.88921-1-sj@kernel.org?part=1
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [RFC PATCH v2 1/7] mm/damon/core: introduce damos_quota_goal->complement
2026-09-19 1:25 ` sashiko-bot
@ 2026-09-19 1:27 ` SJ Park
0 siblings, 0 replies; 19+ messages in thread
From: SJ Park @ 2026-09-19 1:27 UTC (permalink / raw)
To: sashiko-bot; +Cc: SJ Park, damon
On Sat, 19 Sep 2026 01:25:09 +0000 sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] mm: Integer underflow in DAMOS_QUOTA_SOME_MEM_PSI_US complement calculation
> --
>
> commit f2de2d4493473c2c847f3ad213eaef640f0e1600
> Author: SJ Park <sj@kernel.org>
>
> mm/damon/core: introduce damos_quota_goal->complement
>
> Introduce damos_quota_goal->complement for specifying whether to use a
> complemented value of the given goal target metric. Add the field to
> the data structure and implement essential core support. Handle the
> flag in the quota goal commit and current quota goal metric value
> retrieval.
>
> > diff --git a/mm/damon/core.c b/mm/damon/core.c
> > index 2258b72da7a78..9fd08cbfacd8c 100644
> > --- a/mm/damon/core.c
> > +++ b/mm/damon/core.c
> [ ... ]
> > @@ -3238,6 +3239,23 @@ 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]
> Does this unsigned subtraction underflow if goal->current_value exceeds
> s->quota.reset_interval * 1000?
>
> If goal->current_value exceeds the nominal reset interval, which can happen on
> the first iteration when initialized to an arbitrarily large user-provided
> target_value, or on subsequent iterations if kernel scheduling delays cause the
> actual elapsed time between callbacks to exceed the nominal reset_interval,
> this subtraction will underflow and produce a massive current_value near
> ULONG_MAX.
>
> This large value is then passed to damos_quota_score(), which computes a
> normalized score that maxes out the feedback loop, forcing the tuned quota
> limit to drop aggressively.
It's an unlikely corner case. But I agree it would be nice to handle it. I
will do so in the next revision.
>
> > + return;
> > + }
> > + if (goal->current_value < 10000)
> > + goal->current_value = 10000 - goal->current_value;
> > + else
> > + goal->current_value = 0;
> > }
> >
> > /* Return the highest score since it makes schemes least aggressive */
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260919011359.88921-1-sj@kernel.org?part=1
Thanks,
SJ
^ permalink raw reply [flat|nested] 19+ messages in thread
* [RFC PATCH v2 2/7] mm/damon: add complement argument to damos_new_quota_goal()
2026-09-19 1:13 [RFC PATCH v2 0/7] mm/damon: introduce damos quota goal target metric complement flag SJ Park
2026-09-19 1:13 ` [RFC PATCH v2 1/7] mm/damon/core: introduce damos_quota_goal->complement SJ Park
@ 2026-09-19 1:13 ` SJ Park
2026-09-19 1:23 ` sashiko-bot
2026-09-19 1:13 ` [RFC PATCH v2 3/7] mm/damon/sysfs-schemes: support quota goal complement flag SJ Park
` (4 subsequent siblings)
6 siblings, 1 reply; 19+ messages in thread
From: SJ Park @ 2026-09-19 1:13 UTC (permalink / raw)
Cc: SJ Park, Andrew Morton, damon, linux-kernel, linux-mm
damos_quota_goal->complement needs to be manually set by each API
callers. It is easy to make mistakes. Extend the quota goal
constructor, damos_new_quota_goal() to receive and set the complement
flag value. Also update all callers to use the new signature.
Signed-off-by: SJ Park <sj@kernel.org>
---
include/linux/damon.h | 2 +-
mm/damon/core.c | 7 ++++---
mm/damon/lru_sort.c | 5 +++--
mm/damon/reclaim.c | 5 +++--
mm/damon/sysfs-schemes.c | 2 +-
mm/damon/tests/core-kunit.h | 2 +-
samples/damon/mtier.c | 2 +-
7 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/include/linux/damon.h b/include/linux/damon.h
index 78b227875287d..b310c40d6cebd 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -1098,7 +1098,7 @@ bool damos_filter_for_ops(enum damos_filter_type type);
void damos_destroy_filter(struct damos_filter *f);
struct damos_quota_goal *damos_new_quota_goal(
- enum damos_quota_goal_metric metric,
+ enum damos_quota_goal_metric metric, bool complement,
unsigned long target_value);
void damos_add_quota_goal(struct damos_quota *q, struct damos_quota_goal *g);
void damos_destroy_quota_goal(struct damos_quota_goal *goal);
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 05d1df3746e83..570891a15e2f8 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -691,7 +691,7 @@ void damos_destroy_filter(struct damos_filter *f)
}
struct damos_quota_goal *damos_new_quota_goal(
- enum damos_quota_goal_metric metric,
+ enum damos_quota_goal_metric metric, bool complement,
unsigned long target_value)
{
struct damos_quota_goal *goal;
@@ -700,6 +700,7 @@ struct damos_quota_goal *damos_new_quota_goal(
if (!goal)
return NULL;
goal->metric = metric;
+ goal->complement = complement;
goal->target_value = target_value;
if (metric == DAMOS_QUOTA_SOME_MEM_PSI_US)
goal->last_psi_total = U64_MAX;
@@ -1262,8 +1263,8 @@ int damos_commit_quota_goals(struct damos_quota *dst, struct damos_quota *src)
damos_for_each_quota_goal_safe(src_goal, next, src) {
if (j++ < i)
continue;
- new_goal = damos_new_quota_goal(
- src_goal->metric, src_goal->target_value);
+ new_goal = damos_new_quota_goal(src_goal->metric, false,
+ src_goal->target_value);
if (!new_goal)
return -ENOMEM;
err = damos_commit_quota_goal(new_goal, src_goal);
diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c
index 273efa3c913ed..64e086985eb55 100644
--- a/mm/damon/lru_sort.c
+++ b/mm/damon/lru_sort.c
@@ -233,12 +233,13 @@ static int damon_lru_sort_add_quota_goals(struct damos *hot_scheme,
if (!active_mem_bp)
return 0;
- goal = damos_new_quota_goal(DAMOS_QUOTA_ACTIVE_MEM_BP, active_mem_bp);
+ goal = damos_new_quota_goal(DAMOS_QUOTA_ACTIVE_MEM_BP, false,
+ active_mem_bp);
if (!goal)
return -ENOMEM;
damos_add_quota_goal(&hot_scheme->quota, goal);
/* aim 0.2 % goal conflict, to keep little ping pong */
- goal = damos_new_quota_goal(DAMOS_QUOTA_INACTIVE_MEM_BP,
+ goal = damos_new_quota_goal(DAMOS_QUOTA_INACTIVE_MEM_BP, false,
10000 - active_mem_bp + 2);
if (!goal)
return -ENOMEM;
diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c
index 42a2c9cb13431..014b0779ea6dd 100644
--- a/mm/damon/reclaim.c
+++ b/mm/damon/reclaim.c
@@ -233,7 +233,7 @@ static int damon_reclaim_apply_parameters(void)
damon_set_schemes(param_ctx, &scheme, 1);
if (quota_mem_pressure_us) {
- goal = damos_new_quota_goal(DAMOS_QUOTA_SOME_MEM_PSI_US,
+ goal = damos_new_quota_goal(DAMOS_QUOTA_SOME_MEM_PSI_US, false,
quota_mem_pressure_us);
if (!goal)
goto out;
@@ -241,7 +241,8 @@ static int damon_reclaim_apply_parameters(void)
}
if (quota_autotune_feedback) {
- goal = damos_new_quota_goal(DAMOS_QUOTA_USER_INPUT, 10000);
+ goal = damos_new_quota_goal(DAMOS_QUOTA_USER_INPUT, false,
+ 10000);
if (!goal)
goto out;
goal->current_value = quota_autotune_feedback;
diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index bfb6f0bc3f213..06af417bc9a2f 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -2869,7 +2869,7 @@ static int damos_sysfs_add_quota_score(
if (!sysfs_goal->target_value)
continue;
- goal = damos_new_quota_goal(sysfs_goal->metric,
+ goal = damos_new_quota_goal(sysfs_goal->metric, false,
sysfs_goal->target_value);
if (!goal)
return -ENOMEM;
diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index df84d9cc7d204..e8290a2c6f343 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -929,7 +929,7 @@ static void damos_test_commit_quota_goals_for(struct kunit *test,
* damos_commit_quota_goals() will kfree() the dst goals.
* Make it kfree()-able.
*/
- goal = damos_new_quota_goal(dst_goals[i].metric,
+ goal = damos_new_quota_goal(dst_goals[i].metric, false,
dst_goals[i].target_value);
if (!goal)
goto out;
diff --git a/samples/damon/mtier.c b/samples/damon/mtier.c
index 27dc88bdf7a0e..a2e311082cd4b 100644
--- a/samples/damon/mtier.c
+++ b/samples/damon/mtier.c
@@ -163,7 +163,7 @@ static struct damon_ctx *damon_sample_mtier_build_ctx(bool promote)
damon_set_schemes(ctx, &scheme, 1);
quota_goal = damos_new_quota_goal(
promote ? DAMOS_QUOTA_NODE_MEM_USED_BP :
- DAMOS_QUOTA_NODE_MEM_FREE_BP,
+ DAMOS_QUOTA_NODE_MEM_FREE_BP, false,
promote ? node0_mem_used_bp : node0_mem_free_bp);
if (!quota_goal)
goto free_out;
--
2.47.3
^ permalink raw reply related [flat|nested] 19+ messages in thread* Re: [RFC PATCH v2 2/7] mm/damon: add complement argument to damos_new_quota_goal()
2026-09-19 1:13 ` [RFC PATCH v2 2/7] mm/damon: add complement argument to damos_new_quota_goal() SJ Park
@ 2026-09-19 1:23 ` sashiko-bot
2026-09-19 1:36 ` SJ Park
0 siblings, 1 reply; 19+ messages in thread
From: sashiko-bot @ 2026-09-19 1:23 UTC (permalink / raw)
To: SJ Park; +Cc: damon
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] mm: damon: hardcoded false complement flag when cloning quota goals
--
commit 9116ea6f94ac9ade4ef359ba8351ef835957bf80
Author: SJ Park <sj@kernel.org>
mm/damon: add complement argument to damos_new_quota_goal()
This commit extends the damos_new_quota_goal() constructor to accept and
set the 'complement' flag value. It also updates all API callers to use
the new signature, which aims to prevent mistakes where the complement
flag was previously set manually.
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index 9fd08cbfacd8c..932ca3ad0e593 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -1262,8 +1263,8 @@ int damos_commit_quota_goals(struct damos_quota *dst, struct damos_quota *src)
> damos_for_each_quota_goal_safe(src_goal, next, src) {
> if (j++ < i)
> continue;
> - new_goal = damos_new_quota_goal(
> - src_goal->metric, src_goal->target_value);
> + new_goal = damos_new_quota_goal(src_goal->metric, false,
> + src_goal->target_value);
[Severity: Low]
Does this code discard the 'complement' flag from 'src_goal'?
By hardcoding 'false' here instead of passing 'src_goal->complement', the
copied goal initially loses its complement state. While it appears
damos_commit_quota_goal() immediately overwrites the flag with the correct
value, passing 'false' defeats the purpose of the explicit constructor
argument and could create a brittle pattern.
> if (!new_goal)
> return -ENOMEM;
> err = damos_commit_quota_goal(new_goal, src_goal);
[ ... ]
> diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
> index 5ff0436c58441..bba97ad449110 100644
> --- a/mm/damon/tests/core-kunit.h
> +++ b/mm/damon/tests/core-kunit.h
> @@ -929,7 +929,7 @@ static void damos_test_commit_quota_goals_for(struct kunit *test,
> * damos_commit_quota_goals() will kfree() the dst goals.
> * Make it kfree()-able.
> */
> - goal = damos_new_quota_goal(dst_goals[i].metric,
> + goal = damos_new_quota_goal(dst_goals[i].metric, false,
> dst_goals[i].target_value);
[Severity: Low]
Does this discard the 'complement' flag from 'dst_goals[i]'?
Hardcoding 'false' instead of passing 'dst_goals[i].complement' might
break future tests that attempt to verify complemented goals, as the
destination goals in the test framework will lose their intended complement
state.
> if (!goal)
> goto out;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260919011359.88921-1-sj@kernel.org?part=2
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [RFC PATCH v2 2/7] mm/damon: add complement argument to damos_new_quota_goal()
2026-09-19 1:23 ` sashiko-bot
@ 2026-09-19 1:36 ` SJ Park
0 siblings, 0 replies; 19+ messages in thread
From: SJ Park @ 2026-09-19 1:36 UTC (permalink / raw)
To: sashiko-bot; +Cc: SJ Park, damon
On Sat, 19 Sep 2026 01:23:27 +0000 sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Low] mm: damon: hardcoded false complement flag when cloning quota goals
> --
>
> commit 9116ea6f94ac9ade4ef359ba8351ef835957bf80
> Author: SJ Park <sj@kernel.org>
>
> mm/damon: add complement argument to damos_new_quota_goal()
>
> This commit extends the damos_new_quota_goal() constructor to accept and
> set the 'complement' flag value. It also updates all API callers to use
> the new signature, which aims to prevent mistakes where the complement
> flag was previously set manually.
>
> > diff --git a/mm/damon/core.c b/mm/damon/core.c
> > index 9fd08cbfacd8c..932ca3ad0e593 100644
> > --- a/mm/damon/core.c
> > +++ b/mm/damon/core.c
> > @@ -1262,8 +1263,8 @@ int damos_commit_quota_goals(struct damos_quota *dst, struct damos_quota *src)
> > damos_for_each_quota_goal_safe(src_goal, next, src) {
> > if (j++ < i)
> > continue;
> > - new_goal = damos_new_quota_goal(
> > - src_goal->metric, src_goal->target_value);
> > + new_goal = damos_new_quota_goal(src_goal->metric, false,
> > + src_goal->target_value);
>
> [Severity: Low]
> Does this code discard the 'complement' flag from 'src_goal'?
>
> By hardcoding 'false' here instead of passing 'src_goal->complement', the
> copied goal initially loses its complement state. While it appears
> damos_commit_quota_goal() immediately overwrites the flag with the correct
> value, passing 'false' defeats the purpose of the explicit constructor
> argument and could create a brittle pattern.
Makes sense, I will fix this.
>
> > if (!new_goal)
> > return -ENOMEM;
> > err = damos_commit_quota_goal(new_goal, src_goal);
>
> [ ... ]
>
> > diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
> > index 5ff0436c58441..bba97ad449110 100644
> > --- a/mm/damon/tests/core-kunit.h
> > +++ b/mm/damon/tests/core-kunit.h
> > @@ -929,7 +929,7 @@ static void damos_test_commit_quota_goals_for(struct kunit *test,
> > * damos_commit_quota_goals() will kfree() the dst goals.
> > * Make it kfree()-able.
> > */
> > - goal = damos_new_quota_goal(dst_goals[i].metric,
> > + goal = damos_new_quota_goal(dst_goals[i].metric, false,
> > dst_goals[i].target_value);
>
> [Severity: Low]
> Does this discard the 'complement' flag from 'dst_goals[i]'?
>
> Hardcoding 'false' instead of passing 'dst_goals[i].complement' might
> break future tests that attempt to verify complemented goals, as the
> destination goals in the test framework will lose their intended complement
> state.
Nice catch, I will fix this.
>
> > if (!goal)
> > goto out;
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260919011359.88921-1-sj@kernel.org?part=2
>
Thanks,
SJ
^ permalink raw reply [flat|nested] 19+ messages in thread
* [RFC PATCH v2 3/7] mm/damon/sysfs-schemes: support quota goal complement flag
2026-09-19 1:13 [RFC PATCH v2 0/7] mm/damon: introduce damos quota goal target metric complement flag SJ Park
2026-09-19 1:13 ` [RFC PATCH v2 1/7] mm/damon/core: introduce damos_quota_goal->complement SJ Park
2026-09-19 1:13 ` [RFC PATCH v2 2/7] mm/damon: add complement argument to damos_new_quota_goal() SJ Park
@ 2026-09-19 1:13 ` SJ Park
2026-09-19 1:26 ` sashiko-bot
2026-09-19 1:13 ` [RFC PATCH v2 4/7] mm/damon/tests/core-kunit: test quota_goal->complement commit SJ Park
` (3 subsequent siblings)
6 siblings, 1 reply; 19+ messages in thread
From: SJ Park @ 2026-09-19 1:13 UTC (permalink / raw)
Cc: SJ Park, Andrew Morton, damon, linux-kernel, linux-mm
Add a new sysfs file, complement, under the quota goal directory. It
works for setting and getting the quota goal metric complement flag
value.
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/sysfs-schemes.c | 32 +++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index 06af417bc9a2f..8f083611741fd 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -1220,6 +1220,7 @@ static const struct kobj_type damon_sysfs_watermarks_ktype = {
struct damos_sysfs_quota_goal {
struct kobject kobj;
enum damos_quota_goal_metric metric;
+ bool complement;
unsigned long target_value;
unsigned long current_value;
int nid;
@@ -1316,6 +1317,30 @@ static ssize_t target_metric_store(struct kobject *kobj,
return -EINVAL;
}
+static ssize_t complement_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ struct damos_sysfs_quota_goal *goal = container_of(kobj,
+ struct damos_sysfs_quota_goal, kobj);
+
+ return sysfs_emit(buf, "%c\n", goal->complement ? 'Y' : 'N');
+}
+
+static ssize_t complement_store(struct kobject *kobj,
+ struct kobj_attribute *attr, const char *buf, size_t count)
+{
+ struct damos_sysfs_quota_goal *goal = container_of(kobj,
+ struct damos_sysfs_quota_goal, kobj);
+ bool complement;
+ int err = kstrtobool(buf, &complement);
+
+ if (err)
+ return err;
+
+ goal->complement = complement;
+ return count;
+}
+
static ssize_t target_value_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
@@ -1424,6 +1449,9 @@ static void damos_sysfs_quota_goal_release(struct kobject *kobj)
static struct kobj_attribute damos_sysfs_quota_goal_target_metric_attr =
__ATTR_RW_MODE(target_metric, 0600);
+static struct kobj_attribute damos_sysfs_quota_goal_complement_attr =
+ __ATTR_RW_MODE(complement, 0600);
+
static struct kobj_attribute damos_sysfs_quota_goal_target_value_attr =
__ATTR_RW_MODE(target_value, 0600);
@@ -1438,6 +1466,7 @@ static struct kobj_attribute damos_sysfs_quota_goal_path_attr =
static struct attribute *damos_sysfs_quota_goal_attrs[] = {
&damos_sysfs_quota_goal_target_metric_attr.attr,
+ &damos_sysfs_quota_goal_complement_attr.attr,
&damos_sysfs_quota_goal_target_value_attr.attr,
&damos_sysfs_quota_goal_current_value_attr.attr,
&damos_sysfs_quota_goal_nid_attr.attr,
@@ -2869,7 +2898,8 @@ static int damos_sysfs_add_quota_score(
if (!sysfs_goal->target_value)
continue;
- goal = damos_new_quota_goal(sysfs_goal->metric, false,
+ goal = damos_new_quota_goal(sysfs_goal->metric,
+ sysfs_goal->complement,
sysfs_goal->target_value);
if (!goal)
return -ENOMEM;
--
2.47.3
^ permalink raw reply related [flat|nested] 19+ messages in thread* Re: [RFC PATCH v2 3/7] mm/damon/sysfs-schemes: support quota goal complement flag
2026-09-19 1:13 ` [RFC PATCH v2 3/7] mm/damon/sysfs-schemes: support quota goal complement flag SJ Park
@ 2026-09-19 1:26 ` sashiko-bot
2026-09-19 1:37 ` SJ Park
0 siblings, 1 reply; 19+ messages in thread
From: sashiko-bot @ 2026-09-19 1:26 UTC (permalink / raw)
To: SJ Park; +Cc: damon
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mm/damon: integer underflow in DAMOS_QUOTA_SOME_MEM_PSI_US complement calculation
--
commit cd02e1bd14a7884bf9a21f0cab584b1a0f9992ce
Author: SJ Park <sj@kernel.org>
mm/damon/sysfs-schemes: support quota goal complement flag
This patch adds a new sysfs file for the quota goal directory to allow
setting and getting the quota goal metric complement flag value.
> diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
> index 06af417bc9a2f..8f083611741fd 100644
> --- a/mm/damon/sysfs-schemes.c
> +++ b/mm/damon/sysfs-schemes.c
[ ... ]
> @@ -2869,7 +2898,8 @@ static int damos_sysfs_add_quota_score(
> if (!sysfs_goal->target_value)
> continue;
>
> - goal = damos_new_quota_goal(sysfs_goal->metric, false,
> + goal = damos_new_quota_goal(sysfs_goal->metric,
> + sysfs_goal->complement,
> sysfs_goal->target_value);
> if (!goal)
> return -ENOMEM;
[Severity: High]
Now that complement = true can be configured via sysfs, does this expose
an integer underflow in damos_set_quota_goal_current_value()?
If a user configures a DAMOS quota goal using DAMOS_QUOTA_SOME_MEM_PSI_US
with complement = true, the actual elapsed wall-clock time between
evaluations can exceed the configured s->quota.reset_interval due to
routine thread scheduling delays or high system load.
In mm/damon/core.c:damos_set_quota_goal_current_value(), the accumulated
PSI time (goal->current_value) could then exceed reset_interval * 1000,
underflowing the unsigned subtraction:
if (goal->metric == DAMOS_QUOTA_SOME_MEM_PSI_US) {
goal->current_value = s->quota.reset_interval * 1000 -
goal->current_value;
return;
}
Unlike the basis-point metrics below it, this lacks a safety bounds check.
The unsigned integer underflow results in an erroneously massive quota score.
This causes damon_feed_loop_next_input() to evaluate score >= goal * 2 and
return the minimum possible input (min_input), severely throttling the quota
size (esz) to a minimal value.
This effectively disables DAMOS scheme actions for that window, despite the
system being under severe memory pressure, which is exactly when tuning
is most important.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260919011359.88921-1-sj@kernel.org?part=3
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [RFC PATCH v2 3/7] mm/damon/sysfs-schemes: support quota goal complement flag
2026-09-19 1:26 ` sashiko-bot
@ 2026-09-19 1:37 ` SJ Park
0 siblings, 0 replies; 19+ messages in thread
From: SJ Park @ 2026-09-19 1:37 UTC (permalink / raw)
To: sashiko-bot; +Cc: SJ Park, damon
On Sat, 19 Sep 2026 01:26:35 +0000 sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] mm/damon: integer underflow in DAMOS_QUOTA_SOME_MEM_PSI_US complement calculation
> --
>
> commit cd02e1bd14a7884bf9a21f0cab584b1a0f9992ce
> Author: SJ Park <sj@kernel.org>
>
> mm/damon/sysfs-schemes: support quota goal complement flag
>
> This patch adds a new sysfs file for the quota goal directory to allow
> setting and getting the quota goal metric complement flag value.
>
> > diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
> > index 06af417bc9a2f..8f083611741fd 100644
> > --- a/mm/damon/sysfs-schemes.c
> > +++ b/mm/damon/sysfs-schemes.c
>
> [ ... ]
>
> > @@ -2869,7 +2898,8 @@ static int damos_sysfs_add_quota_score(
> > if (!sysfs_goal->target_value)
> > continue;
> >
> > - goal = damos_new_quota_goal(sysfs_goal->metric, false,
> > + goal = damos_new_quota_goal(sysfs_goal->metric,
> > + sysfs_goal->complement,
> > sysfs_goal->target_value);
> > if (!goal)
> > return -ENOMEM;
>
> [Severity: High]
> Now that complement = true can be configured via sysfs, does this expose
> an integer underflow in damos_set_quota_goal_current_value()?
>
> If a user configures a DAMOS quota goal using DAMOS_QUOTA_SOME_MEM_PSI_US
> with complement = true, the actual elapsed wall-clock time between
> evaluations can exceed the configured s->quota.reset_interval due to
> routine thread scheduling delays or high system load.
>
> In mm/damon/core.c:damos_set_quota_goal_current_value(), the accumulated
> PSI time (goal->current_value) could then exceed reset_interval * 1000,
> underflowing the unsigned subtraction:
>
> if (goal->metric = DAMOS_QUOTA_SOME_MEM_PSI_US) {
> goal->current_value = s->quota.reset_interval * 1000 -
> goal->current_value;
> return;
> }
>
> Unlike the basis-point metrics below it, this lacks a safety bounds check.
> The unsigned integer underflow results in an erroneously massive quota score.
>
> This causes damon_feed_loop_next_input() to evaluate score >= goal * 2 and
> return the minimum possible input (min_input), severely throttling the quota
> size (esz) to a minimal value.
>
> This effectively disables DAMOS scheme actions for that window, despite the
> system being under severe memory pressure, which is exactly when tuning
> is most important.
I will fix in the next revision.
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260919011359.88921-1-sj@kernel.org?part=3
>
Thanks,
SJ
^ permalink raw reply [flat|nested] 19+ messages in thread
* [RFC PATCH v2 4/7] mm/damon/tests/core-kunit: test quota_goal->complement commit
2026-09-19 1:13 [RFC PATCH v2 0/7] mm/damon: introduce damos quota goal target metric complement flag SJ Park
` (2 preceding siblings ...)
2026-09-19 1:13 ` [RFC PATCH v2 3/7] mm/damon/sysfs-schemes: support quota goal complement flag SJ Park
@ 2026-09-19 1:13 ` SJ Park
2026-09-19 1:17 ` sashiko-bot
2026-09-19 1:13 ` [RFC PATCH v2 5/7] Docs/mm/damon/design: document damos quota goal complement flag SJ Park
` (2 subsequent siblings)
6 siblings, 1 reply; 19+ messages in thread
From: SJ Park @ 2026-09-19 1:13 UTC (permalink / raw)
Cc: SJ Park, Andrew Morton, Brendan Higgins, David Gow, damon,
kunit-dev, linux-kernel, linux-kselftest, linux-mm
Extend existing DAMOS quota goal commit unit test to test the complement
flag. Set the source complement flag and confirm the destination is
updated to the given input.
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/tests/core-kunit.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index e8290a2c6f343..a2504e96954f7 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -819,6 +819,7 @@ static void damos_test_commit_quota_goal_for(struct kunit *test,
damos_commit_quota_goal(dst, src);
KUNIT_EXPECT_EQ(test, dst->metric, src->metric);
+ KUNIT_EXPECT_EQ(test, dst->complement, src->complement);
KUNIT_EXPECT_EQ(test, dst->target_value, src->target_value);
if (src->metric == DAMOS_QUOTA_USER_INPUT)
KUNIT_EXPECT_EQ(test, dst->current_value, src->current_value);
@@ -862,6 +863,7 @@ static void damos_test_commit_quota_goal(struct kunit *test)
damos_test_commit_quota_goal_for(test, &dst,
&(struct damos_quota_goal){
.metric = DAMOS_QUOTA_USER_INPUT,
+ .complement = true,
.target_value = 789,
.current_value = 12});
damos_test_commit_quota_goal_for(test, &dst,
--
2.47.3
^ permalink raw reply related [flat|nested] 19+ messages in thread* [RFC PATCH v2 5/7] Docs/mm/damon/design: document damos quota goal complement flag
2026-09-19 1:13 [RFC PATCH v2 0/7] mm/damon: introduce damos quota goal target metric complement flag SJ Park
` (3 preceding siblings ...)
2026-09-19 1:13 ` [RFC PATCH v2 4/7] mm/damon/tests/core-kunit: test quota_goal->complement commit SJ Park
@ 2026-09-19 1:13 ` SJ Park
2026-09-19 1:16 ` sashiko-bot
2026-09-19 1:13 ` [RFC PATCH v2 6/7] Docs/admin-guide/mm/damon/usage: update for quota goal complement file SJ Park
2026-09-19 1:13 ` [RFC PATCH v2 7/7] Docs/ABI/damon: update for quota goal metric complement sysfs file SJ Park
6 siblings, 1 reply; 19+ messages in thread
From: SJ Park @ 2026-09-19 1:13 UTC (permalink / raw)
Cc: SJ Park, Liam R. Howlett, Andrew Morton, David Hildenbrand,
Jonathan Corbet, Lorenzo Stoakes, Michal Hocko, Mike Rapoport,
Randy Dunlap, Shuah Khan, Suren Baghdasaryan, Vlastimil Babka,
damon, linux-doc, linux-kernel, linux-mm
Update DAMON design document for the newly added damos quota goal metric
value complement flag.
Signed-off-by: SJ Park <sj@kernel.org>
---
Documentation/mm/damon/design.rst | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/design.rst
index e82390e77a70a..c82be80738c45 100644
--- a/Documentation/mm/damon/design.rst
+++ b/Documentation/mm/damon/design.rst
@@ -702,10 +702,10 @@ There are two such tuning algorithms that users can select as they need.
that the zero quota is a valid quota, and therefore ``qt_exceeds`` :ref:`stat
<damon_design_damos_stat>` will keep increasing in this case.
-The goal can be specified with five parameters, namely ``target_metric``,
-``target_value``, ``current_value``, ``nid`` and ``path``. The auto-tuning
-mechanism tries to make ``current_value`` of ``target_metric`` be same to
-``target_value``.
+The goal can be specified with six parameters, namely ``target_metric``,
+``complement``, ``target_value``, ``current_value``, ``nid`` and ``path``. The
+auto-tuning mechanism tries to make ``current_value`` of ``complement``-ed
+``target_metric`` be same to ``target_value``.
- ``user_input``: User-provided value. Users could use any metric that they
has interest in for the value. Use space main workload's latency or
@@ -733,6 +733,11 @@ mechanism tries to make ``current_value`` of ``target_metric`` be same to
- ``hugepage_mem_bp``: Total huge page to total used memory ratio in bp
(1/10,000).
+``complement`` is a boolean parameter that determines whether to use
+complemented value of the target metric. For example, if ``complement`` is set
+and target metric is ``active_mem_bp``, it is effectively same to
+``inactive_mem_bp``.
+
``nid`` is optionally required for ``node_mem_used_bp``, ``node_mem_free_bp``,
``node_memcg_used_bp``, ``node_memcg_free_bp`` and ``node_eligible_mem_bp`` to
point the specific NUMA node.
--
2.47.3
^ permalink raw reply related [flat|nested] 19+ messages in thread* [RFC PATCH v2 6/7] Docs/admin-guide/mm/damon/usage: update for quota goal complement file
2026-09-19 1:13 [RFC PATCH v2 0/7] mm/damon: introduce damos quota goal target metric complement flag SJ Park
` (4 preceding siblings ...)
2026-09-19 1:13 ` [RFC PATCH v2 5/7] Docs/mm/damon/design: document damos quota goal complement flag SJ Park
@ 2026-09-19 1:13 ` SJ Park
2026-09-19 1:16 ` sashiko-bot
2026-09-19 1:13 ` [RFC PATCH v2 7/7] Docs/ABI/damon: update for quota goal metric complement sysfs file SJ Park
6 siblings, 1 reply; 19+ messages in thread
From: SJ Park @ 2026-09-19 1:13 UTC (permalink / raw)
Cc: SJ Park, Liam R. Howlett, Andrew Morton, David Hildenbrand,
Jonathan Corbet, Lorenzo Stoakes, Michal Hocko, Mike Rapoport,
Randy Dunlap, Shuah Khan, Suren Baghdasaryan, Vlastimil Babka,
damon, linux-doc, linux-kernel, linux-mm
Update DAMON usage document for the newly added quota goal metric
complement sysfs file.
Signed-off-by: SJ Park <sj@kernel.org>
---
Documentation/admin-guide/mm/damon/usage.rst | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-guide/mm/damon/usage.rst
index ba47255448564..3d43954c7046c 100644
--- a/Documentation/admin-guide/mm/damon/usage.rst
+++ b/Documentation/admin-guide/mm/damon/usage.rst
@@ -98,7 +98,8 @@ comma (",").
│ │ │ │ │ │ │ fail_charge_num,fail_charge_denom
│ │ │ │ │ │ │ │ weights/sz_permil,nr_accesses_permil,age_permil
│ │ │ │ │ │ │ │ :ref:`goals <sysfs_schemes_quota_goals>`/nr_goals
- │ │ │ │ │ │ │ │ │ 0/target_metric,target_value,current_value,nid,path
+ │ │ │ │ │ │ │ │ │ 0/target_metric,complement,target_value,
+ │ │ │ │ │ │ │ │ │ current_value,nid,path
│ │ │ │ │ │ │ :ref:`watermarks <sysfs_watermarks>`/metric,interval_us,high,mid,low
│ │ │ │ │ │ │ :ref:`{core_,ops_,}filters <sysfs_filters>`/nr_filters
│ │ │ │ │ │ │ │ 0/type,matching,allow,memcg_path,addr_start,addr_end,damon_target_idx,min,max
@@ -492,12 +493,12 @@ number (``N``) to the file creates the number of child directories named ``0``
to ``N-1``. Each directory represents each goal and current achievement.
Among the multiple feedback, the best one is used.
-Each goal directory contains five files, namely ``target_metric``,
-``target_value``, ``current_value``, ``nid``, and ``path``. Users can set and
-get the five parameters for the quota auto-tuning goals that specified on the
-:ref:`design doc <damon_design_damos_quotas_auto_tuning>` by writing to and
-reading from each of the files. Because the kernel does not update
-``current_value``, reading it only makes sense when ``target_metric`` is
+Each goal directory contains six files, namely ``target_metric``,
+``complement``, ``target_value``, ``current_value``, ``nid``, and ``path``.
+Users can set and get the six parameters for the quota auto-tuning goals that
+specified on the :ref:`design doc <damon_design_damos_quotas_auto_tuning>` by
+writing to and reading from each of the files. Because the kernel does not
+update ``current_value``, reading it only makes sense when ``target_metric`` is
``user_input``. Note that users should further write
``commit_schemes_quota_goals`` to the ``state`` file of the :ref:`kdamond
directory <sysfs_kdamond>` to pass the feedback to DAMON.
--
2.47.3
^ permalink raw reply related [flat|nested] 19+ messages in thread* [RFC PATCH v2 7/7] Docs/ABI/damon: update for quota goal metric complement sysfs file
2026-09-19 1:13 [RFC PATCH v2 0/7] mm/damon: introduce damos quota goal target metric complement flag SJ Park
` (5 preceding siblings ...)
2026-09-19 1:13 ` [RFC PATCH v2 6/7] Docs/admin-guide/mm/damon/usage: update for quota goal complement file SJ Park
@ 2026-09-19 1:13 ` SJ Park
2026-09-19 1:23 ` sashiko-bot
6 siblings, 1 reply; 19+ messages in thread
From: SJ Park @ 2026-09-19 1:13 UTC (permalink / raw)
Cc: SJ Park, Liam R. Howlett, Andrew Morton, David Hildenbrand,
Lorenzo Stoakes, Michal Hocko, Mike Rapoport, Suren Baghdasaryan,
Vlastimil Babka, damon, linux-kernel, linux-mm
Update DAMON ABI document for the newly added damos quota goal metric
complement sysfs file.
Signed-off-by: SJ Park <sj@kernel.org>
---
Documentation/ABI/testing/sysfs-kernel-mm-damon | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-kernel-mm-damon b/Documentation/ABI/testing/sysfs-kernel-mm-damon
index 55df688ea596f..4acb2015c2f4f 100644
--- a/Documentation/ABI/testing/sysfs-kernel-mm-damon
+++ b/Documentation/ABI/testing/sysfs-kernel-mm-damon
@@ -375,6 +375,12 @@ Contact: SJ Park <sj@kernel.org>
Description: Writing to and reading from this file sets and gets the quota
auto-tuning goal metric.
+What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/quotas/goals/<G>/complement
+Date: Sep 2026
+Contact: SJ Park <sj@kernel.org>
+Description: Writing to and reading from this file sets and gets whether to
+ use the complement value of the quota auto-tuning goal metric.
+
What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/quotas/goals/<G>/target_value
Date: Nov 2023
Contact: SJ Park <sj@kernel.org>
--
2.47.3
^ permalink raw reply related [flat|nested] 19+ messages in thread* Re: [RFC PATCH v2 7/7] Docs/ABI/damon: update for quota goal metric complement sysfs file
2026-09-19 1:13 ` [RFC PATCH v2 7/7] Docs/ABI/damon: update for quota goal metric complement sysfs file SJ Park
@ 2026-09-19 1:23 ` sashiko-bot
2026-09-19 1:38 ` SJ Park
0 siblings, 1 reply; 19+ messages in thread
From: sashiko-bot @ 2026-09-19 1:23 UTC (permalink / raw)
To: SJ Park; +Cc: damon
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mm: integer underflow in damos_set_quota_goal_current_value()
--
commit f2de2d4493473c2c847f3ad213eaef640f0e1600
Author: SJ Park <sj@kernel.org>
mm/damon/core: introduce damos_quota_goal->complement
Introduce damos_quota_goal->complement for specifying whether to use a
complemented value of the given goal target metric. Add the field to
the data structure and implement essential core support.
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index 2258b72da7a78..9fd08cbfacd8c 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
[ ... ]
> @@ -3238,6 +3239,23 @@ 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]
Does this unprotected subtraction in damos_set_quota_goal_current_value() risk
an integer underflow?
If a user configures DAMOS_QUOTA_SOME_MEM_PSI_US with complement enabled via
sysfs and sets a target_value greater than reset_interval * 1000, the initial
round (where current_value = target_value) will immediately underflow.
Furthermore, if the kdamond thread is delayed by the scheduler beyond the reset
interval, the measured PSI time can naturally exceed reset_interval * 1000,
which would also trigger the underflow.
This underflow would result in a huge current_value (near ULONG_MAX), which is
then fed into damos_quota_score(), producing an astronomically high tuning
score that aggressively drops the effective quota to zero, breaking the quota
regulation mechanism.
> + return;
> + }
> + if (goal->current_value < 10000)
> + goal->current_value = 10000 - goal->current_value;
> + else
> + goal->current_value = 0;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260919011359.88921-1-sj@kernel.org?part=7
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [RFC PATCH v2 7/7] Docs/ABI/damon: update for quota goal metric complement sysfs file
2026-09-19 1:23 ` sashiko-bot
@ 2026-09-19 1:38 ` SJ Park
0 siblings, 0 replies; 19+ messages in thread
From: SJ Park @ 2026-09-19 1:38 UTC (permalink / raw)
To: sashiko-bot; +Cc: SJ Park, damon
On Sat, 19 Sep 2026 01:23:21 +0000 sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] mm: integer underflow in damos_set_quota_goal_current_value()
> --
>
> commit f2de2d4493473c2c847f3ad213eaef640f0e1600
> Author: SJ Park <sj@kernel.org>
>
> mm/damon/core: introduce damos_quota_goal->complement
>
> Introduce damos_quota_goal->complement for specifying whether to use a
> complemented value of the given goal target metric. Add the field to
> the data structure and implement essential core support.
>
> > diff --git a/mm/damon/core.c b/mm/damon/core.c
> > index 2258b72da7a78..9fd08cbfacd8c 100644
> > --- a/mm/damon/core.c
> > +++ b/mm/damon/core.c
>
> [ ... ]
>
> > @@ -3238,6 +3239,23 @@ 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]
> Does this unprotected subtraction in damos_set_quota_goal_current_value() risk
> an integer underflow?
>
> If a user configures DAMOS_QUOTA_SOME_MEM_PSI_US with complement enabled via
> sysfs and sets a target_value greater than reset_interval * 1000, the initial
> round (where current_value = target_value) will immediately underflow.
>
> Furthermore, if the kdamond thread is delayed by the scheduler beyond the reset
> interval, the measured PSI time can naturally exceed reset_interval * 1000,
> which would also trigger the underflow.
>
> This underflow would result in a huge current_value (near ULONG_MAX), which is
> then fed into damos_quota_score(), producing an astronomically high tuning
> score that aggressively drops the effective quota to zero, breaking the quota
> regulation mechanism.
I will fix this in the next spin.
>
> > + return;
> > + }
> > + if (goal->current_value < 10000)
> > + goal->current_value = 10000 - goal->current_value;
> > + else
> > + goal->current_value = 0;
> > }
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260919011359.88921-1-sj@kernel.org?part=7
>
Thanks,
SJ
^ permalink raw reply [flat|nested] 19+ messages in thread