aboutsummaryrefslogtreecommitdiffstats
path: root/mm/memcontrol.c
diff options
context:
space:
mode:
authorBalbir Singh <balbir@linux.vnet.ibm.com>2009-01-07 21:08:05 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-01-08 11:31:05 -0500
commit28dbc4b6a01fb579a9441c7b81e3d3413dc452df (patch)
treec45d94be6cd243f3e677ec8279bfec87855802d0 /mm/memcontrol.c
parent52bc0d82100cd896213a9a25ec01c1ba87b939db (diff)
memcg: memory cgroup resource counters for hierarchy
Add support for building hierarchies in resource counters. Cgroups allows us to build a deep hierarchy, but we currently don't link the resource counters belonging to the memory controller control groups, in the same fashion as the corresponding cgroup entries in the cgroup hierarchy. This patch provides the infrastructure for resource counters that have the same hiearchy as their cgroup counter parts. These set of patches are based on the resource counter hiearchy patches posted by Pavel Emelianov. NOTE: Building hiearchies is expensive, deeper hierarchies imply charging the all the way up to the root. It is known that hiearchies are expensive, so the user needs to be careful and aware of the trade-offs before creating very deep ones. [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: Balbir Singh <balbir@linux.vnet.ibm.com> Cc: YAMAMOTO Takashi <yamamoto@valinux.co.jp> Cc: Paul Menage <menage@google.com> Cc: Li Zefan <lizf@cn.fujitsu.com> Cc: David Rientjes <rientjes@google.com> Cc: Pavel Emelianov <xemul@openvz.org> Cc: Dhaval Giani <dhaval@linux.vnet.ibm.com> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> 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.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 9846f617115..e72fb2b4a7d 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -471,6 +471,7 @@ static int __mem_cgroup_try_charge(struct mm_struct *mm,
471{ 471{
472 struct mem_cgroup *mem; 472 struct mem_cgroup *mem;
473 int nr_retries = MEM_CGROUP_RECLAIM_RETRIES; 473 int nr_retries = MEM_CGROUP_RECLAIM_RETRIES;
474 struct res_counter *fail_res;
474 /* 475 /*
475 * We always charge the cgroup the mm_struct belongs to. 476 * We always charge the cgroup the mm_struct belongs to.
476 * The mm_struct's mem_cgroup changes on task migration if the 477 * The mm_struct's mem_cgroup changes on task migration if the
@@ -499,11 +500,12 @@ static int __mem_cgroup_try_charge(struct mm_struct *mm,
499 int ret; 500 int ret;
500 bool noswap = false; 501 bool noswap = false;
501 502
502 ret = res_counter_charge(&mem->res, PAGE_SIZE); 503 ret = res_counter_charge(&mem->res, PAGE_SIZE, &fail_res);
503 if (likely(!ret)) { 504 if (likely(!ret)) {
504 if (!do_swap_account) 505 if (!do_swap_account)
505 break; 506 break;
506 ret = res_counter_charge(&mem->memsw, PAGE_SIZE); 507 ret = res_counter_charge(&mem->memsw, PAGE_SIZE,
508 &fail_res);
507 if (likely(!ret)) 509 if (likely(!ret))
508 break; 510 break;
509 /* mem+swap counter fails */ 511 /* mem+swap counter fails */
@@ -1709,22 +1711,26 @@ static void __init enable_swap_cgroup(void)
1709static struct cgroup_subsys_state * 1711static struct cgroup_subsys_state *
1710mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont) 1712mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont)
1711{ 1713{
1712 struct mem_cgroup *mem; 1714 struct mem_cgroup *mem, *parent;
1713 int node; 1715 int node;
1714 1716
1715 mem = mem_cgroup_alloc(); 1717 mem = mem_cgroup_alloc();
1716 if (!mem) 1718 if (!mem)
1717 return ERR_PTR(-ENOMEM); 1719 return ERR_PTR(-ENOMEM);
1718 1720
1719 res_counter_init(&mem->res);
1720 res_counter_init(&mem->memsw);
1721
1722 for_each_node_state(node, N_POSSIBLE) 1721 for_each_node_state(node, N_POSSIBLE)
1723 if (alloc_mem_cgroup_per_zone_info(mem, node)) 1722 if (alloc_mem_cgroup_per_zone_info(mem, node))
1724 goto free_out; 1723 goto free_out;
1725 /* root ? */ 1724 /* root ? */
1726 if (cont->parent == NULL) 1725 if (cont->parent == NULL) {
1727 enable_swap_cgroup(); 1726 enable_swap_cgroup();
1727 parent = NULL;
1728 } else
1729 parent = mem_cgroup_from_cont(cont->parent);
1730
1731 res_counter_init(&mem->res, parent ? &parent->res : NULL);
1732 res_counter_init(&mem->memsw, parent ? &parent->memsw : NULL);
1733
1728 1734
1729 return &mem->css; 1735 return &mem->css;
1730free_out: 1736free_out: