Commit 3168ecbe authored by Johannes Weiner's avatar Johannes Weiner Committed by Linus Torvalds
Browse files

mm: memcg: use proper memcg in limit bypass

Commit 84235de3

 ("fs: buffer: move allocation failure loop into the
allocator") allowed __GFP_NOFAIL allocations to bypass the limit if they
fail to reclaim enough memory for the charge.  But because the main test
case was on a 3.2-based system, the patch missed the fact that on newer
kernels the charge function needs to return root_mem_cgroup when
bypassing the limit, and not NULL.  This will corrupt whatever memory is
at NULL + percpu pointer offset.  Fix this quickly before problems are
Signed-off-by: default avatarJohannes Weiner <>
Acked-by: default avatarMichal Hocko <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 12aee278
......@@ -2765,10 +2765,10 @@ static int __mem_cgroup_try_charge(struct mm_struct *mm,
*ptr = memcg;
return 0;
*ptr = NULL;
if (gfp_mask & __GFP_NOFAIL)
return 0;
return -ENOMEM;
if (!(gfp_mask & __GFP_NOFAIL)) {
*ptr = NULL;
return -ENOMEM;
*ptr = root_mem_cgroup;
return -EINTR;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment