Skip to content

Commit

Permalink
mm/damon/core: avoid divide-by-zero from pseudo-moving window length …
Browse files Browse the repository at this point in the history
…calculation

When calculating the pseudo-moving access rate, DAMON divides some values
by the maximum nr_accesses.  However, due to the type of the related
variables, simple division-based calculation of the divisor can return
zero.  As a result, divide-by-zero is possible.  Fix it by using
damon_max_nr_accesses(), which handles the case.

Note that this is a fix for a commit that not in the mainline but mm
tree.

Link: https://lkml.kernel.org/r/[email protected]
Fixes: ace30fb ("mm/damon/core: use pseudo-moving sum for nr_accesses_bp")
Reported-by: Jakub Acs <[email protected]>
Signed-off-by: SeongJae Park <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
sjp38 authored and akpm00 committed Oct 25, 2023
1 parent 44063f1 commit 62f76a7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mm/damon/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,7 @@ void damon_update_region_access_rate(struct damon_region *r, bool accessed,
* aggr_interval, owing to validation of damon_set_attrs().
*/
if (attrs->sample_interval)
len_window = attrs->aggr_interval / attrs->sample_interval;
len_window = damon_max_nr_accesses(attrs);
r->nr_accesses_bp = damon_moving_sum(r->nr_accesses_bp,
r->last_nr_accesses * 10000, len_window,
accessed ? 10000 : 0);
Expand Down

0 comments on commit 62f76a7

Please sign in to comment.