Skip to content

Commit 16096c2

Browse files
tehcastertorvalds
authored andcommitted
mm, page_alloc: fix fast-path race with cpuset update or removal
Ganapatrao Kulkarni reported that the LTP test cpuset01 in stress mode triggers OOM killer in few seconds, despite lots of free memory. The test attempts to repeatedly fault in memory in one process in a cpuset, while changing allowed nodes of the cpuset between 0 and 1 in another process. One possible cause is that in the fast path we find the preferred zoneref according to current mems_allowed, so that it points to the middle of the zonelist, skipping e.g. zones of node 1 completely. If the mems_allowed is updated to contain only node 1, we never reach it in the zonelist, and trigger OOM before checking the cpuset_mems_cookie. This patch fixes the particular case by redoing the preferred zoneref search if we switch back to the original nodemask. The condition is also slightly changed so that when the last non-root cpuset is removed, we don't miss it. Note that this is not a full fix, and more patches will follow. Link: http://lkml.kernel.org/r/[email protected] Fixes: 682a338 ("mm, page_alloc: inline the fast path of the zonelist iterator") Signed-off-by: Vlastimil Babka <[email protected]> Reported-by: Ganapatrao Kulkarni <[email protected]> Acked-by: Michal Hocko <[email protected]> Acked-by: Mel Gorman <[email protected]> Acked-by: Hillf Danton <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent ea57485 commit 16096c2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

mm/page_alloc.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3804,9 +3804,17 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
38043804
/*
38053805
* Restore the original nodemask if it was potentially replaced with
38063806
* &cpuset_current_mems_allowed to optimize the fast-path attempt.
3807+
* Also recalculate the starting point for the zonelist iterator or
3808+
* we could end up iterating over non-eligible zones endlessly.
38073809
*/
3808-
if (cpusets_enabled())
3810+
if (unlikely(ac.nodemask != nodemask)) {
38093811
ac.nodemask = nodemask;
3812+
ac.preferred_zoneref = first_zones_zonelist(ac.zonelist,
3813+
ac.high_zoneidx, ac.nodemask);
3814+
if (!ac.preferred_zoneref->zone)
3815+
goto no_zone;
3816+
}
3817+
38103818
page = __alloc_pages_slowpath(alloc_mask, order, &ac);
38113819

38123820
no_zone:

0 commit comments

Comments
 (0)