memcg: fail to create cgroup if the cgroup id is too big
authorLi Zefan <lizefan@huawei.com>
Mon, 23 Sep 2013 08:56:29 +0000 (16:56 +0800)
committerTejun Heo <tj@kernel.org>
Tue, 24 Sep 2013 01:44:14 +0000 (21:44 -0400)
memcg requires the cgroup id to be smaller than 65536.

This is a preparation to kill css id.

Signed-off-by: Li Zefan <lizefan@huawei.com>
Acked-by: Michal Hocko <mhocko@suse.cz>
Signed-off-by: Tejun Heo <tj@kernel.org>
mm/memcontrol.c

index 404a13a..c140395 100644 (file)
@@ -488,6 +488,12 @@ static inline bool mem_cgroup_is_root(struct mem_cgroup *memcg)
        return (memcg == root_mem_cgroup);
 }
 
+/*
+ * We restrict the id in the range of [1, 65535], so it can fit into
+ * an unsigned short.
+ */
+#define MEM_CGROUP_ID_MAX      USHRT_MAX
+
 static inline unsigned short mem_cgroup_id(struct mem_cgroup *memcg)
 {
        /*
@@ -6059,6 +6065,9 @@ mem_cgroup_css_online(struct cgroup_subsys_state *css)
        struct mem_cgroup *parent = mem_cgroup_from_css(css_parent(css));
        int error = 0;
 
+       if (css->cgroup->id > MEM_CGROUP_ID_MAX)
+               return -ENOSPC;
+
        if (!parent)
                return 0;