Re: [RFC PATCH 1/5] mm/damon/core: fix nr_accesses_bp underflow in damon_moving_sum
From: SeongJae Park
Date: Sun May 17 2026 - 14:18:15 EST
Hello Ravi,
On Sat, 16 May 2026 14:03:53 -0700 Ravi Jonnalagadda <ravis.opensrc@xxxxxxxxx> wrote:
> Guard against unsigned integer underflow when nomvsum/len_window
> exceeds mvsum.
How could this happen? mvsum is assumed to be same to nomvsum at the beginning
of the window. Hence, even if there is only zero new_value, at the end of the
window, mvsum should be exactly zero. Of course there could be a bug that
breaks the assumption.
> When that subtraction wraps, the moving sum returns a
> near-ULONG_MAX value and corrupts nr_accesses_bp.
>
> If subtrahend > mvsum, return new_value: this clamps the moving-sum
> estimate to the current observation rather than wrapping.
I guess you saw this issue in real, and this change should fix the issue. But
I think we should know why and how mvsum < nomvum / len_window can unexpectedly
happen, and fix that.
Could you share more details about when and how the situation happens?
Thanks,
SJ
[...]