aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorKAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>2011-01-25 18:07:29 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2011-01-25 19:50:04 -0500
commit52dbb9050936fd33ceb45f10529dbc992507c058 (patch)
tree1c3663f50b7dec0bd852b02d76095b9a5618d7b7 /mm
parent3d37c4a9199920964ffdfaec6335d93b9dcf9ca5 (diff)
memcg: fix race at move_parent around compound_order()
A fix up mem_cgroup_move_parent() which use compound_order() in asynchronous manner. This compound_order() may return unknown value because we don't take lock. Use PageTransHuge() and HPAGE_SIZE instead of it. Also clean up for mem_cgroup_move_parent(). - remove unnecessary initialization of local variable. - rename charge_size -> page_size - remove unnecessary (wrong) comment. - added a comment about THP. Note: Current design take compound_page_lock() in caller of move_account(). This should be revisited when we implement direct move_task of hugepage without splitting. [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Reviewed-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp> Cc: Balbir Singh <balbir@in.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/memcontrol.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 8ab1d42664f..3878cfe399d 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2236,7 +2236,12 @@ static int mem_cgroup_move_account(struct page_cgroup *pc,
2236{ 2236{
2237 int ret = -EINVAL; 2237 int ret = -EINVAL;
2238 unsigned long flags; 2238 unsigned long flags;
2239 2239 /*
2240 * The page is isolated from LRU. So, collapse function
2241 * will not handle this page. But page splitting can happen.
2242 * Do this check under compound_page_lock(). The caller should
2243 * hold it.
2244 */
2240 if ((charge_size > PAGE_SIZE) && !PageTransHuge(pc->page)) 2245 if ((charge_size > PAGE_SIZE) && !PageTransHuge(pc->page))
2241 return -EBUSY; 2246 return -EBUSY;
2242 2247
@@ -2268,7 +2273,7 @@ static int mem_cgroup_move_parent(struct page_cgroup *pc,
2268 struct cgroup *cg = child->css.cgroup; 2273 struct cgroup *cg = child->css.cgroup;
2269 struct cgroup *pcg = cg->parent; 2274 struct cgroup *pcg = cg->parent;
2270 struct mem_cgroup *parent; 2275 struct mem_cgroup *parent;
2271 int charge = PAGE_SIZE; 2276 int page_size = PAGE_SIZE;
2272 unsigned long flags; 2277 unsigned long flags;
2273 int ret; 2278 int ret;
2274 2279
@@ -2281,22 +2286,24 @@ static int mem_cgroup_move_parent(struct page_cgroup *pc,
2281 goto out; 2286 goto out;
2282 if (isolate_lru_page(page)) 2287 if (isolate_lru_page(page))
2283 goto put; 2288 goto put;
2284 /* The page is isolated from LRU and we have no race with splitting */ 2289
2285 charge = PAGE_SIZE << compound_order(page); 2290 if (PageTransHuge(page))
2291 page_size = HPAGE_SIZE;
2286 2292
2287 parent = mem_cgroup_from_cont(pcg); 2293 parent = mem_cgroup_from_cont(pcg);
2288 ret = __mem_cgroup_try_charge(NULL, gfp_mask, &parent, false, charge); 2294 ret = __mem_cgroup_try_charge(NULL, gfp_mask,
2295 &parent, false, page_size);
2289 if (ret || !parent) 2296 if (ret || !parent)
2290 goto put_back; 2297 goto put_back;
2291 2298
2292 if (charge > PAGE_SIZE) 2299 if (page_size > PAGE_SIZE)
2293 flags = compound_lock_irqsave(page); 2300 flags = compound_lock_irqsave(page);
2294 2301
2295 ret = mem_cgroup_move_account(pc, child, parent, true, charge); 2302 ret = mem_cgroup_move_account(pc, child, parent, true, page_size);
2296 if (ret) 2303 if (ret)
2297 mem_cgroup_cancel_charge(parent, charge); 2304 mem_cgroup_cancel_charge(parent, page_size);
2298 2305
2299 if (charge > PAGE_SIZE) 2306 if (page_size > PAGE_SIZE)
2300 compound_unlock_irqrestore(page, flags); 2307 compound_unlock_irqrestore(page, flags);
2301put_back: 2308put_back:
2302 putback_lru_page(page); 2309 putback_lru_page(page);