mm/damon/core: always return false when esz is zero
Subsystems (3)
PATCH 1/1 mm/damon/core: always return false when esz is zero
After setting goal_tuner to 'temporal', if the goal is achieved, quota->esz will be set to zero. In this case, damos_quota_is_full() will always return true, even if no regions have been tried at all. This causes qt_exceeds to increase unexpectedly.
Fix it by always returning false when quota->esz is zero.
--- mm/damon/core.c | 2 ++ 1 file changed, 2 insertions(+)
mm/damon/core.c +2 -0
@@ -2560,6 +2560,8 @@ static bool damos_quota_is_full(struct damos_quota *quota, {if (!damos_quota_is_set (quota))return false; +if (!quota->esz) +return false;if (quota->charged_sz >= quota->esz)return true;/*
Signature · 1 line
2.55.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The patch breaks the O(1) early bailout for schemes with a zero quota, causing O(N) evaluation…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The patch breaks the O(1) early bailout for schemes with a zero quota, causing O(N) evaluation of all regions, significant CPU overhead, and corruption of the 'nr_tried' statistic. --
commit dd8f74f4c9d96719d46a1466acabcc4d814aadc9
Author: Liew Rui Yan <[email protected]>
mm/damon/core: always return false when esz is zero
This patch modifies damos_quota_is_full() to return false when the effective quota size (esz) is zero. This prevents qt_exceeds from increasing unexpectedly when a temporal goal tuner achieves its target and sets the quota to zero.
mm/damon/core.c static bool damos_quota_is_full(struct damos_quota *quota, · line 2555
Quoted 10 lines
mm/damon/core.c +2
-0@@ -2551,6 +2551,8 @@ static bool damos_quota_is_full(struct damos_quota *quota, {if (!damos_quota_is_set (quota))return false; +if (!quota->esz) +return false;
[Severity: Medium]
When a scheme's goal tuner achieves its target and sets the quota to zero, does returning false here unintentionally break the early bailout in damon_do_apply_schemes()?
When this function returned true, damon_do_apply_schemes() used it to skip the scheme entirely:
mm/damon/core.c:damon_do_apply_schemes() {
...
/* Check the quota */
if (damos_quota_is_full(quota, c->min_region_sz))
continue;
...
}If it now returns false when esz is 0, doesn't that cause the loop to evaluate every region via damos_valid_target() and damos_apply_scheme() instead of skipping the scheme?
If the scheme is not skipped, it appears damos_apply_scheme() will calculate a zero sz and jump to update_stat:
mm/damon/core.c:damos_apply_scheme() {
...
if (damos_quota_is_set(quota) &&
quota->charged_sz + sz > quota->esz) {
sz = ALIGN_DOWN(quota->esz - quota->charged_sz,
c->min_region_sz);
if (!sz)
goto update_stat;
...
update_stat:
damos_update_stat(s, sz, sz_applied, sz_ops_filter_passed);
}Will this cause s->stat.nr_tried to be incorrectly incremented in damos_update_stat() for every bypassed region?
Quoted 2 lines
mm/damon/core.c +0
-0if (quota->charged_sz >= quota->esz)return true;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 61 lines · On Tue, 01 Sep 2026 11:12:47 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The patch breaks the O(1) early bailout for schemes with a zero quota, causing O(N) evaluation of all regions, significant CPU overhead, and corruption of the 'nr_tried' statistic. --commit
dd8f74f4c9d96719d46a1466acabcc4d814aadc9
Author: Liew Rui Yan <[email protected]>
mm/damon/core: always return false when esz is zeroThis patch modifies
damos_quota_is_full()to return false when the effective quota size (esz) is zero. This preventsqt_exceedsfrom increasing unexpectedly when a temporal goal tuner achieves its target and sets the quota to zero.mm/damon/core.c static bool damos_quota_is_full(struct damos_quota *quota, · line 2555
Quoted 10 lines
mm/damon/core.c +2
-0@@ -2551,6 +2551,8 @@ static bool damos_quota_is_full(struct damos_quota *quota, {if (!damos_quota_is_set (quota))return false; +if (!quota->esz) +return false;[Severity: Medium]
When a scheme's goal tuner achieves its target and sets the quota to zero, does returning false here unintentionally break the early bailout indamon_do_apply_schemes()?When this function returned true,
damon_do_apply_schemes()used it to skip the scheme entirely:mm/damon/core.c:damon_do_apply_schemes() { ... /* Check the quota */ if (damos_quota_is_full(quota, c->min_region_sz)) continue; ... }If it now returns false when esz is 0, doesn't that cause the loop to evaluate every region via
damos_valid_target()anddamos_apply_scheme()instead of skipping the scheme?If the scheme is not skipped, it appears
damos_apply_scheme()will calculate a zero sz and jump toupdate_stat:mm/damon/core.c:damos_apply_scheme() { ... if (damos_quota_is_set(quota) && quota->charged_sz + sz > quota->esz) { sz = ALIGN_DOWN(quota->esz - quota->charged_sz, c->min_region_sz); if (!sz) goto update_stat; ... update_stat: damos_update_stat(s, sz, sz_applied, sz_ops_filter_passed); }
Quoted 2 lines
Will this cause
s->stat.nr_triedto be incorrectly incremented indamos_update_stat()for every bypassed region?
Thank you for pointing this out!
This can fixed by adding a check before damos_quota_is_set().
'''
mm/damon/core.c +5 -0
@@ -2560,6 +2560,8 @@ static bool damos_quota_is_full(struct damos_quota *quota, {if (!damos_quota_is_set (quota))return false; +if (!quota->charged_sz) +return false;if (quota->charged_sz >= quota->esz)return true;/*
@@ -2654,6 +2656,9 @@ static void damon_do_apply_schemes(struct damon_ctx *c,if (!s->wmarks.activated)continue ; +if (!quota->esz) +continue ; +/* Check the quota */ if (damos_quota_is_full (quota, c->min_region_sz))continue ;
'''
Note that this also changes the implementation of this patch, because quota->esz is an upper-bound, while quota->charged_sz represents the actual quota usage.
Quoted 6 lines
Quoted 3 lines
mm/damon/core.c +0
-0if (quota->charged_sz >= quota->esz)return true;Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Best regards,
Rui Yan