* Re: [PATCH] mm/damon/ops-common.c: Fixup missing parentheses
[not found] <tencent_3EF8231A65618FEEC716F90828433D6E9C09@qq.com>
@ 2023-11-16 10:58 ` SeongJae Park
0 siblings, 0 replies; only message in thread
From: SeongJae Park @ 2023-11-16 10:58 UTC (permalink / raw)
To: FANG2508; +Cc: linux-mm, sj, linux-kernel, damon
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
^ permalink raw reply [flat|nested] only message in thread