When memcg->use_hierarchy==true, the parent res_counter includes the usage in child's usage. So, it's not necessary to call try_charge() in the parent. Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@xxxxxxxxxxxxxx> --- mm/memcontrol.c | 39 ++++++++++++++++++++++++++++++++------- 1 files changed, 32 insertions(+), 7 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index fa01106..3215880 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2409,6 +2409,20 @@ static void __mem_cgroup_cancel_charge(struct mem_cgroup *memcg, res_counter_uncharge(&memcg->memsw, bytes); } } +/* + * Moving usage between a child to its parent if use_hierarchy==true. + */ +static void __mem_cgroup_move_charge_parent(struct mem_cgroup *memcg, + unsigned int nr_pages) +{ + if (!mem_cgroup_is_root(memcg)) { + unsigned long bytes = nr_pages * PAGE_SIZE; + + res_counter_move_parent(&memcg->res, bytes); + if (do_swap_account) + res_counter_move_parent(&memcg->memsw, bytes); + } +} /* * A helper function to get mem_cgroup from ID. must be called under @@ -2666,18 +2680,29 @@ static int mem_cgroup_move_parent(struct page *page, goto put; nr_pages = hpage_nr_pages(page); - parent = mem_cgroup_from_cont(pcg); - ret = __mem_cgroup_try_charge(NULL, gfp_mask, nr_pages, &parent, false); - if (ret) - goto put_back; + + if (!parent->use_hierarchy) { + ret = __mem_cgroup_try_charge(NULL, gfp_mask, + nr_pages, &parent, false); + if (ret) + goto put_back; + } if (nr_pages > 1) flags = compound_lock_irqsave(page); - ret = mem_cgroup_move_account(page, nr_pages, pc, child, parent, true); - if (ret) - __mem_cgroup_cancel_charge(parent, nr_pages); + if (!parent->use_hierarchy) { + ret = mem_cgroup_move_account(page, nr_pages, pc, + child, parent, true); + if (ret) + __mem_cgroup_cancel_charge(parent, nr_pages); + } else { + ret = mem_cgroup_move_account(page, nr_pages, pc, + child, parent, false); + if (!ret) + __mem_cgroup_move_charge_parent(child, nr_pages); + } if (nr_pages > 1) compound_unlock_irqrestore(page, flags); -- 1.7.4.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@xxxxxxxxx. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"dont@xxxxxxxxx"> email@xxxxxxxxx </a>