diff options
-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); |