damon.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: SeongJae Park <sj@kernel.org>
To: FANG2508 <1031576200@qq.com>
Cc: linux-mm@kvack.org, sj@kernel.org, linux-kernel@vger.kernel.org,
	damon@lists.linux.dev
Subject: Re: [PATCH] mm/damon/ops-common.c: Fixup missing parentheses
Date: Thu, 16 Nov 2023 10:58:17 +0000	[thread overview]
Message-ID: <20231116105817.51824-1-sj@kernel.org> (raw)
In-Reply-To: <tencent_3EF8231A65618FEEC716F90828433D6E9C09@qq.com>

Hello FANG2508,

On Thu, 16 Nov 2023 18:21:47 +0800 FANG2508 <1031576200@qq.com> wrote:

> In function 'damon_hot_score', the variable 'hotness' should be divided by the sum of 'freq_weight' and 'age_weight' instead of /'freq_weight'+'age_weight'.
> 
> Signed-off-by: FANG2508 <1031576200@qq.com>
> ---
>  mm/damon/ops-common.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c
> index d25d99cb5f2b..fc7886c63bf1 100644
> --- a/mm/damon/ops-common.c
> +++ b/mm/damon/ops-common.c
> @@ -102,7 +102,7 @@ int damon_hot_score(struct damon_ctx *c, struct damon_region *r,
>  
>  	hotness = (freq_weight * freq_subscore + age_weight * age_subscore);
>  	if (freq_weight + age_weight)
> -		hotness /= freq_weight + age_weight;
> +		hotness /= (freq_weight + age_weight);

Thank you for this patch.  However, I think the old code is ok, since the
precedence of the /= operation is right to left[1]?  I also checked that's true
by confirming below simple kunit passes.

    int abc = 3;

    abc /= 1 + 2;
    KUNIT_EXPECT_EQ(test, abc, 1);

Please let me know if I'm
missing something.


[1] https://en.cppreference.com/w/c/language/operator_precedence


Thanks,
SJ

>  	/*
>  	 * Transform it to fit in [0, DAMOS_MAX_SCORE]
>  	 */
> -- 
> 2.39.2

           reply	other threads:[~2023-11-16 10:58 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <tencent_3EF8231A65618FEEC716F90828433D6E9C09@qq.com>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231116105817.51824-1-sj@kernel.org \
    --to=sj@kernel.org \
    --cc=1031576200@qq.com \
    --cc=damon@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).