Skip to content

Commit

Permalink
mm: memcg: use proper memcg in limit bypass
Browse files Browse the repository at this point in the history
Commit 84235de ("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
reported.

Signed-off-by: Johannes Weiner <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
hnaz authored and torvalds committed Oct 31, 2013
1 parent 12aee27 commit 3168ecb
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -2765,10 +2765,10 @@ static int __mem_cgroup_try_charge(struct mm_struct *mm,
*ptr = memcg;
return 0;
nomem:
*ptr = NULL;
if (gfp_mask & __GFP_NOFAIL)
return 0;
return -ENOMEM;
if (!(gfp_mask & __GFP_NOFAIL)) {
*ptr = NULL;
return -ENOMEM;
}
bypass:
*ptr = root_mem_cgroup;
return -EINTR;
Expand Down

0 comments on commit 3168ecb

Please sign in to comment.