damon.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH v4] mm/damon/core: Fix return value from damos_wmark_metric_value
@ 2024-05-06 18:02 SeongJae Park
  0 siblings, 0 replies; only message in thread
From: SeongJae Park @ 2024-05-06 18:02 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Alex Rusuf, SeongJae Park, damon, linux-mm, linux-kernel

From: Alex Rusuf <yorha.op@gmail.com>

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")
Signed-off-by: Alex Rusuf <yorha.op@gmail.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
Signed-off-by: SeongJae Park <sj@kernel.org>
---

Changes from v3
(https://lore.kernel.org/20240428191439.194027-1-yorha.op@gmail.com)
- Add Reviewed-by: SeongJae Park <sj@kernel.org>
- Send to Andrew and linux-mm@ for being merged in mm tree

 mm/damon/core.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 939ecfcd4641..6392f1cc97a3 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1481,12 +1481,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;
 	}
@@ -1501,10 +1503,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)
-- 
2.39.2


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-05-06 18:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-06 18:02 [PATCH v4] mm/damon/core: Fix return value from damos_wmark_metric_value SeongJae Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).