Skip to content

Commit

Permalink
mm,vmscan: fix divide by zero in get_scan_count
Browse files Browse the repository at this point in the history
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/[email protected]
Fixes: f56ce41 ("mm: memcontrol: fix occasional OOMs due to proportional memory.low reclaim")
Signed-off-by: Rik van Riel <[email protected]>
Acked-by: Roman Gushchin <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Acked-by: Johannes Weiner <[email protected]>
Acked-by: Chris Down <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
rikvanriel authored and torvalds committed Sep 9, 2021
1 parent 13db8c5 commit 32d4f4b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mm/vmscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -2715,7 +2715,7 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc,
cgroup_size = max(cgroup_size, protection);

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

/*
* Minimally target SWAP_CLUSTER_MAX pages to keep
Expand Down

0 comments on commit 32d4f4b

Please sign in to comment.