All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/damon/core: Refactor damos_set_effective_quota
@ 2024-11-22  8:18 Honggyu Kim
  2024-11-22 19:29 ` SeongJae Park
  0 siblings, 1 reply; 4+ messages in thread
From: Honggyu Kim @ 2024-11-22  8:18 UTC (permalink / raw)
  To: damon; +Cc: SeongJae Park, kernel_team, Honggyu Kim

The damos_set_effective_quota checks quota contidions but there are some
duplicate checks for quota->goals inside.

This patch reduces one of if statement to simplify the esz calculation
logic.

Signed-off-by: Honggyu Kim <honggyu.kim@sk.com>
---
 mm/damon/core.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 511c3f61ab44..eb2761866dda 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1542,7 +1542,7 @@ static unsigned long damos_quota_score(struct damos_quota *quota)
 static void damos_set_effective_quota(struct damos_quota *quota)
 {
 	unsigned long throughput;
-	unsigned long esz;
+	unsigned long esz = UINT_MAX;
 
 	if (!quota->ms && list_empty(&quota->goals)) {
 		quota->esz = quota->sz;
@@ -1564,10 +1564,7 @@ static void damos_set_effective_quota(struct damos_quota *quota)
 				quota->total_charged_ns;
 		else
 			throughput = PAGE_SIZE * 1024;
-		if (!list_empty(&quota->goals))
-			esz = min(throughput * quota->ms, esz);
-		else
-			esz = throughput * quota->ms;
+		esz = min(throughput * quota->ms, esz);
 	}
 
 	if (quota->sz && quota->sz < esz)
-- 
2.34.1


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

* Re: [PATCH] mm/damon/core: Refactor damos_set_effective_quota
  2024-11-22  8:18 [PATCH] mm/damon/core: Refactor damos_set_effective_quota Honggyu Kim
@ 2024-11-22 19:29 ` SeongJae Park
  2024-11-25  4:49   ` Honggyu Kim
  0 siblings, 1 reply; 4+ messages in thread
From: SeongJae Park @ 2024-11-22 19:29 UTC (permalink / raw)
  To: Honggyu Kim; +Cc: SeongJae Park, damon, kernel_team

Hi Honggyu,


Thank you for this patch.  Definitely DAMON needs many refactoring and
cleanups.

The subject of the patch is a little bit ambiguous to me.  Could we make it
more specific, e.g., "set esz of damos_set_effective_quota() as ULONG_MAX by
default"?

On Fri, 22 Nov 2024 17:18:34 +0900 Honggyu Kim <honggyu.kim@sk.com> wrote:

> The damos_set_effective_quota checks quota contidions but there are some
> duplicate checks for quota->goals inside.

From the above, I was thinking the duplicates should be somewhat unnecessary.
And indeed the function list_empty(&quota->goal) multiple times.  But, that's
not for a unnecessary reason.  We need to know whether 'esz' is set or not.
The check is for that.

> 
> This patch reduces one of if statement to simplify the esz calculation
> logic.

More technically speaking, this patch gives 'esz' a safe default value, and
removes the checks of 'esz' initialization, which is no more necessary owing to
the default value change.

Honggyu, could you please update the subject and message to more clearly
explain the change?

> 
> Signed-off-by: Honggyu Kim <honggyu.kim@sk.com>
> ---
>  mm/damon/core.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index 511c3f61ab44..eb2761866dda 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -1542,7 +1542,7 @@ static unsigned long damos_quota_score(struct damos_quota *quota)
>  static void damos_set_effective_quota(struct damos_quota *quota)
>  {
>  	unsigned long throughput;
> -	unsigned long esz;
> +	unsigned long esz = UINT_MAX;

Let's use ULONG_MAX.

>  
>  	if (!quota->ms && list_empty(&quota->goals)) {
>  		quota->esz = quota->sz;
> @@ -1564,10 +1564,7 @@ static void damos_set_effective_quota(struct damos_quota *quota)
>  				quota->total_charged_ns;
>  		else
>  			throughput = PAGE_SIZE * 1024;
> -		if (!list_empty(&quota->goals))
> -			esz = min(throughput * quota->ms, esz);
> -		else
> -			esz = throughput * quota->ms;
> +		esz = min(throughput * quota->ms, esz);
>  	}
>  
>  	if (quota->sz && quota->sz < esz)
> -- 
> 2.34.1


Thanks,
SJ

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

* Re: [PATCH] mm/damon/core: Refactor damos_set_effective_quota
  2024-11-22 19:29 ` SeongJae Park
@ 2024-11-25  4:49   ` Honggyu Kim
  2024-11-25 18:27     ` SeongJae Park
  0 siblings, 1 reply; 4+ messages in thread
From: Honggyu Kim @ 2024-11-25  4:49 UTC (permalink / raw)
  To: SeongJae Park; +Cc: damon, kernel_team, Honggyu Kim

On Fri, 22 Nov 2024 11:29:26 -0800 SeongJae Park <sj@kernel.org> wrote:
> Hi Honggyu,
> 
> 
> Thank you for this patch.  Definitely DAMON needs many refactoring and
> cleanups.
> 
> The subject of the patch is a little bit ambiguous to me.  Could we make it
> more specific, e.g., "set esz of damos_set_effective_quota() as ULONG_MAX by
> default"?

Hi SeongJae,

Thanks for the review, but IMHO, setting the default value of esz is to remove
one of duplicate if statement, not the goal of this patch.

So I think the following title might be better.

  mm/damon/core: remove duplicate list_empty quota->goals check

Is this okay for you?

> On Fri, 22 Nov 2024 17:18:34 +0900 Honggyu Kim <honggyu.kim@sk.com> wrote:
> 
> > The damos_set_effective_quota checks quota contidions but there are some
> > duplicate checks for quota->goals inside.
> 
> >From the above, I was thinking the duplicates should be somewhat unnecessary.
> And indeed the function list_empty(&quota->goal) multiple times.  But, that's
> not for a unnecessary reason.  We need to know whether 'esz' is set or not.
> The check is for that.
> 
> > 
> > This patch reduces one of if statement to simplify the esz calculation
> > logic.
> 
> More technically speaking, this patch gives 'esz' a safe default value, and
> removes the checks of 'esz' initialization, which is no more necessary owing to
> the default value change.
> 
> Honggyu, could you please update the subject and message to more clearly
> explain the change?
> 
> > 
> > Signed-off-by: Honggyu Kim <honggyu.kim@sk.com>
> > ---
> >  mm/damon/core.c | 7 ++-----
> >  1 file changed, 2 insertions(+), 5 deletions(-)
> > 
> > diff --git a/mm/damon/core.c b/mm/damon/core.c
> > index 511c3f61ab44..eb2761866dda 100644
> > --- a/mm/damon/core.c
> > +++ b/mm/damon/core.c
> > @@ -1542,7 +1542,7 @@ static unsigned long damos_quota_score(struct damos_quota *quota)
> >  static void damos_set_effective_quota(struct damos_quota *quota)
> >  {
> >  	unsigned long throughput;
> > -	unsigned long esz;
> > +	unsigned long esz = UINT_MAX;
> 
> Let's use ULONG_MAX.

Ack. I will apply this and send v2 soon.

Thanks,
Honggyu

> >  
> >  	if (!quota->ms && list_empty(&quota->goals)) {
> >  		quota->esz = quota->sz;
> > @@ -1564,10 +1564,7 @@ static void damos_set_effective_quota(struct damos_quota *quota)
> >  				quota->total_charged_ns;
> >  		else
> >  			throughput = PAGE_SIZE * 1024;
> > -		if (!list_empty(&quota->goals))
> > -			esz = min(throughput * quota->ms, esz);
> > -		else
> > -			esz = throughput * quota->ms;
> > +		esz = min(throughput * quota->ms, esz);
> >  	}
> >  
> >  	if (quota->sz && quota->sz < esz)
> > -- 
> > 2.34.1
> 
> 
> Thanks,
> SJ

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

* Re: [PATCH] mm/damon/core: Refactor damos_set_effective_quota
  2024-11-25  4:49   ` Honggyu Kim
@ 2024-11-25 18:27     ` SeongJae Park
  0 siblings, 0 replies; 4+ messages in thread
From: SeongJae Park @ 2024-11-25 18:27 UTC (permalink / raw)
  To: Honggyu Kim; +Cc: SeongJae Park, damon, kernel_team

On Mon, 25 Nov 2024 13:49:33 +0900 Honggyu Kim <honggyu.kim@sk.com> wrote:

> On Fri, 22 Nov 2024 11:29:26 -0800 SeongJae Park <sj@kernel.org> wrote:
> > Hi Honggyu,
> > 
> > 
> > Thank you for this patch.  Definitely DAMON needs many refactoring and
> > cleanups.
> > 
> > The subject of the patch is a little bit ambiguous to me.  Could we make it
> > more specific, e.g., "set esz of damos_set_effective_quota() as ULONG_MAX by
> > default"?
> 
> Hi SeongJae,
> 
> Thanks for the review, but IMHO, setting the default value of esz is to remove
> one of duplicate if statement, not the goal of this patch.
> 
> So I think the following title might be better.
> 
>   mm/damon/core: remove duplicate list_empty quota->goals check
> 
> Is this okay for you?

Yes, this looks specific and non-ambiguous enough to me.

[...]
> > > --- a/mm/damon/core.c
> > > +++ b/mm/damon/core.c
> > > @@ -1542,7 +1542,7 @@ static unsigned long damos_quota_score(struct damos_quota *quota)
> > >  static void damos_set_effective_quota(struct damos_quota *quota)
> > >  {
> > >  	unsigned long throughput;
> > > -	unsigned long esz;
> > > +	unsigned long esz = UINT_MAX;
> > 
> > Let's use ULONG_MAX.
> 
> Ack. I will apply this and send v2 soon.

Thank you, I will review it soon :)


Thanks,
SJ

[...]

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

end of thread, other threads:[~2024-11-25 18:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-22  8:18 [PATCH] mm/damon/core: Refactor damos_set_effective_quota Honggyu Kim
2024-11-22 19:29 ` SeongJae Park
2024-11-25  4:49   ` Honggyu Kim
2024-11-25 18:27     ` 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.