From 7c82f022193a4f590ddcac8d3bd564330ec0bece Mon Sep 17 00:00:00 2001 From: liubo Date: Mon, 10 Jul 2023 09:43:53 +0800 Subject: [PATCH] etmem: fix the div 0 problem in swapcache reclaim process euleros inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I7JI6K CVE: NA ---------------------------------------------------- In the swapcache recycling process, the number of pages to be reclaimed on each node is obtained as follows: nr_to_reclaim[nid_num] = (swapcache_to_reclaim / (swapcache_total_reclaimable / nr[nid_num])); However, nr[nid_num] is obtained by traversing the number of swapcache pages on each node. If there are multiple nodes in the environment and no swap process occurs on a node, no swapcache page exists. The value of nr[nid_num] may be 0. Therefore, division by zero errors may occur. Signed-off-by: liubo (cherry picked from commit 905e7debc2732c158b31ff064af16118312f197d) --- mm/vmscan.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index d062f0aa06ee..c590d0d245c2 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4895,8 +4895,10 @@ int do_swapcache_reclaim(unsigned long *swapcache_watermark, for_each_node_state(nid, N_MEMORY) { cond_resched(); - nr_to_reclaim[nid_num] = (swapcache_to_reclaim / - (swapcache_total_reclaimable / nr[nid_num])); + nr_to_reclaim[nid_num] = (swapcache_total_reclaimable == 0) ? 0 : + ((swapcache_to_reclaim * nr[nid_num]) / + swapcache_total_reclaimable); + reclaim_page_count += reclaim_swapcache_pages_from_list(nid, &swapcache_list[nid_num], nr_to_reclaim[nid_num], false); -- Gitee