Commit 9221edb7 authored by Johannes Weiner's avatar Johannes Weiner Committed by Linus Torvalds

memcg: prevent endless loop when charging huge pages

The charging code can encounter a charge size that is bigger than a
regular page in two situations: one is a batched charge to fill the
per-cpu stocks, the other is a huge page charge.

This code is distributed over two functions, however, and only the outer
one is aware of huge pages.  In case the charging fails, the inner
function will tell the outer function to retry if the charge size is
bigger than regular pages--assuming batched charging is the only case.
And the outer function will retry forever charging a huge page.

This patch makes sure the inner function can distinguish between batch
charging and a single huge page charge.  It will only signal another
attempt if batch charging failed, and go into regular reclaim when it is
called on behalf of a huge page.
Signed-off-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
Acked-by: default avatarKAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Reviewed-by: default avatarMinchan Kim <minchan.kim@gmail.com>
Cc: Balbir Singh <balbir@linux.vnet.ibm.com>
Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent af241a08
...@@ -1837,8 +1837,15 @@ static int __mem_cgroup_do_charge(struct mem_cgroup *mem, gfp_t gfp_mask, ...@@ -1837,8 +1837,15 @@ static int __mem_cgroup_do_charge(struct mem_cgroup *mem, gfp_t gfp_mask,
flags |= MEM_CGROUP_RECLAIM_NOSWAP; flags |= MEM_CGROUP_RECLAIM_NOSWAP;
} else } else
mem_over_limit = mem_cgroup_from_res_counter(fail_res, res); mem_over_limit = mem_cgroup_from_res_counter(fail_res, res);
/*
if (csize > PAGE_SIZE) /* change csize and retry */ * csize can be either a huge page (HPAGE_SIZE), a batch of
* regular pages (CHARGE_SIZE), or a single regular page
* (PAGE_SIZE).
*
* Never reclaim on behalf of optional batching, retry with a
* single page instead.
*/
if (csize == CHARGE_SIZE)
return CHARGE_RETRY; return CHARGE_RETRY;
if (!(gfp_mask & __GFP_WAIT)) if (!(gfp_mask & __GFP_WAIT))
......
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