Skip to content

Commit 3bafc47

Browse files
sjp38akpm00
authored andcommitted
mm/damon/ops-common: avoid divide-by-zero during region hotness calculation
When calculating the hotness of each region for the under-quota regions prioritization, 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. Link: https://lkml.kernel.org/r/[email protected] Fixes: 198f0f4 ("mm/damon/vaddr,paddr: support pageout prioritization") Signed-off-by: SeongJae Park <[email protected]> Reported-by: Jakub Acs <[email protected]> Cc: <[email protected]> [5.16+] Signed-off-by: Andrew Morton <[email protected]>
1 parent d35963b commit 3bafc47

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

mm/damon/ops-common.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,15 @@ void damon_pmdp_mkold(pmd_t *pmd, struct vm_area_struct *vma, unsigned long addr
7373
int damon_hot_score(struct damon_ctx *c, struct damon_region *r,
7474
struct damos *s)
7575
{
76-
unsigned int max_nr_accesses;
7776
int freq_subscore;
7877
unsigned int age_in_sec;
7978
int age_in_log, age_subscore;
8079
unsigned int freq_weight = s->quota.weight_nr_accesses;
8180
unsigned int age_weight = s->quota.weight_age;
8281
int hotness;
8382

84-
max_nr_accesses = c->attrs.aggr_interval / c->attrs.sample_interval;
85-
freq_subscore = r->nr_accesses * DAMON_MAX_SUBSCORE / max_nr_accesses;
83+
freq_subscore = r->nr_accesses * DAMON_MAX_SUBSCORE /
84+
damon_max_nr_accesses(&c->attrs);
8685

8786
age_in_sec = (unsigned long)r->age * c->attrs.aggr_interval / 1000000;
8887
for (age_in_log = 0; age_in_log < DAMON_MAX_AGE_IN_LOG && age_in_sec;

0 commit comments

Comments
 (0)