mm/damon: fix wrong behaviors in DAMOS quota goals and sysfs refresh_ms
Subsystems (3)
SJ Park
maintainerRFC PATCH 2/3 mm/damon/core: copy nid for eligible_mem_bp damos quota goal commit
In reply to SJ Parkdamos_commit_quota_goal_union() is not updating the ->nid union field when the goal metric is DAMOS_QUITA_NODE_ELIGIBLE_MEM_BP. Hence, if a DAMOS quota goal of the type is online committed in a way that it will reuse other quota goal's memory space, the new goal will work with a garbage nid value. As a result, the DAMOS scheme can show unexpected aggressiveness. Do the update.
The user impact is not catastrophic. No leak or crash happens. Doing the quota goal online commit that can reproduce the issue is expected to be not common. This issue was not found by real users but the AI review. That said, the issue can reliably be reproduced.
This issue was discovered [1] by Sashiko.
[1] https://lore.kkernel.org/[email protected]
--- mm/damon/core.c | 3 +++ 1 file changed, 3 insertions(+)
mm/damon/core.c +3 -0
@@ -1136,6 +1136,9 @@ static void damos_commit_quota_goal_union( dst->nid = src->nid; dst->memcg_id = src->memcg_id;break ; +case DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP : + dst->nid = src->nid; +break ;default :break ; }
Signature · 1 line
2.47.3
SJ Park
maintainercover mm/damon: fix wrong behaviors in DAMOS quota goals and sysfs refresh_ms
DAMOS quota goals and DAMON sysfs refresh_ms file have bugs that can produce non critical but still unexpected behaviors. Fix the two bugs.
Patches 1 and 2 fix the bugs in DAMOS PSI goal initialization and eligible_mem_bp online commit, respectively. Patch 3 fixes the bug in DAMON sysfs refresh_ms file handling.
Changes from RFC
- RFC: https://lore.kernel.org/[email protected]
(Mistakenly missed RFC tag)
- Fix build error.
- Add eligible_mem_bp nid commit fix.
SJ Park (3):
mm/damon/core: initialize damos_quota_goal->last_psi_total mm/damon/core: copy nid for eligible_mem_bp damos quota goal commit mm/damon/sysfs: set next refresh jiffies per sysfs context
mm/damon/core.c | 21 ++++++++++++++++++++- mm/damon/sysfs.c | 11 +++++------ 2 files changed, 25 insertions(+), 7 deletions(-)
base-commit: 9e11dd3caaf0ac70acdc0f568265a7fa5085ef42
Signature · 1 line
2.47.3
SJ Park
maintainerRFC PATCH 1/3 mm/damon/core: initialize damos_quota_goal->last_psi_total
When DAMOS_QUOTA_SOME_MEM_PSI_US metric damos quota goal is set, the PSI delta for the feedback loop is calculated using damos_quota_goal->last_psi_total. However, it is initialized only after the first feedback loop. The first iteration of the loop uses the uninitialized value. As a result, the feedback loop can change the effective quota in an unexpected way at the first iteration.
The user impact of the issue is not big, because the issue impacts only the first iteration of the feedback loop. The feedback loop also has an internal cap of the quota adjustment. The wrong adjustment will soon be corrected over a few iterations. For this reason, doing no initialization at commit time was intentional. It is also explicitly commented. That said, nobody likes behaviors that are unexpected or difficult to be expected. Fixing it is also simple and not expensive.
Initialize the field at the beginning of kdamond and each commit of SOME_MEM_PSI_US type quota goals.
The issue was discovered [1] by Sashiko.
[1] https://lore.kernel.org/[email protected]
--- mm/damon/core.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
mm/damon/core.c +17 -1
@@ -1118,10 +1118,15 @@ static struct damos_quota_goal *damos_nth_quota_goal(return NULL ; } +static u64 damos_get_some_mem_psi_total (void ); +static void damos_commit_quota_goal_union (struct damos_quota_goal *dst,struct damos_quota_goal *src) {switch (dst->metric) { +case DAMOS_QUOTA_SOME_MEM_PSI_US : + dst->last_psi_total =damos_get_some_mem_psi_total (); +break ;case DAMOS_QUOTA_NODE_MEM_USED_BP :case DAMOS_QUOTA_NODE_MEM_FREE_BP : dst->nid = src->nid;
@@ -1143,7 +1148,6 @@ static void damos_commit_quota_goal( dst->target_value = src->target_value;if (dst->metric ==DAMOS_QUOTA_USER_INPUT ) dst->current_value = src->current_value; -/* keep last_psi_total as is, since it will be updated in next cycle */ damos_commit_quota_goal_union (dst, src); }
@@ -3741,6 +3745,17 @@ static int kdamond_wait_activation(struct damon_ctx *ctx)return -EBUSY ; } +static void damos_init_quota_goal_last_psi (struct damos *s) +{ +struct damos_quota_goal *goal; + +damos_for_each_quota_goal (goal, &s->quota) { +if (goal->metric !=DAMOS_QUOTA_SOME_MEM_PSI_US ) +continue ; + goal->last_psi_total =damos_get_some_mem_psi_total (); + } +} +static void kdamond_init_ctx (struct damon_ctx *ctx) { unsigned long sample_interval = ctx->attrs.sample_interval ?
@@ -3757,6 +3772,7 @@ static void kdamond_init_ctx(struct damon_ctx *ctx)damon_for_each_scheme (scheme, ctx) {damos_set_next_apply_sis (scheme, ctx);damos_set_filters_default_reject (scheme); +damos_init_quota_goal_last_psi (scheme); } }
Signature · 1 line
2.47.3
SJ Park
maintainerRFC PATCH 3/3 mm/damon/sysfs: set next refresh jiffies per sysfs context
In reply to SJ ParkWhen 'refresh_ms' is set, DAMON sysfs interface periodically updates auto-tuned parameters and DAMOS stats. The timestamp for the next refresh is initialized when a DAMON context starts, and updated in its damon_call() callback function. That is, each DAMON context updates it. However, the timestamp is a global variable that is shared with all the contexts. When there are multiple DAMON contexts having different refresh_ms, the update frequency will be changed, depending on the order of the contexts. When there are multiple kdamonds, it will be even more chaotic. Fix the problem by having the timestamp per each context.
The user impact is not very critical. It does not leak, corrupt or crash. The update will not be faster or slower than the lowest and largest refresh_ms values of the contexts, respectively. The user can also manually ask the updates on demand using kdamond state commands. That said, clearly this is a bug and can easily be reproduced.
--- mm/damon/sysfs.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
mm/damon/sysfs.c +5 -6
@@ -1789,6 +1789,7 @@ struct damon_sysfs_kdamond {struct damon_sysfs_contexts *contexts;struct damon_ctx *damon_ctx;unsigned int refresh_ms; +unsigned long next_refresh_jiffies; };static struct damon_sysfs_kdamond *damon_sysfs_kdamond_alloc (void )
@@ -2215,17 +2216,15 @@ static struct damon_ctx *damon_sysfs_build_ctx(return ctx; } -static unsigned long damon_sysfs_next_update_jiffies; -static int damon_sysfs_repeat_call_fn (void *data) {struct damon_sysfs_kdamond *sysfs_kdamond = data;if (!sysfs_kdamond->refresh_ms)return 0 ; -if (time_before (jiffies, damon_sysfs_next_update_jiffies)) +if (time_before (jiffies, sysfs_kdamond->next_refresh_jiffies))return 0 ; - damon_sysfs_next_update_jiffies = jiffies + + sysfs_kdamond->next_refresh_jiffies = jiffies +msecs_to_jiffies (sysfs_kdamond->refresh_ms);if (!mutex_trylock (&damon_sysfs_lock))
@@ -2273,8 +2272,8 @@ static int damon_sysfs_turn_damon_on(struct damon_sysfs_kdamond *kdamond) } kdamond->damon_ctx = ctx; - damon_sysfs_next_update_jiffies = - jiffies +msecs_to_jiffies (kdamond->refresh_ms); + kdamond->next_refresh_jiffies = jiffies + +msecs_to_jiffies (kdamond->refresh_ms); repeat_call_control->fn = damon_sysfs_repeat_call_fn; repeat_call_control->data = kdamond;
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH v1.1 3/3] mm/damon/sysfs: set next refresh jiffies per sysfs context
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 16 lines
When '
refresh_ms' is set, DAMON sysfs interface periodically updates auto-tuned parameters and DAMOS stats. The timestamp for the next refresh is initialized when a DAMON context starts, and updated in itsdamon_call()callback function. That is, each DAMON context updates it. However, the timestamp is a global variable that is shared with all the contexts. When there are multiple DAMON contexts having differentrefresh_ms, the update frequency will be changed, depending on the order of the contexts. When there are multiple kdamonds, it will be even more chaotic. Fix the problem by having the timestamp per each context.The user impact is not very critical. It does not leak, corrupt or crash. The update will not be faster or slower than the lowest and largest
refresh_msvalues of the contexts, respectively. The user can also manually ask the updates on demand using kdamond state commands. That said, clearly this is a bug and can easily be reproduced.
Quoted 3 lines
Fixes 9fd7bb5083d1 ("mm/damon/sysfs: change next_update_jiffies to a global variable")Cc <[email protected]> # 6.18.xSigned-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=3
[email protected]
AI reviewRe: [RFC PATCH v1.1 2/3] mm/damon/core: copy nid for eligible_mem_bp damos quota goal commit
In reply to SJ ParkSashiko has reviewed this patch and found no issues. It looks great!
Quoted 12 lines
damos_commit_quota_goal_union()is not updating the ->nid union field when the goal metric isDAMOS_QUITA_NODE_ELIGIBLE_MEM_BP. Hence, if a DAMOS quota goal of the type is online committed in a way that it will reuse other quota goal's memory space, the new goal will work with a garbage nid value. As a result, the DAMOS scheme can show unexpected aggressiveness. Do the update.The user impact is not catastrophic. No leak or crash happens. Doing the quota goal online commit that can reproduce the issue is expected to be not common. This issue was not found by real users but the AI review. That said, the issue can reliably be reproduced.
Quoted 7 lines
This issue was discovered [1] by Sashiko.
[1] https://lore.kkernel.org/[email protected]
Fixes 9138e27a3bc3 ("mm/damon: add node_eligible_mem_bp goal metric")Cc <[email protected]> # 7.2.xSigned-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
[email protected]
AI reviewRe: [RFC PATCH v1.1 1/3] mm/damon/core: initialize damos_quota_goal->last_psi_total
In reply to SJ ParkThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Unconditionally resetting last_psi_total in damos_commit_quota_goal_union() breaks the feedback…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Unconditionally resetting last_psi_total in damos_commit_quota_goal_union() breaks the feedback loop measurement interval for existing goals during sysfs updates.
- [Medium] The patch changes the semantics of damos_commit_quota_goal() to explicitly overwrite last_psi_total instead of preserving it, but leaves behind a KUnit test assertion that expects preservation. --
commit 8007d7351717974f3d1ef45ed438346542307389
Author: SJ Park <[email protected]>
mm/damon/core: initialize damos_quota_goal->last_psi_total
This patch initializes the last_psi_total for DAMOS_QUOTA_SOME_MEM_PSI_US quota goals to prevent the first iteration of the feedback loop from using an uninitialized value. It introduces initialization at the start of kdamond and during each goal commit.
Quoted 7 lines
mm/damon/core.c +0
-0@@ -1118,10 +1118,15 @@ static struct damos_quota_goal *damos_nth_quota_goal(return NULL ; }
mm/damon/core.c static struct damos_quota_goal *damos_nth_quota_goal( · line 1129
Quoted 10 lines
mm/damon/core.c +5
-0+static u64 damos_get_some_mem_psi_total (void ); +static void damos_commit_quota_goal_union (struct damos_quota_goal *dst,struct damos_quota_goal *src) {switch (dst->metric) { +case DAMOS_QUOTA_SOME_MEM_PSI_US : + dst->last_psi_total =damos_get_some_mem_psi_total (); +break ;
[Severity: High]
Does this unconditional reset of last_psi_total truncate the measurement window for running goals that are updated via sysfs?
When a user updates a running DAMON context via sysfs that includes an existing DAMOS_QUOTA_SOME_MEM_PSI_US goal, this overwrites the running goal's last_psi_total with the current time's PSI value, without resetting the overall charged_from interval timer.
Could this produce an artificially small current_value, causing the feedback loop tuner to falsely assume memory pressure is low and erroneously increase the scheme's quota?
Quoted 3 lines
mm/damon/core.c +0
-0case DAMOS_QUOTA_NODE_MEM_USED_BP :case DAMOS_QUOTA_NODE_MEM_FREE_BP : dst->nid = src->nid;
[ ... ]
mm/damon/core.c static void damos_commit_quota_goal( · line 1152
Quoted 7 lines
mm/damon/core.c +0
-1@@ -1143,7 +1148,6 @@ static void damos_commit_quota_goal( dst->target_value = src->target_value;if (dst->metric ==DAMOS_QUOTA_USER_INPUT ) dst->current_value = src->current_value; -/* keep last_psi_total as is, since it will be updated in next cycle */ damos_commit_quota_goal_union (dst, src); }
[Severity: Medium]
Since the semantics of damos_commit_quota_goal() have changed to explicitly overwrite last_psi_total rather than preserve it, should the corresponding KUnit test be updated as well?
The existing KUnit test in mm/damon/tests/core-kunit.h (damos_test_commit_quota_goal_for()) expects the old preservation behavior:
if (dst_last_psi_total && src->metric == DAMOS_QUOTA_SOME_MEM_PSI_US)
KUNIT_EXPECT_EQ(test, dst->last_psi_total, dst_last_psi_total);
Without updating this assertion, there appears to be a mismatch between the new code behavior and what the test expects.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
SJ Park
maintainerRe: [RFC PATCH v1.1 1/3] mm/damon/core: initialize damos_quota_goal->last_psi_total
Quoted 39 lines · On Thu, 27 Aug 2026 13:59:58 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Unconditionally resettinglast_psi_totalindamos_commit_quota_goal_union()breaks the feedback loop measurement interval for existing goals during sysfs updates.
- [Medium] The patch changes the semantics ofdamos_commit_quota_goal()to explicitly overwritelast_psi_totalinstead of preserving it, but leaves behind a KUnit test assertion that expects preservation. --commit
8007d7351717974f3d1ef45ed438346542307389
Author: SJ Park <[email protected]>
mm/damon/core: initializedamos_quota_goal->last_psi_totalThis patch initializes the
last_psi_totalforDAMOS_QUOTA_SOME_MEM_PSI_USquota goals to prevent the first iteration of the feedback loop from using an uninitialized value. It introduces initialization at the start of kdamond and during each goal commit.Quoted 7 lines
mm/damon/core.c +0
-0@@ -1118,10 +1118,15 @@ static struct damos_quota_goal *damos_nth_quota_goal(return NULL ; }mm/damon/core.c static struct damos_quota_goal *damos_nth_quota_goal( · line 1129
Quoted 10 lines
mm/damon/core.c +5
-0+static u64 damos_get_some_mem_psi_total (void ); +static void damos_commit_quota_goal_union (struct damos_quota_goal *dst,struct damos_quota_goal *src) {switch (dst->metric) { +case DAMOS_QUOTA_SOME_MEM_PSI_US : + dst->last_psi_total =damos_get_some_mem_psi_total (); +break ;[Severity: High]
Does this unconditional reset oflast_psi_totaltruncate the measurement window for running goals that are updated via sysfs?
Quoted 8 lines
When a user updates a running DAMON context via sysfs that includes an existing
DAMOS_QUOTA_SOME_MEM_PSI_USgoal, this overwrites the running goal'slast_psi_totalwith the current time's PSI value, without resetting the overallcharged_frominterval timer.Could this produce an artificially small
current_value, causing the feedback loop tuner to falsely assume memory pressure is low and erroneously increase the scheme's quota?
When the entire context is committed, damos->next_apply_sis is also updated, so this problem doesn't happen. However, we allow commit_schemes_quota_goals sysfs command to directly commit goals. In the case, this issue can happen.
We could handle the corner case. But I start feeling this is adding too much complexity for the small bug. As also mentioned on the original commit message, the impact is transient and minor. Users can also set additional quotas or quota goals as guardrails. I will keep the original behavior as is, and just add comments about it. We can revisit if a real user gets real problem from the documented behavior.
Quoted 20 lines
Quoted 4 lines
mm/damon/core.c +0
-0case DAMOS_QUOTA_NODE_MEM_USED_BP :case DAMOS_QUOTA_NODE_MEM_FREE_BP : dst->nid = src->nid;[ ... ]
mm/damon/core.c static void damos_commit_quota_goal( · line 1152
Quoted 7 lines
mm/damon/core.c +0
-1@@ -1143,7 +1148,6 @@ static void damos_commit_quota_goal( dst->target_value = src->target_value;if (dst->metric =DAMOS_QUOTA_USER_INPUT ) dst->current_value = src->current_value; -/* keep last_psi_total as is, since it will be updated in next cycle */ damos_commit_quota_goal_union (dst, src); }[Severity: Medium]
Since the semantics ofdamos_commit_quota_goal()have changed to explicitly overwritelast_psi_totalrather than preserve it, should the corresponding KUnit test be updated as well?
Quoted 8 lines
The existing KUnit test in
mm/damon/tests/core-kunit.h(damos_test_commit_quota_goal_for()) expects the old preservation behavior:if (
dst_last_psi_total&&src->metric=DAMOS_QUOTA_SOME_MEM_PSI_US)KUNIT_EXPECT_EQ(test, dst->last_psi_total, dst_last_psi_total);Without updating this assertion, there appears to be a mismatch between the new code behavior and what the test expects.
Good catch. I usually run kunit without CONFIG_PSI, so didn't encounter the issue. However, as I'm changing my mind to keep the behavior but just update the documents, this is irrelevant.
Quoted 4 lines
Signature · 2 lines
-- Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Thanks,
SJ
SJ Park
maintainerRe: [RFC PATCH v1.1 1/3] mm/damon/core: initialize damos_quota_goal->last_psi_total
Quoted 1 line · On Thu, 27 Aug 2026 07:17:37 -0700 SJ Park <[email protected]> wrote:
On Thu, 27 Aug 2026 13:59:58 +0000 [email protected] wrote:
[...]
Quoted 17 lines
Quoted 4 lines
[Severity: High]
Does this unconditional reset oflast_psi_totaltruncate the measurement window for running goals that are updated via sysfs?Quoted 8 lines
When a user updates a running DAMON context via sysfs that includes an existing
DAMOS_QUOTA_SOME_MEM_PSI_USgoal, this overwrites the running goal'slast_psi_totalwith the current time's PSI value, without resetting the overallcharged_frominterval timer.Could this produce an artificially small
current_value, causing the feedback loop tuner to falsely assume memory pressure is low and erroneously increase the scheme's quota?When the entire context is committed,
damos->next_apply_sisis also updated, so this problem doesn't happen. However, we allowcommit_schemes_quota_goalssysfs command to directly commit goals. In the case, this issue can happen.
Quoted 6 lines
We could handle the corner case. But I start feeling this is adding too much complexity for the small bug. As also mentioned on the original commit message, the impact is transient and minor. Users can also set additional quotas or quota goals as guardrails. I will keep the original behavior as is, and just add comments about it. We can revisit if a real user gets real problem from the documented behavior.
While writing the documentation I found myself don't really like this random behavior. Another solution is initializing the field as UINT64_MAX at new quota goal creation (damos_new_quota_goal()). When the ->current_value for the goal is calculated in damos_set_quota_goal_current_value(), it can check the UINT64_MAX case and set the current value same to target value, so that this tuning round make no change to the tuned quota. The last_psi_total will be updated to real value and make effect from the next round.
damos_commit_quota_goal_union() will also be updated to set the destination goal's last_psi_total to the source goal's value. Let's assume the source was made with damos_new_quota_goal() and the last_psi_total field is not modified. It should be a safe assumption since normal API callers are supposed to use damos_new_quota_goal(), and don't reuse a goal that were updated by kdamond. So the next round tuning will be skipped, but works without unexpected effect from the next round. If the destination goal was the PSI goal, this makes the goal to skip next round auto-tuning for no good reason. But that should be fine. DAMOS auto-tuning is basically for long term best-effort, not short-term fully deterministic control.
Quoted 27 lines
Quoted 27 lines
Quoted 5 lines
mm/damon/core.c +0
-0case DAMOS_QUOTA_NODE_MEM_USED_BP :case DAMOS_QUOTA_NODE_MEM_FREE_BP : dst->nid = src->nid;[ ... ]
mm/damon/core.c static void damos_commit_quota_goal( · line 1152
Quoted 7 lines
mm/damon/core.c +0
-1@@ -1143,7 +1148,6 @@ static void damos_commit_quota_goal( dst->target_value = src->target_value;if (dst->metric =DAMOS_QUOTA_USER_INPUT ) dst->current_value = src->current_value; -/* keep last_psi_total as is, since it will be updated in next cycle */ damos_commit_quota_goal_union (dst, src); }[Severity: Medium]
Since the semantics ofdamos_commit_quota_goal()have changed to explicitly overwritelast_psi_totalrather than preserve it, should the corresponding KUnit test be updated as well?The existing KUnit test in
mm/damon/tests/core-kunit.h(damos_test_commit_quota_goal_for()) expects the old preservation behavior:if (
dst_last_psi_total&&src->metric=DAMOS_QUOTA_SOME_MEM_PSI_US)KUNIT_EXPECT_EQ(test, dst->last_psi_total, dst_last_psi_total);
Quoted 6 lines
Quoted 2 lines
Without updating this assertion, there appears to be a mismatch between the new code behavior and what the test expects.
Good catch. I usually run kunit without
CONFIG_PSI, so didn't encounter the issue. However, as I'm changing my mind to keep the behavior but just update the documents, this is irrelevant.
So relevant kunit test case may also be updated.
Thanks,
SJ
[...]
SJ Park
maintainerRe: [RFC PATCH v1.1 1/3] mm/damon/core: initialize damos_quota_goal->last_psi_total
Quoted 36 lines · On Thu, 27 Aug 2026 07:50:33 -0700 SJ Park <[email protected]> wrote:
Quoted 1 line · On Thu, 27 Aug 2026 07:17:37 -0700 SJ Park <[email protected]> wrote:
On Thu, 27 Aug 2026 13:59:58 +0000 [email protected] wrote:
[...]
Quoted 17 lines
Quoted 4 lines
[Severity: High]
Does this unconditional reset oflast_psi_totaltruncate the measurement window for running goals that are updated via sysfs?Quoted 8 lines
When a user updates a running DAMON context via sysfs that includes an existing
DAMOS_QUOTA_SOME_MEM_PSI_USgoal, this overwrites the running goal'slast_psi_totalwith the current time's PSI value, without resetting the overallcharged_frominterval timer.Could this produce an artificially small
current_value, causing the feedback loop tuner to falsely assume memory pressure is low and erroneously increase the scheme's quota?When the entire context is committed,
damos->next_apply_sisis also updated, so this problem doesn't happen. However, we allowcommit_schemes_quota_goalssysfs command to directly commit goals. In the case, this issue can happen.Quoted 6 lines
We could handle the corner case. But I start feeling this is adding too much complexity for the small bug. As also mentioned on the original commit message, the impact is transient and minor. Users can also set additional quotas or quota goals as guardrails. I will keep the original behavior as is, and just add comments about it. We can revisit if a real user gets real problem from the documented behavior.
While writing the documentation I found myself don't really like this random behavior. Another solution is initializing the field as
UINT64_MAXat new quota goal creation (damos_new_quota_goal()). When the ->current_value for the goal is calculated indamos_set_quota_goal_current_value(), it can check theUINT64_MAXcase and set the current value same to target value, so that this tuning round make no change to the tuned quota. Thelast_psi_totalwill be updated to real value and make effect from the next round.
Quoted 5 lines
damos_commit_quota_goal_union()will also be updated to set the destination goal'slast_psi_totalto the source goal's value. Let's assume the source was made withdamos_new_quota_goal()and thelast_psi_totalfield is not modified. It should be a safe assumption since normal API callers are supposed to usedamos_new_quota_goal(), and don't reuse a goal that were updated by kdamond.
Maybe a better approach is drop the assumption and always set it to U64_MAX. It may unnecessarily skip one tuning round if the destination was PSI goal. The impact is modest, and make the behavior more deterministic.
Quoted 33 lines
So the next round tuning will be skipped, but works without unexpected effect from the next round. If the destination goal was the PSI goal, this makes the goal to skip next round auto-tuning for no good reason. But that should be fine. DAMOS auto-tuning is basically for long term best-effort, not short-term fully deterministic control.
Quoted 27 lines
Quoted 27 lines
Quoted 5 lines
mm/damon/core.c +0
-0case DAMOS_QUOTA_NODE_MEM_USED_BP :case DAMOS_QUOTA_NODE_MEM_FREE_BP : dst->nid = src->nid;[ ... ]
mm/damon/core.c static void damos_commit_quota_goal( · line 1152
Quoted 7 lines
mm/damon/core.c +0
-1@@ -1143,7 +1148,6 @@ static void damos_commit_quota_goal( dst->target_value = src->target_value;if (dst->metric =DAMOS_QUOTA_USER_INPUT ) dst->current_value = src->current_value; -/* keep last_psi_total as is, since it will be updated in next cycle */ damos_commit_quota_goal_union (dst, src); }[Severity: Medium]
Since the semantics ofdamos_commit_quota_goal()have changed to explicitly overwritelast_psi_totalrather than preserve it, should the corresponding KUnit test be updated as well?The existing KUnit test in
mm/damon/tests/core-kunit.h(damos_test_commit_quota_goal_for()) expects the old preservation behavior:if (
dst_last_psi_total&&src->metric=DAMOS_QUOTA_SOME_MEM_PSI_US)KUNIT_EXPECT_EQ(test, dst->last_psi_total, dst_last_psi_total);
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Without updating this assertion, there appears to be a mismatch between the new code behavior and what the test expects.
Good catch. I usually run kunit without
CONFIG_PSI, so didn't encounter the issue. However, as I'm changing my mind to keep the behavior but just update the documents, this is irrelevant.So relevant kunit test case may also be updated.
And I found the current test is broken. It is not really testing committing PSI goal to PSI goal case. I will fix it, too.
Thanks,
SJ
[...]