Skip to contentSkip to conversation

FAILED: patch "[PATCH] mm/damon/core: disallow time-quota setting zero esz" failed to apply to 6.18-stable tree

PATCH Superseded [email protected] 3 participants 7 messages May 3 – May 7

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x 8bbde987c2b84f80da0853f739f0a920386f8b99
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026050306-june-passerby-c0a0@gregkh' --subject-prefix 'PATCH 6.18.y' HEAD^..

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 8bbde987c2b84f80da0853f739f0a920386f8b99 Mon Sep 17 00:00:00 2001
From: SeongJae Park <[email protected]>
Date: Mon, 6 Apr 2026 17:31:52 -0700
Subject: [PATCH] mm/damon/core: disallow time-quota setting zero esz

When the throughput of a DAMOS scheme is very slow, DAMOS time quota can make the effective size quota smaller than damon_ctx->min_region_sz. In the case, damos_apply_scheme() will skip applying the action, because the action is tried at region level, which requires >=min_region_sz size. That is, the quota is effectively exceeded for the quota charge window.

Because no action will be applied, the total_charged_sz and total_charged_ns are also not updated. damos_set_effective_quota() will try to update the effective size quota before starting the next charge window. However, because the total_charged_sz and total_charged_ns have not updated, the throughput and effective size quota are also not changed. Since effective size quota can only be decreased, other effective size quota update factors including DAMOS quota goals and size quota cannot make any change, either.

As a result, the scheme is unexpectedly deactivated until the user notices and mitigates the situation. The users can mitigate this situation by changing the time quota online or re-install the scheme. While the mitigation is somewhat straightforward, finding the situation would be challenging, because DAMON is not providing good observabilities for that. Even if such observability is provided, doing the additional monitoring and the mitigation is somewhat cumbersome and not aligned to the intention of the time quota. The time quota was intended to help reduce the user's administration overhead.

Fix the problem by setting time quota-modified effective size quota be at least min_region_sz always.

The issue was discovered [1] by sashiko.

mm/damon/core.c +5 -3
index 3e1890d64d06..3703f62a876b 100644
@@ -2228,7 +2228,8 @@ static unsigned long damos_quota_score(struct damos_quota *quota)
 /*
  * Called only if quota->ms, or quota->sz are set, or quota->goals is not empty
  */
-static void damos_set_effective_quota(struct damos_quota *quota)
+static void damos_set_effective_quota(struct damos_quota *quota,
+		struct damon_ctx *ctx)
 {
 	unsigned long throughput;
 	unsigned long esz = ULONG_MAX;
@@ -2254,6 +2255,7 @@ static void damos_set_effective_quota(struct damos_quota *quota)
 		else
 			throughput = PAGE_SIZE * 1024;
 		esz = min(throughput * quota->ms, esz);
+		esz = max(ctx->min_region_sz, esz);
 	}
 
 	if (quota->sz && quota->sz < esz)
@@ -2290,7 +2292,7 @@ static void damos_adjust_quota(struct damon_ctx *c, struct damos *s)
 	/* First charge window */
 	if (!quota->total_charged_sz && !quota->charged_from) {
 		quota->charged_from = jiffies;
-		damos_set_effective_quota(quota);
+		damos_set_effective_quota(quota, c);
 	}
 
 	/* New charge window starts */
@@ -2303,7 +2305,7 @@ static void damos_adjust_quota(struct damon_ctx *c, struct damos *s)
 		quota->charged_sz = 0;
 		if (trace_damos_esz_enabled())
 			cached_esz = quota->esz;
-		damos_set_effective_quota(quota);
+		damos_set_effective_quota(quota, c);
 		if (trace_damos_esz_enabled() && quota->esz != cached_esz)
 			damos_trace_esz(c, s, quota);
 	}
maintainer
#1 lore raw

PATCH 1/1 mm/damon/core: disallow time-quota setting zero esz

When the throughput of a DAMOS scheme is very slow, DAMOS time quota can make the effective size quota smaller than damon_ctx->min_region_sz. In the case, damos_apply_scheme() will skip applying the action, because the action is tried at region level, which requires >=min_region_sz size. That is, the quota is effectively exceeded for the quota charge window.

Because no action will be applied, the total_charged_sz and total_charged_ns are also not updated. damos_set_effective_quota() will try to update the effective size quota before starting the next charge window. However, because the total_charged_sz and total_charged_ns have not updated, the throughput and effective size quota are also not changed. Since effective size quota can only be decreased, other effective size quota update factors including DAMOS quota goals and size quota cannot make any change, either.

As a result, the scheme is unexpectedly deactivated until the user notices and mitigates the situation. The users can mitigate this situation by changing the time quota online or re-install the scheme. While the mitigation is somewhat straightforward, finding the situation would be challenging, because DAMON is not providing good observabilities for that. Even if such observability is provided, doing the additional monitoring and the mitigation is somewhat cumbersome and not aligned to the intention of the time quota. The time quota was intended to help reduce the user's administration overhead.

Fix the problem by setting time quota-modified effective size quota be at least min_region_sz always.

The issue was discovered [1] by sashiko.

Fixes 1cd243030059 ("mm/damon/schemes: implement time quota")
Cc <[email protected]> # 5.16.x
(cherry picked from commit 8bbde987c2b84f80da0853f739f0a920386f8b99)
---
 mm/damon/core.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
mm/damon/core.c +5 -3
index 87b6c9c2d647..952cc770edf7 100644
@@ -2124,7 +2124,8 @@ static unsigned long damos_quota_score(struct damos_quota *quota)
 /*
  * Called only if quota->ms, or quota->sz are set, or quota->goals is not empty
  */
-static void damos_set_effective_quota(struct damos_quota *quota)
+static void damos_set_effective_quota(struct damos_quota *quota,
+		struct damon_ctx *ctx)
 {
 	unsigned long throughput;
 	unsigned long esz = ULONG_MAX;
@@ -2150,6 +2151,7 @@ static void damos_set_effective_quota(struct damos_quota *quota)
 		else
 			throughput = PAGE_SIZE * 1024;
 		esz = min(throughput * quota->ms, esz);
+		esz = max(DAMON_MIN_REGION, esz);
 	}
 
 	if (quota->sz && quota->sz < esz)
@@ -2186,7 +2188,7 @@ static void damos_adjust_quota(struct damon_ctx *c, struct damos *s)
 	/* First charge window */
 	if (!quota->total_charged_sz && !quota->charged_from) {
 		quota->charged_from = jiffies;
-		damos_set_effective_quota(quota);
+		damos_set_effective_quota(quota, c);
 	}
 
 	/* New charge window starts */
@@ -2199,7 +2201,7 @@ static void damos_adjust_quota(struct damon_ctx *c, struct damos *s)
 		quota->charged_sz = 0;
 		if (trace_damos_esz_enabled())
 			cached_esz = quota->esz;
-		damos_set_effective_quota(quota);
+		damos_set_effective_quota(quota, c);
 		if (trace_damos_esz_enabled() && quota->esz != cached_esz)
 			damos_trace_esz(c, s, quota);
 	}
Signature · 1 line
2.47.3
#2 lore raw

Re: [PATCH 6.18.y] mm/damon/core: disallow time-quota setting zero esz

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The newly added `ctx` parameter in `damos_set_effective_quota()` is unused, and the function…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The newly added ctx parameter in damos_set_effective_quota() is unused, and the function incorrectly uses the DAMON_MIN_REGION macro instead of ctx->min_sz_region. --

commit 8afd735e4c663dcbcca090e71f37ad10c37c705a
Author: SeongJae Park <[email protected]>

mm/damon/core: disallow time-quota setting zero esz

When DAMOS scheme throughput is very slow, the time quota can make the effective size quota smaller than the context's minimum region size, causing actions to be skipped. This commit attempts to fix the problem by ensuring the effective size quota is at least the minimum region size.

Quoted 13 lines
mm/damon/core.c +2 -1
@@ -2124,7 +2124,8 @@ static unsigned long damos_quota_score(struct damos_quota *quota)
 /*
  * Called only if quota->ms, or quota->sz are set, or quota->goals is not empty
  */
-static void damos_set_effective_quota(struct damos_quota *quota)
+static void damos_set_effective_quota(struct damos_quota *quota,
+		struct damon_ctx *ctx)
 {
 	unsigned long throughput;
 	unsigned long esz = ULONG_MAX;

[ ... ]

mm/damon/core.c static void damos_set_effective_quota(struct damos_quota *quota) · line 2154

Quoted 5 lines
mm/damon/core.c +1 -0
@@ -2150,6 +2151,7 @@ static void damos_set_effective_quota(struct damos_quota *quota)
 		else
 			throughput = PAGE_SIZE * 1024;
 		esz = min(throughput * quota->ms, esz);
+		esz = max(DAMON_MIN_REGION, esz);

Should this be using ctx->min_sz_region instead of DAMON_MIN_REGION?

The commit message mentions bounding the effective size quota to damon_ctx->min_region_sz, and the ctx parameter was successfully added to the function signature.

However, the ctx parameter is left unused here and the macro is used as a hardcoded bound instead. Since ctx->min_sz_region can be dynamically configured, can the effective size quota still fall below it with this implementation?

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
maintainer
#3 lore raw

Re: [PATCH 6.18.y] mm/damon/core: disallow time-quota setting zero esz

TL; DR: This patch is broken, please drop. I will send v2 soon, as a reply to this. Please read below for details.

Quoted 41 lines · On Mon, 04 May 2026 17:06:06 +0000 [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The newly added ctx parameter in damos_set_effective_quota() is unused, and the function incorrectly uses the DAMON_MIN_REGION macro instead of ctx->min_sz_region. --

commit 8afd735e4c663dcbcca090e71f37ad10c37c705a
Author: SeongJae Park <[email protected]>

mm/damon/core: disallow time-quota setting zero esz

When DAMOS scheme throughput is very slow, the time quota can make the effective size quota smaller than the context's minimum region size, causing actions to be skipped. This commit attempts to fix the problem by ensuring the effective size quota is at least the minimum region size.

Quoted 13 lines
mm/damon/core.c +2 -1
@@ -2124,7 +2124,8 @@ static unsigned long damos_quota_score(struct damos_quota *quota)
 /*
  * Called only if quota->ms, or quota->sz are set, or quota->goals is not empty
  */
-static void damos_set_effective_quota(struct damos_quota *quota)
+static void damos_set_effective_quota(struct damos_quota *quota,
+		struct damon_ctx *ctx)
 {
 	unsigned long throughput;
 	unsigned long esz = ULONG_MAX;

[ ... ]

mm/damon/core.c static void damos_set_effective_quota(struct damos_quota *quota) · line 2154

Quoted 5 lines
mm/damon/core.c +1 -0
@@ -2150,6 +2151,7 @@ static void damos_set_effective_quota(struct damos_quota *quota)
 		else
 			throughput = PAGE_SIZE * 1024;
 		esz = min(throughput * quota->ms, esz);
+		esz = max(DAMON_MIN_REGION, esz);

Should this be using ctx->min_sz_region instead of DAMON_MIN_REGION?

Quoted 8 lines

The commit message mentions bounding the effective size quota to damon_ctx->min_region_sz, and the ctx parameter was successfully added to the function signature.

However, the ctx parameter is left unused here and the macro is used as a hardcoded bound instead. Since ctx->min_sz_region can be dynamically configured, can the effective size quota still fall below it with this implementation?

Correct. Cherry-picking the original commit was causing build issue since the upstream commit is renamed field (min_region_sz). When fixing the build issue I mistakenly assumed the field itslef is not yet introduced to 6.18 and using DAMON_MIN_REGION. It should use the field that not yet renamed (min_sz_region), as Sashiko pointed out.

Greg, please drop this. I will send a v2 soon, as a reply to this mail.

Quoted 8 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

Thanks,
SJ

maintainer
#4 lore raw

PATCH v2 1/1 mm/damon/core: disallow time-quota setting zero esz

When the throughput of a DAMOS scheme is very slow, DAMOS time quota can make the effective size quota smaller than damon_ctx->min_region_sz. In the case, damos_apply_scheme() will skip applying the action, because the action is tried at region level, which requires >=min_region_sz size. That is, the quota is effectively exceeded for the quota charge window.

Because no action will be applied, the total_charged_sz and total_charged_ns are also not updated. damos_set_effective_quota() will try to update the effective size quota before starting the next charge window. However, because the total_charged_sz and total_charged_ns have not updated, the throughput and effective size quota are also not changed. Since effective size quota can only be decreased, other effective size quota update factors including DAMOS quota goals and size quota cannot make any change, either.

As a result, the scheme is unexpectedly deactivated until the user notices and mitigates the situation. The users can mitigate this situation by changing the time quota online or re-install the scheme. While the mitigation is somewhat straightforward, finding the situation would be challenging, because DAMON is not providing good observabilities for that. Even if such observability is provided, doing the additional monitoring and the mitigation is somewhat cumbersome and not aligned to the intention of the time quota. The time quota was intended to help reduce the user's administration overhead.

Fix the problem by setting time quota-modified effective size quota be at least min_region_sz always.

The issue was discovered [1] by sashiko.

Fixes 1cd243030059 ("mm/damon/schemes: implement time quota")
Cc <[email protected]> # 5.16.x
(cherry picked from commit 8bbde987c2b84f80da0853f739f0a920386f8b99)
---
 mm/damon/core.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
mm/damon/core.c +5 -3
index 87b6c9c2d647..feec1b0c2bab 100644
@@ -2124,7 +2124,8 @@ static unsigned long damos_quota_score(struct damos_quota *quota)
 /*
  * Called only if quota->ms, or quota->sz are set, or quota->goals is not empty
  */
-static void damos_set_effective_quota(struct damos_quota *quota)
+static void damos_set_effective_quota(struct damos_quota *quota,
+		struct damon_ctx *ctx)
 {
 	unsigned long throughput;
 	unsigned long esz = ULONG_MAX;
@@ -2150,6 +2151,7 @@ static void damos_set_effective_quota(struct damos_quota *quota)
 		else
 			throughput = PAGE_SIZE * 1024;
 		esz = min(throughput * quota->ms, esz);
+		esz = max(ctx->min_sz_region, esz);
 	}
 
 	if (quota->sz && quota->sz < esz)
@@ -2186,7 +2188,7 @@ static void damos_adjust_quota(struct damon_ctx *c, struct damos *s)
 	/* First charge window */
 	if (!quota->total_charged_sz && !quota->charged_from) {
 		quota->charged_from = jiffies;
-		damos_set_effective_quota(quota);
+		damos_set_effective_quota(quota, c);
 	}
 
 	/* New charge window starts */
@@ -2199,7 +2201,7 @@ static void damos_adjust_quota(struct damon_ctx *c, struct damos *s)
 		quota->charged_sz = 0;
 		if (trace_damos_esz_enabled())
 			cached_esz = quota->esz;
-		damos_set_effective_quota(quota);
+		damos_set_effective_quota(quota, c);
 		if (trace_damos_esz_enabled() && quota->esz != cached_esz)
 			damos_trace_esz(c, s, quota);
 	}
Signature · 1 line
2.47.3
#5 lore raw

Re: [PATCH 6.18.y v2] mm/damon/core: disallow time-quota setting zero esz

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Incomplete fix: DAMOS scheme can still unexpectedly deactivate if using quota goals without a time…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Incomplete fix: DAMOS scheme can still unexpectedly deactivate if using quota goals without a time quota. --

commit ce7d104c8087fff14fb782b89848659312c204fa
Author: SeongJae Park <[email protected]>
Subject: mm/damon/core: disallow time-quota setting zero esz

This commit addresses an issue where DAMOS time quota can reduce the effective size quota below the minimum region size. This causes no actions to be applied, unexpectedly deactivating the scheme. The fix enforces a lower bound of min_sz_region on the effective size quota when a time quota is used.

Quoted 4 lines
mm/damon/core.c +0 -0
index 87b6c9c2d6471..feec1b0c2babe 100644

[ ... ]

mm/damon/core.c static void damos_set_effective_quota(struct damos_quota *quota) · line 2157

Quoted 8 lines
mm/damon/core.c +1 -0
@@ -2150,6 +2151,7 @@ static void damos_set_effective_quota(struct damos_quota *quota)
 		else
 			throughput = PAGE_SIZE * 1024;
 		esz = min(throughput * quota->ms, esz);
+		esz = max(ctx->min_sz_region, esz);
 	}
 
 	if (quota->sz && quota->sz < esz)

Could this still leave a case where the scheme is unexpectedly deactivated if quota goals are used without a time quota?

If a scheme is configured with quota goals (!list_empty(&quota->goals)) but no time quota (quota->ms == 0), the bounds check added here inside the if (quota->ms) block is bypassed.

When the system metric over-achieves, the feedback loop in damon_feed_loop_next_input() can limit quota->esz_bp to its minimum of 10000, which evaluates to an esz of 1:

	if (!list_empty(&quota->goals)) {
		unsigned long score = damos_quota_score(quota);

		quota->esz_bp = damon_feed_loop_next_input(
				max(quota->esz_bp, 10000UL),
				score);
		esz = quota->esz_bp / 10000;
	}

During scheme application, damos_apply_scheme() calculates the size using ALIGN_DOWN(1 - 0, ctx->min_sz_region). Since min_sz_region is typically PAGE_SIZE, this evaluates to 0 and the action is skipped entirely.

Because the feedback loop increases esz_bp multiplicatively, it would take multiple charge windows for esz to grow from 1 back to min_sz_region after the score drops. During this period, the scheme applies 0 actions despite the score indicating they are needed.

Should the max(ctx->min_sz_region, esz) bound be applied outside the if (quota->ms) block to ensure any auto-tuned esz is properly bounded?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#6 lore raw

Re: [PATCH 6.18.y v2] mm/damon/core: disallow time-quota setting zero esz

Quoted 2 lines · On Wed, 06 May 2026 20:40:45 +0000 [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Incomplete fix: DAMOS scheme can still unexpectedly deactivate if using quota goals without a time quota.

No valid issue. Read below for details, please.

Quoted 49 lines

--

commit ce7d104c8087fff14fb782b89848659312c204fa
Author: SeongJae Park <[email protected]>
Subject: mm/damon/core: disallow time-quota setting zero esz

This commit addresses an issue where DAMOS time quota can reduce the effective size quota below the minimum region size. This causes no actions to be applied, unexpectedly deactivating the scheme. The fix enforces a lower bound of min_sz_region on the effective size quota when a time quota is used.

Quoted 4 lines
mm/damon/core.c +0 -0
index 87b6c9c2d6471..feec1b0c2babe 100644

[ ... ]

mm/damon/core.c static void damos_set_effective_quota(struct damos_quota *quota) · line 2157

Quoted 8 lines
mm/damon/core.c +1 -0
@@ -2150,6 +2151,7 @@ static void damos_set_effective_quota(struct damos_quota *quota)
 		else
 			throughput = PAGE_SIZE * 1024;
 		esz = min(throughput * quota->ms, esz);
+		esz = max(ctx->min_sz_region, esz);
 	}
 
 	if (quota->sz && quota->sz < esz)

Could this still leave a case where the scheme is unexpectedly deactivated if quota goals are used without a time quota?

If a scheme is configured with quota goals (!list_empty(&quota->goals)) but no time quota (quota->ms == 0), the bounds check added here inside the if (quota->ms) block is bypassed.

When the system metric over-achieves, the feedback loop in damon_feed_loop_next_input() can limit quota->esz_bp to its minimum of 10000, which evaluates to an esz of 1:

	if (!list_empty(&quota->goals)) {
		unsigned long score = damos_quota_score(quota);

		quota->esz_bp = damon_feed_loop_next_input(
				max(quota->esz_bp, 10000UL),
				score);
		esz = quota->esz_bp / 10000;
	}
Quoted 8 lines

During scheme application, damos_apply_scheme() calculates the size using ALIGN_DOWN(1 - 0, ctx->min_sz_region). Since min_sz_region is typically PAGE_SIZE, this evaluates to 0 and the action is skipped entirely.

Because the feedback loop increases esz_bp multiplicatively, it would take multiple charge windows for esz to grow from 1 back to min_sz_region after the score drops. During this period, the scheme applies 0 actions despite the score indicating they are needed.

Yes, and this is the intended behavior.

Quoted 3 lines

Should the max(ctx->min_sz_region, esz) bound be applied outside the if (quota->ms) block to ensure any auto-tuned esz is properly bounded?

Because it is an intended behavior, no.

Thanks,
SJ

[...]