Skip to content

Commit 44063f1

Browse files
sjp38akpm00
authored andcommitted
mm/damon/lru_sort: avoid divide-by-zero in hot threshold calculation
When calculating the hotness threshold for lru_prio scheme of DAMON_LRU_SORT, the module 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: 40e983c ("mm/damon: introduce DAMON-based LRU-lists Sorting") Signed-off-by: SeongJae Park <[email protected]> Reported-by: Jakub Acs <[email protected]> Cc: <[email protected]> [6.0+] Signed-off-by: Andrew Morton <[email protected]>
1 parent 3bafc47 commit 44063f1

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

mm/damon/lru_sort.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,7 @@ static int damon_lru_sort_apply_parameters(void)
195195
if (err)
196196
return err;
197197

198-
/* aggr_interval / sample_interval is the maximum nr_accesses */
199-
hot_thres = damon_lru_sort_mon_attrs.aggr_interval /
200-
damon_lru_sort_mon_attrs.sample_interval *
198+
hot_thres = damon_max_nr_accesses(&damon_lru_sort_mon_attrs) *
201199
hot_thres_access_freq / 1000;
202200
scheme = damon_lru_sort_new_hot_scheme(hot_thres);
203201
if (!scheme)

0 commit comments

Comments
 (0)