Re: [PATCH 03/10] mm/damon/core: use mult_frac() in damon_feed_loop_next_input()
From: Gutierrez Asier
Date: Thu Sep 17 2026 - 11:52:57 EST
On 9/17/2026 5:22 PM, SJ Park wrote:
> damon_feed_loop_next_input() does its best effort overflow protection.
> score_goal_diff is always smaller than goal (10,000). Hence the
> calculation can be replaced to use mult_frac() without concerning the
> overflow. Use mult_frac().
>
> Signed-off-by: SJ Park <sj@xxxxxxxxxx>
> ---
> mm/damon/core.c | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index de46072dc1a2f..bc41ac7ecca43 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -2927,11 +2927,7 @@ static unsigned long damon_feed_loop_next_input(unsigned long last_input,
> return min_input;
>
> score_goal_diff = abs_diff(score, goal);
> -
> - if (last_input < ULONG_MAX / score_goal_diff)
> - compensation = last_input * score_goal_diff / goal;
> - else
> - compensation = last_input / goal * score_goal_diff;
> + compensation = mult_frac(last_input, score_goal_diff, goal);
>
> if (over_achieving)
> return max(last_input - compensation, min_input);
LGTM
Reviewed-by: Asier Gutierrez <gutierrez.asier@xxxxxxxxxxxxxxxxxxx>
--
Asier Gutierrez
Huawei