Skip to content

Commit 388f12d

Browse files
rikvanrielgregkh
authored andcommitted
mm,vmscan: fix divide by zero in get_scan_count
commit 32d4f4b upstream. Commit f56ce41 ("mm: memcontrol: fix occasional OOMs due to proportional memory.low reclaim") introduced a divide by zero corner case when oomd is being used in combination with cgroup memory.low protection. When oomd decides to kill a cgroup, it will force the cgroup memory to be reclaimed after killing the tasks, by writing to the memory.max file for that cgroup, forcing the remaining page cache and reclaimable slab to be reclaimed down to zero. Previously, on cgroups with some memory.low protection that would result in the memory being reclaimed down to the memory.low limit, or likely not at all, having the page cache reclaimed asynchronously later. With f56ce41 the oomd write to memory.max tries to reclaim all the way down to zero, which may race with another reclaimer, to the point of ending up with the divide by zero below. This patch implements the obvious fix. Link: https://lkml.kernel.org/r/20210826220149.058089c6@imladris.surriel.com Fixes: f56ce41 ("mm: memcontrol: fix occasional OOMs due to proportional memory.low reclaim") Signed-off-by: Rik van Riel <riel@surriel.com> Acked-by: Roman Gushchin <guro@fb.com> Acked-by: Michal Hocko <mhocko@suse.com> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Chris Down <chris@chrisdown.name> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2d2d8b0 commit 388f12d

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎mm/vmscan.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2378,7 +2378,7 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc,
23782378
cgroup_size = max(cgroup_size, protection);
23792379

23802380
scan = lruvec_size - lruvec_size * protection /
2381-
cgroup_size;
2381+
(cgroup_size + 1);
23822382

23832383
/*
23842384
* Minimally target SWAP_CLUSTER_MAX pages to keep

0 commit comments

Comments
 (0)