Skip to contentSkip to conversation

mm/damon/core: Fix return value from damos_wmark_metric_value

PATCH In review Alex Rusuf 2 participants 2 messages Apr 28, 2024

Subsystems (2)
lore
Share & tools
lore

Alex Rusuf

author
#0 lore raw

PATCH v3 1/1 mm/damon/core: Fix return value from damos_wmark_metric_value

damos_wmark_metric_value's return value is 'unsigned long', so returning -EINVAL as 'unsigned long' may turn out to be very different from the expected one (using 2's complement) and treat as usual matric's value. So, fix that, checking if returned value is not 0.

Fixes ee801b7dd782 ("mm/damon/schemes: activate schemes based on a watermarks mechanism")
---
 mm/damon/core.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
mm/damon/core.c +5 -4
index 6d503c1c125e..172095e68c5d 100644
@@ -1480,12 +1480,14 @@ static bool kdamond_need_stop(struct damon_ctx *ctx)
 	return true;
 }
 
-static unsigned long damos_wmark_metric_value(enum damos_wmark_metric metric)
+static int damos_get_wmark_metric_value(enum damos_wmark_metric metric,
+					unsigned long *metric_value)
 {
 	switch (metric) {
 	case DAMOS_WMARK_FREE_MEM_RATE:
-		return global_zone_page_state(NR_FREE_PAGES) * 1000 /
+		*metric_value = global_zone_page_state(NR_FREE_PAGES) * 1000 /
 		       totalram_pages();
+		return 0;
 	default:
 		break;
 	}
@@ -1500,10 +1502,9 @@ static unsigned long damos_wmark_wait_us(struct damos *scheme)
 {
 	unsigned long metric;
 
-	if (scheme->wmarks.metric == DAMOS_WMARK_NONE)
+	if (damos_get_wmark_metric_value(scheme->wmarks.metric, &metric))
 		return 0;
 
-	metric = damos_wmark_metric_value(scheme->wmarks.metric);
 	/* higher than high watermark or lower than low watermark */
 	if (metric > scheme->wmarks.high || scheme->wmarks.low > metric) {
 		if (scheme->wmarks.activated)
Signature · 1 line
2.42.0
maintainer Reviewed-by on v3 1/1
#1 lore raw

Hi Alex,

Quoted 8 lines · On Sun, 28 Apr 2024 22:14:39 +0300 Alex Rusuf <[email protected]> wrote:

damos_wmark_metric_value's return value is 'unsigned long', so returning -EINVAL as 'unsigned long' may turn out to be very different from the expected one (using 2's complement) and treat as usual matric's value. So, fix that, checking if returned value is not 0.

Fixes ee801b7dd782 ("mm/damon/schemes: activate schemes based on a watermarks mechanism")

Thank you for patiently revisioning the patch!

Thanks,
SJ

[...]