Skip to contentSkip to conversation

mm/damon/core: simplify minimum watermark wait time calculation

PATCH In review Adrian Huang (Lenovo) 3 participants 4 messages Nov 10 – Nov 11

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

PATCH 1/1 mm/damon/core: simplify minimum watermark wait time calculation

The minimum watermark wait time calculation uses an additional boolean variable, init_wait_time, to determine whether min_wait_time has been initialized.

Simplify the logic by using list_is_first() to identify the first scheme and initialize min_wait_time accordingly. Subsequent schemes update min_wait_time only when their waiting intervals are shorter.

This removes the unnecessary boolean variable while preserving the existing behavior, including the case where no schemes are configured.

---
 mm/damon/core.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
mm/damon/core.c +2 -4
index d36823f4d092..93ec684a113c 100644
@@ -3985,14 +3985,12 @@ static int kdamond_wait_activation(struct damon_ctx *ctx)
 
 	while (!kdamond_need_stop(ctx)) {
 		unsigned long min_wait_time = 0;
-		bool init_wait_time = false;
 
 		damon_for_each_scheme(s, ctx) {
 			wait_time = damos_wmark_wait_us(s);
-			if (!init_wait_time || wait_time < min_wait_time) {
-				init_wait_time = true;
+			if (list_is_first(&s->list, &ctx->schemes) ||
+			    wait_time < min_wait_time)
 				min_wait_time = wait_time;
-			}
 		}
 		if (!min_wait_time)
 			return 0;
Signature · 1 line
2.43.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines

The minimum watermark wait time calculation uses an additional boolean variable, init_wait_time, to determine whether min_wait_time has been initialized.

Quoted 8 lines

Simplify the logic by using list_is_first() to identify the first scheme and initialize min_wait_time accordingly. Subsequent schemes update min_wait_time only when their waiting intervals are shorter.

This removes the unnecessary boolean variable while preserving the existing behavior, including the case where no schemes are configured.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#2 lore raw
In reply to Adrian Huang (Lenovo)

Hello Adrian,

Quoted 24 lines · On Tue, 10 Nov 2026 16:51:32 +0800 "Adrian Huang (Lenovo)"…

The minimum watermark wait time calculation uses an additional boolean variable, init_wait_time, to determine whether min_wait_time has been initialized.

Simplify the logic by using list_is_first() to identify the first scheme and initialize min_wait_time accordingly. Subsequent schemes update min_wait_time only when their waiting intervals are shorter.

This removes the unnecessary boolean variable while preserving the existing behavior, including the case where no schemes are configured.

---
 mm/damon/core.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
mm/damon/core.c +0 -0
index d36823f4d092..93ec684a113c 100644
@@ -3985,14 +3985,12 @@ static int kdamond_wait_activation(struct damon_ctx *ctx)
 
 	while (!kdamond_need_stop(ctx)) {
 		unsigned long min_wait_time = 0;

mm/damon/core.c static int kdamond_wait_activation(struct damon_ctx *ctx) · line 3995

Quoted 10 lines
mm/damon/core.c +2 -4
-		bool init_wait_time = false;
 
 		damon_for_each_scheme(s, ctx) {
 			wait_time = damos_wmark_wait_us(s);
-			if (!init_wait_time || wait_time < min_wait_time) {
-				init_wait_time = true;
+			if (list_is_first(&s->list, &ctx->schemes) ||
+			    wait_time < min_wait_time)
 				min_wait_time = wait_time;
-			}

I implemented and used list handling wrappers like damon_for_each_scheme(), to hide implementation details of data structures. This change exposes some of such details. If we agree we have to remove init_wait_time, I'd prefer adding a sort of damon_first_scheme() like wrapper.

But, init_wait_time really need to be removed? I cannot show clear benefit of removing it that justifies adding a new wrapper. To someone or on some evironments, init_wait_time might making the code too difficult to read or inefficient (system having so small amount of memory?), though. If not, I'd suggest dropping this.

What do you think, Adrian?

Thanks,
SJ

[...]

#3 lore raw

Hi SJ,

Quoted 31 lines · SJ Park

Hello Adrian,

Quoted 26 lines · On Tue, 10 Nov 2026 16:51:32 +0800 "Adrian Huang (Lenovo)"…

The minimum watermark wait time calculation uses an additional boolean variable, init_wait_time, to determine whether min_wait_time has been initialized.

Simplify the logic by using list_is_first() to identify the first scheme and initialize min_wait_time accordingly. Subsequent schemes update min_wait_time only when their waiting intervals are shorter.

This removes the unnecessary boolean variable while preserving the existing behavior, including the case where no schemes are configured.

---
 mm/damon/core.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
mm/damon/core.c +0 -1
index d36823f4d092..93ec684a113c 100644
@@ -3985,14 +3985,12 @@ static int kdamond_wait_activation(struct damon_ctx *ctx)
 
      while (!kdamond_need_stop(ctx)) {
              unsigned long min_wait_time = 0;
-             bool init_wait_time = false;
 
Quoted 13 lines

mm/damon/core.c static int kdamond_wait_activation(struct damon_ctx *ctx) · line 3995

Quoted 8 lines
mm/damon/core.c +2 -3
              damon_for_each_scheme(s, ctx) {
                      wait_time = damos_wmark_wait_us(s);
-                     if (!init_wait_time || wait_time < min_wait_time) {
-                             init_wait_time = true;
+                     if (list_is_first(&s->list, &ctx->schemes) ||
+                         wait_time < min_wait_time)
                              min_wait_time = wait_time;
-                     }

I implemented and used list handling wrappers like damon_for_each_scheme(), to hide implementation details of data structures. This change exposes some of such details. If we agree we have to remove init_wait_time, I'd prefer adding a sort of damon_first_scheme() like wrapper.

Ah, sorry. I didn't realize you intentionally hid the implementation details. That makes sense.

Quoted 7 lines

But, init_wait_time really need to be removed? I cannot show clear benefit of removing it that justifies adding a new wrapper. To someone or on some evironments, init_wait_time might making the code too difficult to read or inefficient (system having so small amount of memory?), though. If not, I'd suggest dropping this.

What do you think, Adrian?

I agree with your point. Let's drop this patch. Thanks for the quick feedback anyway. ;-)

-- Adrian