mm/damon: introduce damos quota goal target metric complement flag
Subsystems (5)
SJ Park
maintainercover mm/damon: introduce damos quota goal target metric complement flag
Aim-oriented DAMOS quota auto-tuning assumes the aggressiveness of the scheme (quota) and the quota goal metric are directly proportional. Depending on the scheme setup and usage, keeping the relationship can be challenging.
For example, let's suppose a memory tiering approach for higher upper tier utilization. One common idea for that (TPP) is utilizing two schemes, one for promotion and the other one for demotion. The promotion scheme migrates hot pages from lower tier to upper tier, aiming for high utilization of the upper tier. The demotion scheme migrates cold pages from upper tier to lower tier, aiming for head room free memory of the upper tier. Both schemes and their goals are in direct proportion. However, for this kind of use case, we need to implement two different goal metrics (per-node memory utilization and free memory ratio) while essentially the free memory ratio is just a complemented value of the utilization.
To avoid adding too many new metrics, we are adding metrics that turn out to be really needed for each found use case. For example, some_mem_psi_us, node_eligible_mem_bp and hugepage_mem_bp don't have their complemented value version. But it is not really difficult to expect use cases that their complemented version can be useful. For example, hugepage_mem_bp use case may need a way to reduce the hugepage ratio. That would require a complemented version of hugepage_mem_bp. Adding a new metric for each of such use cases could make the number of metrics unnecessarily high, and discourage flexible usages of DAMOS.
Add a new flag, quota goal complement, to allow flexible tuning goal setup without unnecessarily increasing the number of metrics. The flag specifies whether to use the complemented value of the given goal metric for the tuning. For example, if the complement flag is set, the upper tier memory utilization ratio metric works the same as the free memory ratio metric for the tier.
SJ Park (7):
mm/damon/core: introduce damos_quota_goal->complement mm/damon: add complement argument to damos_new_quota_goal() mm/damon/sysfs-schemes: support quota goal complement flag mm/damon/tests/core-kunit: test quota_goal->complement commit Docs/mm/damon/design: document damos quota goal complement flag Docs/admin-guide/mm/damon/usage: update for quota goal complement file Docs/ABI/damon: update for quota goal metric complement sysfs file
.../ABI/testing/sysfs-kernel-mm-damon | 6 ++++ Documentation/admin-guide/mm/damon/usage.rst | 13 ++++---- Documentation/mm/damon/design.rst | 13 +++++--- include/linux/damon.h | 4 ++- mm/damon/core.c | 21 +++++++++++-- mm/damon/lru_sort.c | 5 ++-- mm/damon/reclaim.c | 5 ++-- mm/damon/sysfs-schemes.c | 30 +++++++++++++++++++ mm/damon/tests/core-kunit.h | 4 ++- samples/damon/mtier.c | 2 +- 10 files changed, 83 insertions(+), 20 deletions(-)
base-commit: 93d2baf86ca2a321306c5ea2f07e3d936cc4e6fa
Signature · 1 line
2.47.3
SJ Park
maintainerRFC PATCH 1/7 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.
--- include/linux/damon.h | 2 ++ mm/damon/core.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+)
include/linux/damon.h +2 -0
@@ -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 */
mm/damon/core.c +14 -0
@@ -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,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; +else + goal->current_value =10000 - goal->current_value; }/* Return the highest score since it makes schemes least aggressive */
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH 1/7] mm/damon/core: introduce damos_quota_goal->complement
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() for complemented metrics --
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() for complemented metrics --
commit 94b0fa41235165f1d082ca5735dcefbf9f65199b
Author: SJ Park <[email protected]>
mm/damon/core: introduce damos_quota_goal->complement
This commit introduces the complement field to struct damos_quota_goal to allow specifying whether to use a complemented value of the goal target metric. It adds the field and implements the core support, handling the flag during quota goal commit and current quota goal metric value retrieval.
Quoted 4 lines
mm/damon/core.c +0
-0
[ ... ]
Quoted 7 lines
mm/damon/core.c +3
-0@@ -3238,6 +3239,19 @@ static void damos_set_quota_goal_current_value(struct damon_ctx *c,default :break ; } +if (!goal->complement) +return ; +
mm/damon/core.c static void damos_set_quota_goal_current_value(struct damon_ctx *c, · line 3254
Quoted 10 lines
mm/damon/core.c +10
-0+/* 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; +else + goal->current_value =10000 - goal->current_value;
[Severity: High]
Can this unsigned subtraction result in an integer underflow?
In damos_set_quota_goal_current_value(), if the measured memory stall (current_value) exceeds the reset interval due to kdamond thread scheduling delays, heavy system load, or if the user configures reset_interval_ms to 0 via sysfs, s->quota.reset_interval * 1000 - goal->current_value will underflow.
Similarly, for BP metrics relying on loosely-coupled lockless kernel counters (e.g., global_node_page_state), per-CPU drift can occasionally cause the returned value to exceed 10000, causing 10000 - goal->current_value to underflow.
If an underflow occurs, it produces a value near ULONG_MAX.
Would passing this immense value to the auto-tuner mistakenly drop the scheme's reclaim quota to its minimum precisely when memory pressure is highest?
Quoted 3 lines
mm/damon/core.c +0
-0}/* Return the highest score since it makes schemes least aggressive */
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
SJ Park
maintainerRe: [RFC PATCH 1/7] mm/damon/core: introduce damos_quota_goal->complement
Quoted 53 lines · On Fri, 18 Sep 2026 14:48:17 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mm: integer underflow indamos_set_quota_goal_current_value()for complemented metrics --commit
94b0fa41235165f1d082ca5735dcefbf9f65199b
Author: SJ Park <[email protected]>
mm/damon/core: introducedamos_quota_goal->complementThis commit introduces the complement field to struct
damos_quota_goalto allow specifying whether to use a complemented value of the goal target metric. It adds the field and implements the core support, handling the flag during quota goal commit and current quota goal metric value retrieval.Quoted 4 lines
mm/damon/core.c +0
-0[ ... ]
Quoted 7 lines
mm/damon/core.c +3
-0@@ -3238,6 +3239,19 @@ static void damos_set_quota_goal_current_value(struct damon_ctx *c,default :break ; } +if (!goal->complement) +return ; +mm/damon/core.c static void damos_set_quota_goal_current_value(struct damon_ctx *c, · line 3254
Quoted 10 lines
mm/damon/core.c +10
-0+/* 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; +else + goal->current_value =10000 - goal->current_value;[Severity: High]
Can this unsigned subtraction result in an integer underflow?In
damos_set_quota_goal_current_value(), if the measured memory stall (current_value) exceeds the reset interval due to kdamond thread scheduling delays, heavy system load, or if the user configuresreset_interval_msto 0 via sysfs,s->quota.reset_interval* 1000 -goal->current_valuewill underflow.Similarly, for BP metrics relying on loosely-coupled lockless kernel counters (e.g.,
global_node_page_state), per-CPU drift can occasionally cause the returned value to exceed 10000, causing 10000 -goal->current_valueto underflow.
Quoted 4 lines
If an underflow occurs, it produces a value near
ULONG_MAX.Would passing this immense value to the auto-tuner mistakenly drop the scheme's reclaim quota to its minimum precisely when memory pressure is highest?
Good catch. I will fix this in the next revision.
Quoted 7 lines
Quoted 4 lines
mm/damon/core.c +0
-0}/* Return the highest score since it makes schemes least aggressive */ Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Thanks,
SJ
SJ Park
maintainerRFC PATCH 2/7 mm/damon: add complement argument to damos_new_quota_goal()
In reply to SJ Parkdamos_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.
--- 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(-)
include/linux/damon.h +1 -1
@@ -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);
mm/damon/core.c +4 -3
@@ -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);
mm/damon/lru_sort.c +3 -2
@@ -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 ;
mm/damon/reclaim.c +3 -2
@@ -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;
mm/damon/sysfs-schemes.c +1 -1
@@ -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 ;
mm/damon/tests/core-kunit.h +1 -1
@@ -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;
samples/damon/mtier.c +1 -1
@@ -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;
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH 2/7] mm/damon: add complement argument to damos_new_quota_goal()
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
damos_quota_goal->complementneeds 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 <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
SJ Park
maintainerRFC PATCH 3/7 mm/damon/sysfs-schemes: support quota goal complement flag
In reply to SJ ParkAdd a new sysfs file, complement, under the quota goal directory. It works for setting and getting the quota goal metric complement flag value.
--- mm/damon/sysfs-schemes.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)
mm/damon/sysfs-schemes.c +31 -1
@@ -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 ;
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH 3/7] mm/damon/sysfs-schemes: support quota goal complement flag
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] mm: unsigned integer underflow in damos quota complement calculation --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mm: unsigned integer underflow in damos quota complement calculation --
commit 8f39260b8b618fca6e69e55388bee135a86971f3
Author: SJ Park <[email protected]>
mm/damon/sysfs-schemes: support quota goal complement flag
This commit adds a new sysfs file to support setting and getting the quota goal metric complement flag. It exposes this flag to user space, allowing the complement value to be passed to damos_new_quota_goal().
Quoted 4 lines
mm/damon/sysfs-schemes.c +0
-0
[ ... ]
mm/damon/sysfs-schemes.c static int damos_sysfs_add_quota_score( · line 2903
Quoted 8 lines
mm/damon/sysfs-schemes.c +2
-1@@ -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);
[Severity: High]
Does exposing the complement flag to user space introduce an integer underflow risk for PSI metrics?
When the complement flag is enabled via sysfs for a DAMOS_QUOTA_SOME_MEM_PSI_US goal, damos_set_quota_goal_current_value() in mm/damon/core.c performs a direct subtraction:
if (goal->metric == DAMOS_QUOTA_SOME_MEM_PSI_US) goal->current_value = s->quota.reset_interval * 1000 - goal->current_value; else goal->current_value = 10000 - goal->current_value;
Because DAMON runs in a preemptible worker thread, natural scheduling delays can cause the elapsed PSI time (initially stored in goal->current_value) to exceed the nominal reset_interval * 1000.
If this happens, the subtraction underflows, wrapping current_value to near ULONG_MAX. This corrupted value is then used to calculate the quota score, which completely breaks DAMON's throttling logic.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
SJ Park
maintainerRe: [RFC PATCH 3/7] mm/damon/sysfs-schemes: support quota goal complement flag
Quoted 41 lines · On Fri, 18 Sep 2026 15:05:35 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mm: unsigned integer underflow in damos quota complement calculation --commit
8f39260b8b618fca6e69e55388bee135a86971f3
Author: SJ Park <[email protected]>
mm/damon/sysfs-schemes: support quota goal complement flagThis commit adds a new sysfs file to support setting and getting the quota goal metric complement flag. It exposes this flag to user space, allowing the complement value to be passed to
damos_new_quota_goal().Quoted 4 lines
mm/damon/sysfs-schemes.c +0
-0[ ... ]
mm/damon/sysfs-schemes.c static int damos_sysfs_add_quota_score( · line 2903
Quoted 8 lines
mm/damon/sysfs-schemes.c +2
-1@@ -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);[Severity: High]
Does exposing the complement flag to user space introduce an integer underflow risk for PSI metrics?When the complement flag is enabled via sysfs for a
DAMOS_QUOTA_SOME_MEM_PSI_USgoal,damos_set_quota_goal_current_value()inmm/damon/core.cperforms a direct subtraction:if (goal->metric == DAMOS_QUOTA_SOME_MEM_PSI_US) goal->current_value = s->quota.reset_interval * 1000 - goal->current_value; else goal->current_value = 10000 - goal->current_value;
Quoted 7 lines
Because DAMON runs in a preemptible worker thread, natural scheduling delays can cause the elapsed PSI time (initially stored in
goal->current_value) to exceed the nominalreset_interval* 1000.If this happens, the subtraction underflows, wrapping
current_valueto nearULONG_MAX. This corrupted value is then used to calculate the quota score, which completely breaks DAMON's throttling logic.
I will fix the core logic in the next revision.
Quoted 3 lines
Signature · 2 lines
-- Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Thanks,
SJ
SJ Park
maintainerRFC PATCH 4/7 mm/damon/tests/core-kunit: test quota_goal->complement commit
In reply to SJ ParkExtend 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.
--- mm/damon/tests/core-kunit.h | 2 ++ 1 file changed, 2 insertions(+)
mm/damon/tests/core-kunit.h +2 -0
@@ -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,
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH 4/7] mm/damon/tests/core-kunit: test quota_goal->complement commit
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines
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 <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
SJ Park
maintainerRFC PATCH 5/7 Docs/mm/damon/design: document damos quota goal complement flag
In reply to SJ ParkUpdate DAMON design document for the newly added damos quota goal metric value complement flag.
--- Documentation/mm/damon/design.rst | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
Documentation/mm/damon/design.rst +9 -4
@@ -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.
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH 5/7] Docs/mm/damon/design: document damos quota goal complement flag
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines
Update DAMON design document for the newly added damos quota goal metric value complement flag.
Signed-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
SJ Park
maintainerRFC PATCH 6/7 Docs/admin-guide/mm/damon/usage: update for quota goal complement file
In reply to SJ ParkUpdate DAMON usage document for the newly added quota goal metric complement sysfs file.
--- Documentation/admin-guide/mm/damon/usage.rst | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
Documentation/admin-guide/mm/damon/usage.rst +7 -6
@@ -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
@@ -493,11 +494,11 @@ 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 +``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.
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH 6/7] Docs/admin-guide/mm/damon/usage: update for quota goal complement file
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] damon: inconsistent file count in usage documentation --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] damon: inconsistent file count in usage documentation
--
commit 3ff19ca809eb7c0b839b503a68fe82c349a81160
Author: SJ Park <[email protected]>
Docs/admin-guide/mm/damon/usage: update for quota goal complement file
Update DAMON usage document for the newly added quota goal metric complement sysfs file.
Quoted 4 lines
Documentation/admin-guide/mm/damon/usage.rst +0
-0
[ ... ]
Documentation/admin-guide/mm/damon/usage.rst to ``N-1``. Each directory represents each goal and current achievement. · line 497
Quoted 10 lines
Documentation/admin-guide/mm/damon/usage.rst +1
-5@@ -493,11 +494,11 @@ 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 +``complement``, ``target_value``, ``current_value``, ``nid``, and ``path``.
[Severity: Low]
Does this introductory sentence need to be updated to say six files instead of five files?
The patch updates the next sentence to say six parameters, but the word five in the preceding context line was missed, so it now contradicts the list of six files that immediately follows it.
Quoted 7 lines
Documentation/admin-guide/mm/damon/usage.rst +4
-0+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.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
SJ Park
maintainerRe: [RFC PATCH 6/7] Docs/admin-guide/mm/damon/usage: update for quota goal complement file
Quoted 34 lines · On Fri, 18 Sep 2026 15:09:33 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] damon: inconsistent file count in usage documentation
--commit
3ff19ca809eb7c0b839b503a68fe82c349a81160
Author: SJ Park <[email protected]>Docs/admin-guide/mm/damon/usage: update for quota goal complement file
Update DAMON usage document for the newly added quota goal metric complement sysfs file.
Quoted 4 lines
Documentation/admin-guide/mm/damon/usage.rst +0
-0[ ... ]
Documentation/admin-guide/mm/damon/usage.rst to ``N-1``. Each directory represents each goal and current achievement. · line 497
Quoted 10 lines
Documentation/admin-guide/mm/damon/usage.rst +1
-5@@ -493,11 +494,11 @@ 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 +``complement``, ``target_value``, ``current_value``, ``nid``, and ``path``.[Severity: Low]
Does this introductory sentence need to be updated to say six files instead of five files?
Quoted 3 lines
The patch updates the next sentence to say six parameters, but the word five in the preceding context line was missed, so it now contradicts the list of six files that immediately follows it.
Nice catch! I will fix this in the next revision.
Quoted 11 lines
Quoted 8 lines
Documentation/admin-guide/mm/damon/usage.rst +4
-0+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.Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Thanks,
SJ
SJ Park
maintainerRFC PATCH 7/7 Docs/ABI/damon: update for quota goal metric complement sysfs file
In reply to SJ ParkUpdate DAMON ABI document for the newly added damos quota goal metric complement sysfs file.
--- Documentation/ABI/testing/sysfs-kernel-mm-damon | 6 ++++++ 1 file changed, 6 insertions(+)
Documentation/ABI/testing/sysfs-kernel-mm-damon +6 -0
@@ -375,6 +375,12 @@ Contact: SJ Park <[email protected]> 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 <[email protected]> +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 <[email protected]>
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH 7/7] Docs/ABI/damon: update for quota goal metric complement sysfs file
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() --
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 <[email protected]>
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.
Quoted 4 lines
mm/damon/core.c +0
-0
[ ... ]
Quoted 5 lines
mm/damon/core.c +1
-0@@ -3238,6 +3239,19 @@ static void damos_set_quota_goal_current_value(struct damon_ctx *c,default :break ; } +if (!goal->complement)
mm/damon/core.c static void damos_set_quota_goal_current_value(struct damon_ctx *c, · line 3252
Quoted 10 lines
mm/damon/core.c +10
-0+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.
mm/damon/core.c static void damos_set_quota_goal_current_value(struct damon_ctx *c, · line 3254
Quoted 2 lines
mm/damon/core.c +2
-0+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.
Quoted 3 lines
mm/damon/core.c +0
-0}/* Return the highest score since it makes schemes least aggressive */
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7