Skip to contentSkip to conversation

mm/damon/core: fix quota could not be set to zero

PATCH In review Liew Rui Yan 3 participants 4 messages Sep 1 – Sep 2

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/damon/core: fix quota could not be set to zero

When the temporal quota goal tuner determines that the goal has been achieved (score >= 10000), it sets esz_bp to zero so that the effective quota becomes error. However, damos_set_effective_quota() unconditionally clamps the quota to min_region_sz, preventing the quota from ever reaching zero.

Fix this by skip the min_region_sz clamping when esz is already zero so that the temporal tuner's intent is respected.

Fixes 8bbde987c2b8 ("mm/damon/core: disallow time-quota setting zero esz")
Cc <[email protected]> # v7.1.x
---
 mm/damon/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/damon/core.c +2 -1
index 53cf32f1d515..0258769b8727 100644
@@ -3114,7 +3114,8 @@ static void damos_set_effective_quota(struct damon_ctx *ctx, struct damos *s)
 		else
 			throughput = PAGE_SIZE * 1024;
 		esz = min(throughput * quota->ms, esz);
-		esz = max(ctx->min_region_sz, esz);
+		if (esz)
+			esz = max(ctx->min_region_sz, esz);
 	}
 
 	if (quota->sz && quota->sz < esz)
Signature · 1 line
2.55.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] The patch places the `if (esz)` check after the throughput calculation, inadvertently reverting a…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The patch places the if (esz) check after the throughput calculation, inadvertently reverting a previous fix (commit 8bbde987c2b8) and causing schemes with low throughput to permanently deactivate. --

commit a1511f591a76665e55c325a03d3d47bf4ba87dc6
Author: Liew Rui Yan <[email protected]>

mm/damon/core: fix quota could not be set to zero

This commit modifies the damos quota setting logic to skip clamping to min_region_sz when the effective size quota is already zero. This is intended to allow the temporal tuner's zero quota goal to be respected.

mm/damon/core.c static void damos_set_effective_quota(struct damon_ctx *ctx, struct damos *s) · line 3126

Quoted 11 lines
mm/damon/core.c +2 -1
index 3f89cfdf5f022..fdec7c0fe913a 100644
@@ -3122,7 +3122,8 @@ static void damos_set_effective_quota(struct damon_ctx *ctx, struct damos *s)
 		else
 			throughput = PAGE_SIZE * 1024;
 		esz = min(throughput * quota->ms, esz);
-		esz = max(ctx->min_region_sz, esz);
+		if (esz)
+			esz = max(ctx->min_region_sz, esz);

[Severity: High]
Does placing the if (esz) check after the throughput calculation inadvertently revert the fix from commit 8bbde987c2b8 and cause a regression where slow schemes permanently deactivate?

If a damos scheme with a time quota processes regions slowly, integer division can cause throughput to truncate to 0. When this happens, the calculation esz = min(throughput * quota->ms, esz) evaluates to 0.

Because the new if (esz) check is placed after this min() calculation, the 0 value causes the check to fail, skipping the max(ctx->min_region_sz, esz) clamp.

With esz == 0, damos_quota_is_full() always returns true, bypassing all scheme operations. Since no regions are processed, total_charged_ns and total_charged_sz are never updated. This leaves throughput permanently at 0, resulting in an unrecoverable starvation loop.

Quoted 3 lines
mm/damon/core.c +0 -0
 	}
 
 	if (quota->sz && quota->sz < esz)
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
Quoted 34 lines · On Tue, 01 Sep 2026 11:14:40 +0000 [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The patch places the if (esz) check after the throughput calculation, inadvertently reverting a previous fix (commit 8bbde987c2b8) and causing schemes with low throughput to permanently deactivate. --

commit a1511f591a76665e55c325a03d3d47bf4ba87dc6
Author: Liew Rui Yan <[email protected]>

mm/damon/core: fix quota could not be set to zero

This commit modifies the damos quota setting logic to skip clamping to min_region_sz when the effective size quota is already zero. This is intended to allow the temporal tuner's zero quota goal to be respected.

mm/damon/core.c static void damos_set_effective_quota(struct damon_ctx *ctx, struct damos *s) · line 3126

Quoted 11 lines
mm/damon/core.c +2 -1
index 3f89cfdf5f022..fdec7c0fe913a 100644
@@ -3122,7 +3122,8 @@ static void damos_set_effective_quota(struct damon_ctx *ctx, struct damos *s)
 		else
 			throughput = PAGE_SIZE * 1024;
 		esz = min(throughput * quota->ms, esz);
-		esz = max(ctx->min_region_sz, esz);
+		if (esz)
+			esz = max(ctx->min_region_sz, esz);

[Severity: High]
Does placing the if (esz) check after the throughput calculation inadvertently revert the fix from commit 8bbde987c2b8 and cause a regression where slow schemes permanently deactivate?

If a damos scheme with a time quota processes regions slowly, integer division can cause throughput to truncate to 0. When this happens, the calculation esz = min(throughput * quota->ms, esz) evaluates to 0.

Quoted 8 lines

Because the new if (esz) check is placed after this min() calculation, the 0 value causes the check to fail, skipping the max(ctx->min_region_sz, esz) clamp.

With esz == 0, damos_quota_is_full() always returns true, bypassing all scheme operations. Since no regions are processed, total_charged_ns and total_charged_sz are never updated. This leaves throughput permanently at 0, resulting in an unrecoverable starvation loop.

Thank you for pointing out this! Yes, this can happen, and this is what 8bbde987c2b8 was fixing.

damos_goal_tune_esz_bp_temporal() will set quota->esz_bp to zero when goal is archived, so this need fix by adding a check for quota->esz_bp.

'''

mm/damon/core.c +3 -0
index 644daf5a1656..c07ae66caa49 100644
@@ -3118,6 +3118,9 @@ static void damos_set_effective_quota(struct damon_ctx *ctx, struct damos *s)
        if (quota->sz && quota->sz < esz)
                esz = quota->sz;
 
+       if (!quota->esz_bp)
+               esz = quota->esz_bp / 10000;
+
        quota->esz = esz;
 }

'''

I will change this in next revision.

Quoted 7 lines
Quoted 4 lines
mm/damon/core.c +0 -0
 	}
 
 	if (quota->sz && quota->sz < esz)
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1

Best regards,
Rui Yan

maintainer
#3 lore raw
In reply to Liew Rui Yan

Hi Liew,

Seems Sashiko found something and you are planning to revision this patch that. I will hold review until the next version is posted. Same for your other patch that sent in the same time.

Thanks,
SJ

[...]