Commit 18f59ea7de08db2449ba99185e8d8cc30e7acac5

Authored by Balbir Singh
Committed by Linus Torvalds
1 parent 6d61ef409d

memcg: memory cgroup hierarchy feature selector

Don't enable multiple hierarchy support by default.  This patch introduces
a features element that can be set to enable the nested depth hierarchy
feature.  This feature can only be enabled when the cgroup for which the
feature this is enabled, has no children.

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>

Showing 1 changed file with 57 additions and 4 deletions Side-by-side Diff

... ... @@ -149,6 +149,10 @@
149 149 * reclaimed from. Protected by cgroup_lock()
150 150 */
151 151 struct mem_cgroup *last_scanned_child;
  152 + /*
  153 + * Should the accounting and control be hierarchical, per subtree?
  154 + */
  155 + bool use_hierarchy;
152 156  
153 157 int obsolete;
154 158 atomic_t refcnt;
... ... @@ -1543,6 +1547,44 @@
1543 1547 }
1544 1548  
1545 1549  
  1550 +static u64 mem_cgroup_hierarchy_read(struct cgroup *cont, struct cftype *cft)
  1551 +{
  1552 + return mem_cgroup_from_cont(cont)->use_hierarchy;
  1553 +}
  1554 +
  1555 +static int mem_cgroup_hierarchy_write(struct cgroup *cont, struct cftype *cft,
  1556 + u64 val)
  1557 +{
  1558 + int retval = 0;
  1559 + struct mem_cgroup *mem = mem_cgroup_from_cont(cont);
  1560 + struct cgroup *parent = cont->parent;
  1561 + struct mem_cgroup *parent_mem = NULL;
  1562 +
  1563 + if (parent)
  1564 + parent_mem = mem_cgroup_from_cont(parent);
  1565 +
  1566 + cgroup_lock();
  1567 + /*
  1568 + * If parent's use_hiearchy is set, we can't make any modifications
  1569 + * in the child subtrees. If it is unset, then the change can
  1570 + * occur, provided the current cgroup has no children.
  1571 + *
  1572 + * For the root cgroup, parent_mem is NULL, we allow value to be
  1573 + * set if there are no children.
  1574 + */
  1575 + if ((!parent_mem || !parent_mem->use_hierarchy) &&
  1576 + (val == 1 || val == 0)) {
  1577 + if (list_empty(&cont->children))
  1578 + mem->use_hierarchy = val;
  1579 + else
  1580 + retval = -EBUSY;
  1581 + } else
  1582 + retval = -EINVAL;
  1583 + cgroup_unlock();
  1584 +
  1585 + return retval;
  1586 +}
  1587 +
1546 1588 static u64 mem_cgroup_read(struct cgroup *cont, struct cftype *cft)
1547 1589 {
1548 1590 struct mem_cgroup *mem = mem_cgroup_from_cont(cont);
... ... @@ -1706,6 +1748,11 @@
1706 1748 .name = "force_empty",
1707 1749 .trigger = mem_cgroup_force_empty_write,
1708 1750 },
  1751 + {
  1752 + .name = "use_hierarchy",
  1753 + .write_u64 = mem_cgroup_hierarchy_write,
  1754 + .read_u64 = mem_cgroup_hierarchy_read,
  1755 + },
1709 1756 };
1710 1757  
1711 1758 #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
1712 1759  
1713 1760  
... ... @@ -1881,12 +1928,18 @@
1881 1928 if (cont->parent == NULL) {
1882 1929 enable_swap_cgroup();
1883 1930 parent = NULL;
1884   - } else
  1931 + } else {
1885 1932 parent = mem_cgroup_from_cont(cont->parent);
  1933 + mem->use_hierarchy = parent->use_hierarchy;
  1934 + }
1886 1935  
1887   - res_counter_init(&mem->res, parent ? &parent->res : NULL);
1888   - res_counter_init(&mem->memsw, parent ? &parent->memsw : NULL);
1889   -
  1936 + if (parent && parent->use_hierarchy) {
  1937 + res_counter_init(&mem->res, &parent->res);
  1938 + res_counter_init(&mem->memsw, &parent->memsw);
  1939 + } else {
  1940 + res_counter_init(&mem->res, NULL);
  1941 + res_counter_init(&mem->memsw, NULL);
  1942 + }
1890 1943  
1891 1944 mem->last_scanned_child = NULL;
1892 1945