All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] DAMON: Fix return value from damos_wmark_metric_value
@ 2024-04-28 15:49 Alex Rusuf
  2024-04-28 16:57 ` SeongJae Park
  2024-04-28 18:41 ` [PATCH v2] mm/damon/core: " Alex Rusuf
  0 siblings, 2 replies; 7+ messages in thread
From: Alex Rusuf @ 2024-04-28 15:49 UTC (permalink / raw)
  To: damon; +Cc: sj

Signed-off-by: Alex Rusuf <yorha.op@gmail.com>
---
 mm/damon/core.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 6d503c1c125e..994ccd272555 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -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_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,10 @@ static unsigned long damos_wmark_wait_us(struct damos *scheme)
 {
 	unsigned long metric;
 
-	if (scheme->wmarks.metric == DAMOS_WMARK_NONE)
+	if (scheme->wmarks.metric == DAMOS_WMARK_NONE ||
+	    damos_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.42.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] DAMON: Fix return value from damos_wmark_metric_value
  2024-04-28 15:49 [PATCH] DAMON: Fix return value from damos_wmark_metric_value Alex Rusuf
@ 2024-04-28 16:57 ` SeongJae Park
  2024-04-28 18:46   ` Kirito Asuna
  2024-04-28 18:41 ` [PATCH v2] mm/damon/core: " Alex Rusuf
  1 sibling, 1 reply; 7+ messages in thread
From: SeongJae Park @ 2024-04-28 16:57 UTC (permalink / raw)
  To: Alex Rusuf; +Cc: SeongJae Park, damon

Hi Alex,


Thank you for this patch!  I have a few comments below.

For the consistency, could you please use 'mm/damon/core:' as the patch subject
prefix instead of 'DAMON:'?

On Sun, 28 Apr 2024 18:49:33 +0300 Alex Rusuf <yorha.op@gmail.com> wrote:

> Signed-off-by: Alex Rusuf <yorha.op@gmail.com>

Could you pleae add more detailed explanation about this patch, including why
the return value is wrong?

And, I think we would better to add below tags?

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

> ---
>  mm/damon/core.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index 6d503c1c125e..994ccd272555 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -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_wmark_metric_value(enum damos_wmark_metric metric,
> +				    unsigned long *metric_value)

Because the return value is no more the metric value, what about renaming this
function to, say, 'damos_get_wmark_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,10 @@ static unsigned long damos_wmark_wait_us(struct damos *scheme)
>  {
>  	unsigned long metric;
>  
> -	if (scheme->wmarks.metric == DAMOS_WMARK_NONE)
> +	if (scheme->wmarks.metric == DAMOS_WMARK_NONE ||
> +	    damos_wmark_metric_value(scheme->wmarks.metric, &metric))
>  		return 0;

DAMOS_WMARK_NONE check can be handled from damos_wmark_metric_value() function.
Could you please remove the check here?

>  
> -	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.42.0


Thanks,
SJ

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2] mm/damon/core: Fix return value from damos_wmark_metric_value
  2024-04-28 15:49 [PATCH] DAMON: Fix return value from damos_wmark_metric_value Alex Rusuf
  2024-04-28 16:57 ` SeongJae Park
@ 2024-04-28 18:41 ` Alex Rusuf
  2024-04-28 18:57   ` SeongJae Park
  1 sibling, 1 reply; 7+ messages in thread
From: Alex Rusuf @ 2024-04-28 18:41 UTC (permalink / raw)
  To: damon; +Cc: sj

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>
---
 mm/damon/core.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 6d503c1c125e..53d33b2fa0b9 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1480,12 +1480,17 @@ 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)
 {
+	if (metric == DAMOS_WMARK_NONE)
+		return -EINVAL;
+
 	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 +1505,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.42.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] DAMON: Fix return value from damos_wmark_metric_value
  2024-04-28 16:57 ` SeongJae Park
@ 2024-04-28 18:46   ` Kirito Asuna
  0 siblings, 0 replies; 7+ messages in thread
From: Kirito Asuna @ 2024-04-28 18:46 UTC (permalink / raw)
  To: sj; +Cc: damon, yorha.op

SJ,

thank you for your comments, I tried to address them in the v2 patch 
(https://lore.kernel.org/damon/20240428184159.188535-1-yorha.op@gmail.com/)


BR,

Alex


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] mm/damon/core: Fix return value from damos_wmark_metric_value
  2024-04-28 18:41 ` [PATCH v2] mm/damon/core: " Alex Rusuf
@ 2024-04-28 18:57   ` SeongJae Park
  2024-04-28 19:17     ` Alex Rusuf
  0 siblings, 1 reply; 7+ messages in thread
From: SeongJae Park @ 2024-04-28 18:57 UTC (permalink / raw)
  To: Alex Rusuf; +Cc: SeongJae Park, damon

Hi Alex,

On Sun, 28 Apr 2024 21:41:59 +0300 Alex Rusuf <yorha.op@gmail.com> 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")
> Signed-off-by: Alex Rusuf <yorha.op@gmail.com>
> ---

We usually post new revisions of patches as new thread, instead of reply to
previous revision.  If you want to kindly letting reviewers understand the
revision history of the patch, you could put the summary of the changes in each
revisions here[1].

[1] https://www.kernel.org/doc/html/v4.17/process/submitting-patches.html#the-canonical-patch-format

>  mm/damon/core.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index 6d503c1c125e..53d33b2fa0b9 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -1480,12 +1480,17 @@ 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)
>  {
> +	if (metric == DAMOS_WMARK_NONE)
> +		return -EINVAL;
> +

Below switch-case will handle this case too.  How about removing this if
statement?

>  	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 +1505,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.42.0


Thanks,
SJ

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] mm/damon/core: Fix return value from damos_wmark_metric_value
  2024-04-28 18:57   ` SeongJae Park
@ 2024-04-28 19:17     ` Alex Rusuf
  2024-04-28 19:36       ` SeongJae Park
  0 siblings, 1 reply; 7+ messages in thread
From: Alex Rusuf @ 2024-04-28 19:17 UTC (permalink / raw)
  To: sj; +Cc: damon, yorha.op

SJ,

thank you again for your comments, I'm not very familiar with sending 
patches here, so I'll try my best, thank you again!

BR,

Alex


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] mm/damon/core: Fix return value from damos_wmark_metric_value
  2024-04-28 19:17     ` Alex Rusuf
@ 2024-04-28 19:36       ` SeongJae Park
  0 siblings, 0 replies; 7+ messages in thread
From: SeongJae Park @ 2024-04-28 19:36 UTC (permalink / raw)
  To: Alex Rusuf; +Cc: SeongJae Park, damon

Hi Alex,

On Sun, 28 Apr 2024 22:17:26 +0300 Alex Rusuf <yorha.op@gmail.com> wrote:

> SJ,
> 
> thank you again for your comments, I'm not very familiar with sending 
> patches here, so I'll try my best, thank you again!

No problem at all.  Nobody is familiar with the process from the beginning, and
you're doing great.  I'm happy to help you. :)

I'll also try my best for making the process easier.


Thanks,
SJ

> 
> BR,
> 
> Alex

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-04-28 19:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-28 15:49 [PATCH] DAMON: Fix return value from damos_wmark_metric_value Alex Rusuf
2024-04-28 16:57 ` SeongJae Park
2024-04-28 18:46   ` Kirito Asuna
2024-04-28 18:41 ` [PATCH v2] mm/damon/core: " Alex Rusuf
2024-04-28 18:57   ` SeongJae Park
2024-04-28 19:17     ` Alex Rusuf
2024-04-28 19:36       ` SeongJae Park

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.