diff options
author | KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> | 2012-05-29 18:07:03 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-05-29 19:22:27 -0400 |
commit | d01dd17f1067ca50dbb9d1d3400d33221ce339e7 (patch) | |
tree | 07c8f7da424666c7fd81bb4a5b8288e68b87d094 /mm/memcontrol.c | |
parent | 2bb2ba9d51a8044a71a29608d2c4ef8f5b2d57a2 (diff) |
memcg: use res_counter_uncharge_until() in move_parent()
By using res_counter_uncharge_until(), we can avoid race and unnecessary
charging.
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ying Han <yinghan@google.com>
Cc: Glauber Costa <glommer@parallels.com>
Reviewed-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/memcontrol.c')
-rw-r--r-- | mm/memcontrol.c | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 9d1764630dff..1262a8bc402b 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c | |||
@@ -2423,6 +2423,24 @@ static void __mem_cgroup_cancel_charge(struct mem_cgroup *memcg, | |||
2423 | } | 2423 | } |
2424 | 2424 | ||
2425 | /* | 2425 | /* |
2426 | * Cancel chrages in this cgroup....doesn't propagate to parent cgroup. | ||
2427 | * This is useful when moving usage to parent cgroup. | ||
2428 | */ | ||
2429 | static void __mem_cgroup_cancel_local_charge(struct mem_cgroup *memcg, | ||
2430 | unsigned int nr_pages) | ||
2431 | { | ||
2432 | unsigned long bytes = nr_pages * PAGE_SIZE; | ||
2433 | |||
2434 | if (mem_cgroup_is_root(memcg)) | ||
2435 | return; | ||
2436 | |||
2437 | res_counter_uncharge_until(&memcg->res, memcg->res.parent, bytes); | ||
2438 | if (do_swap_account) | ||
2439 | res_counter_uncharge_until(&memcg->memsw, | ||
2440 | memcg->memsw.parent, bytes); | ||
2441 | } | ||
2442 | |||
2443 | /* | ||
2426 | * A helper function to get mem_cgroup from ID. must be called under | 2444 | * A helper function to get mem_cgroup from ID. must be called under |
2427 | * rcu_read_lock(). The caller must check css_is_removed() or some if | 2445 | * rcu_read_lock(). The caller must check css_is_removed() or some if |
2428 | * it's concern. (dropping refcnt from swap can be called against removed | 2446 | * it's concern. (dropping refcnt from swap can be called against removed |
@@ -2680,16 +2698,28 @@ static int mem_cgroup_move_parent(struct page *page, | |||
2680 | nr_pages = hpage_nr_pages(page); | 2698 | nr_pages = hpage_nr_pages(page); |
2681 | 2699 | ||
2682 | parent = mem_cgroup_from_cont(pcg); | 2700 | parent = mem_cgroup_from_cont(pcg); |
2683 | ret = __mem_cgroup_try_charge(NULL, gfp_mask, nr_pages, &parent, false); | 2701 | if (!parent->use_hierarchy) { |
2684 | if (ret) | 2702 | ret = __mem_cgroup_try_charge(NULL, |
2685 | goto put_back; | 2703 | gfp_mask, nr_pages, &parent, false); |
2704 | if (ret) | ||
2705 | goto put_back; | ||
2706 | } | ||
2686 | 2707 | ||
2687 | if (nr_pages > 1) | 2708 | if (nr_pages > 1) |
2688 | flags = compound_lock_irqsave(page); | 2709 | flags = compound_lock_irqsave(page); |
2689 | 2710 | ||
2690 | ret = mem_cgroup_move_account(page, nr_pages, pc, child, parent, true); | 2711 | if (parent->use_hierarchy) { |
2691 | if (ret) | 2712 | ret = mem_cgroup_move_account(page, nr_pages, |
2692 | __mem_cgroup_cancel_charge(parent, nr_pages); | 2713 | pc, child, parent, false); |
2714 | if (!ret) | ||
2715 | __mem_cgroup_cancel_local_charge(child, nr_pages); | ||
2716 | } else { | ||
2717 | ret = mem_cgroup_move_account(page, nr_pages, | ||
2718 | pc, child, parent, true); | ||
2719 | |||
2720 | if (ret) | ||
2721 | __mem_cgroup_cancel_charge(parent, nr_pages); | ||
2722 | } | ||
2693 | 2723 | ||
2694 | if (nr_pages > 1) | 2724 | if (nr_pages > 1) |
2695 | compound_unlock_irqrestore(page, flags); | 2725 | compound_unlock_irqrestore(page, flags); |