Skip to content

Commit d35963b

Browse files
sjp38akpm00
authored andcommitted
mm/damon/core: avoid divide-by-zero during monitoring results update
When monitoring attributes are changed, DAMON updates access rate of the monitoring results accordingly. For that, it 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. Link: https://lkml.kernel.org/r/[email protected] Fixes: 2f5bef5 ("mm/damon/core: update monitoring results for new monitoring attributes") Signed-off-by: SeongJae Park <[email protected]> Reported-by: Jakub Acs <[email protected]> Cc: <[email protected]> [6.3+] Signed-off-by: Andrew Morton <[email protected]>
1 parent 35f5d94 commit d35963b

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

mm/damon/core.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -500,20 +500,14 @@ static unsigned int damon_age_for_new_attrs(unsigned int age,
500500
static unsigned int damon_accesses_bp_to_nr_accesses(
501501
unsigned int accesses_bp, struct damon_attrs *attrs)
502502
{
503-
unsigned int max_nr_accesses =
504-
attrs->aggr_interval / attrs->sample_interval;
505-
506-
return accesses_bp * max_nr_accesses / 10000;
503+
return accesses_bp * damon_max_nr_accesses(attrs) / 10000;
507504
}
508505

509506
/* convert nr_accesses to access ratio in bp (per 10,000) */
510507
static unsigned int damon_nr_accesses_to_accesses_bp(
511508
unsigned int nr_accesses, struct damon_attrs *attrs)
512509
{
513-
unsigned int max_nr_accesses =
514-
attrs->aggr_interval / attrs->sample_interval;
515-
516-
return nr_accesses * 10000 / max_nr_accesses;
510+
return nr_accesses * 10000 / damon_max_nr_accesses(attrs);
517511
}
518512

519513
static unsigned int damon_nr_accesses_for_new_attrs(unsigned int nr_accesses,

0 commit comments

Comments
 (0)