aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlauber Costa <glommer@parallels.com>2012-04-09 18:36:33 -0400
committerTejun Heo <tj@kernel.org>2012-04-10 13:04:07 -0400
commit1d62e43657c63a858560c98069706c705d20505d (patch)
tree8b55403e0cf1efaab0c0fd7a2e53751dd21f1ebd
parent48ddbe194623ae089cc0576e60363f2d2e85662a (diff)
cgroup: pass struct mem_cgroup instead of struct cgroup to socket memcg
The only reason cgroup was used, was to be consistent with the populate() interface. Now that we're getting rid of it, not only we no longer need it, but we also *can't* call it this way. Since we will no longer rely on populate(), this will be called from create(). During create, the association between struct mem_cgroup and struct cgroup does not yet exist, since cgroup internals hasn't yet initialized its bookkeeping. This means we would not be able to draw the memcg pointer from the cgroup pointer in these functions, which is highly undesirable. Signed-off-by: Glauber Costa <glommer@parallels.com> Acked-by: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Signed-off-by: Tejun Heo <tj@kernel.org> CC: Li Zefan <lizefan@huawei.com> CC: Johannes Weiner <hannes@cmpxchg.org> CC: Michal Hocko <mhocko@suse.cz>
-rw-r--r--include/net/sock.h12
-rw-r--r--include/net/tcp_memcontrol.h4
-rw-r--r--mm/memcontrol.c24
-rw-r--r--net/core/sock.c10
-rw-r--r--net/ipv4/tcp_memcontrol.c6
5 files changed, 24 insertions, 32 deletions
diff --git a/include/net/sock.h b/include/net/sock.h
index a6ba1f8871fd..b3ebe6b3e7db 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -70,16 +70,16 @@
70struct cgroup; 70struct cgroup;
71struct cgroup_subsys; 71struct cgroup_subsys;
72#ifdef CONFIG_NET 72#ifdef CONFIG_NET
73int mem_cgroup_sockets_init(struct cgroup *cgrp, struct cgroup_subsys *ss); 73int mem_cgroup_sockets_init(struct mem_cgroup *memcg, struct cgroup_subsys *ss);
74void mem_cgroup_sockets_destroy(struct cgroup *cgrp); 74void mem_cgroup_sockets_destroy(struct mem_cgroup *memcg);
75#else 75#else
76static inline 76static inline
77int mem_cgroup_sockets_init(struct cgroup *cgrp, struct cgroup_subsys *ss) 77int mem_cgroup_sockets_init(struct mem_cgroup *memcg, struct cgroup_subsys *ss)
78{ 78{
79 return 0; 79 return 0;
80} 80}
81static inline 81static inline
82void mem_cgroup_sockets_destroy(struct cgroup *cgrp) 82void mem_cgroup_sockets_destroy(struct mem_cgroup *memcg)
83{ 83{
84} 84}
85#endif 85#endif
@@ -900,9 +900,9 @@ struct proto {
900 * This function has to setup any files the protocol want to 900 * This function has to setup any files the protocol want to
901 * appear in the kmem cgroup filesystem. 901 * appear in the kmem cgroup filesystem.
902 */ 902 */
903 int (*init_cgroup)(struct cgroup *cgrp, 903 int (*init_cgroup)(struct mem_cgroup *memcg,
904 struct cgroup_subsys *ss); 904 struct cgroup_subsys *ss);
905 void (*destroy_cgroup)(struct cgroup *cgrp); 905 void (*destroy_cgroup)(struct mem_cgroup *memcg);
906 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg); 906 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
907#endif 907#endif
908}; 908};
diff --git a/include/net/tcp_memcontrol.h b/include/net/tcp_memcontrol.h
index 48410ff25c9e..7df18bc43a97 100644
--- a/include/net/tcp_memcontrol.h
+++ b/include/net/tcp_memcontrol.h
@@ -12,8 +12,8 @@ struct tcp_memcontrol {
12}; 12};
13 13
14struct cg_proto *tcp_proto_cgroup(struct mem_cgroup *memcg); 14struct cg_proto *tcp_proto_cgroup(struct mem_cgroup *memcg);
15int tcp_init_cgroup(struct cgroup *cgrp, struct cgroup_subsys *ss); 15int tcp_init_cgroup(struct mem_cgroup *memcg, struct cgroup_subsys *ss);
16void tcp_destroy_cgroup(struct cgroup *cgrp); 16void tcp_destroy_cgroup(struct mem_cgroup *memcg);
17unsigned long long tcp_max_memory(const struct mem_cgroup *memcg); 17unsigned long long tcp_max_memory(const struct mem_cgroup *memcg);
18void tcp_prot_mem(struct mem_cgroup *memcg, long val, int idx); 18void tcp_prot_mem(struct mem_cgroup *memcg, long val, int idx);
19#endif /* _TCP_MEMCG_H */ 19#endif /* _TCP_MEMCG_H */
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index d28359cd6b55..785c32367075 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4640,29 +4640,22 @@ static int mem_control_numa_stat_open(struct inode *unused, struct file *file)
4640#endif /* CONFIG_NUMA */ 4640#endif /* CONFIG_NUMA */
4641 4641
4642#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM 4642#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM
4643static int register_kmem_files(struct cgroup *cont, struct cgroup_subsys *ss) 4643static int register_kmem_files(struct mem_cgroup *memcg, struct cgroup_subsys *ss)
4644{ 4644{
4645 /* 4645 return mem_cgroup_sockets_init(memcg, ss);
4646 * Part of this would be better living in a separate allocation
4647 * function, leaving us with just the cgroup tree population work.
4648 * We, however, depend on state such as network's proto_list that
4649 * is only initialized after cgroup creation. I found the less
4650 * cumbersome way to deal with it to defer it all to populate time
4651 */
4652 return mem_cgroup_sockets_init(cont, ss);
4653}; 4646};
4654 4647
4655static void kmem_cgroup_destroy(struct cgroup *cont) 4648static void kmem_cgroup_destroy(struct mem_cgroup *memcg)
4656{ 4649{
4657 mem_cgroup_sockets_destroy(cont); 4650 mem_cgroup_sockets_destroy(memcg);
4658} 4651}
4659#else 4652#else
4660static int register_kmem_files(struct cgroup *cont, struct cgroup_subsys *ss) 4653static int register_kmem_files(struct mem_cgroup *memcg, struct cgroup_subsys *ss)
4661{ 4654{
4662 return 0; 4655 return 0;
4663} 4656}
4664 4657
4665static void kmem_cgroup_destroy(struct cgroup *cont) 4658static void kmem_cgroup_destroy(struct mem_cgroup *memcg)
4666{ 4659{
4667} 4660}
4668#endif 4661#endif
@@ -5034,7 +5027,7 @@ static void mem_cgroup_destroy(struct cgroup *cont)
5034{ 5027{
5035 struct mem_cgroup *memcg = mem_cgroup_from_cont(cont); 5028 struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
5036 5029
5037 kmem_cgroup_destroy(cont); 5030 kmem_cgroup_destroy(memcg);
5038 5031
5039 mem_cgroup_put(memcg); 5032 mem_cgroup_put(memcg);
5040} 5033}
@@ -5042,7 +5035,8 @@ static void mem_cgroup_destroy(struct cgroup *cont)
5042static int mem_cgroup_populate(struct cgroup_subsys *ss, 5035static int mem_cgroup_populate(struct cgroup_subsys *ss,
5043 struct cgroup *cont) 5036 struct cgroup *cont)
5044{ 5037{
5045 return register_kmem_files(cont, ss); 5038 struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
5039 return register_kmem_files(memcg, ss);
5046} 5040}
5047 5041
5048#ifdef CONFIG_MMU 5042#ifdef CONFIG_MMU
diff --git a/net/core/sock.c b/net/core/sock.c
index b2e14c07d920..878f7447cf61 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -140,7 +140,7 @@ static DEFINE_MUTEX(proto_list_mutex);
140static LIST_HEAD(proto_list); 140static LIST_HEAD(proto_list);
141 141
142#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM 142#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM
143int mem_cgroup_sockets_init(struct cgroup *cgrp, struct cgroup_subsys *ss) 143int mem_cgroup_sockets_init(struct mem_cgroup *memcg, struct cgroup_subsys *ss)
144{ 144{
145 struct proto *proto; 145 struct proto *proto;
146 int ret = 0; 146 int ret = 0;
@@ -148,7 +148,7 @@ int mem_cgroup_sockets_init(struct cgroup *cgrp, struct cgroup_subsys *ss)
148 mutex_lock(&proto_list_mutex); 148 mutex_lock(&proto_list_mutex);
149 list_for_each_entry(proto, &proto_list, node) { 149 list_for_each_entry(proto, &proto_list, node) {
150 if (proto->init_cgroup) { 150 if (proto->init_cgroup) {
151 ret = proto->init_cgroup(cgrp, ss); 151 ret = proto->init_cgroup(memcg, ss);
152 if (ret) 152 if (ret)
153 goto out; 153 goto out;
154 } 154 }
@@ -159,19 +159,19 @@ int mem_cgroup_sockets_init(struct cgroup *cgrp, struct cgroup_subsys *ss)
159out: 159out:
160 list_for_each_entry_continue_reverse(proto, &proto_list, node) 160 list_for_each_entry_continue_reverse(proto, &proto_list, node)
161 if (proto->destroy_cgroup) 161 if (proto->destroy_cgroup)
162 proto->destroy_cgroup(cgrp); 162 proto->destroy_cgroup(memcg);
163 mutex_unlock(&proto_list_mutex); 163 mutex_unlock(&proto_list_mutex);
164 return ret; 164 return ret;
165} 165}
166 166
167void mem_cgroup_sockets_destroy(struct cgroup *cgrp) 167void mem_cgroup_sockets_destroy(struct mem_cgroup *memcg)
168{ 168{
169 struct proto *proto; 169 struct proto *proto;
170 170
171 mutex_lock(&proto_list_mutex); 171 mutex_lock(&proto_list_mutex);
172 list_for_each_entry_reverse(proto, &proto_list, node) 172 list_for_each_entry_reverse(proto, &proto_list, node)
173 if (proto->destroy_cgroup) 173 if (proto->destroy_cgroup)
174 proto->destroy_cgroup(cgrp); 174 proto->destroy_cgroup(memcg);
175 mutex_unlock(&proto_list_mutex); 175 mutex_unlock(&proto_list_mutex);
176} 176}
177#endif 177#endif
diff --git a/net/ipv4/tcp_memcontrol.c b/net/ipv4/tcp_memcontrol.c
index 8f1753defa5c..151703791bb0 100644
--- a/net/ipv4/tcp_memcontrol.c
+++ b/net/ipv4/tcp_memcontrol.c
@@ -18,7 +18,7 @@ static void memcg_tcp_enter_memory_pressure(struct sock *sk)
18} 18}
19EXPORT_SYMBOL(memcg_tcp_enter_memory_pressure); 19EXPORT_SYMBOL(memcg_tcp_enter_memory_pressure);
20 20
21int tcp_init_cgroup(struct cgroup *cgrp, struct cgroup_subsys *ss) 21int tcp_init_cgroup(struct mem_cgroup *memcg, struct cgroup_subsys *ss)
22{ 22{
23 /* 23 /*
24 * The root cgroup does not use res_counters, but rather, 24 * The root cgroup does not use res_counters, but rather,
@@ -28,7 +28,6 @@ int tcp_init_cgroup(struct cgroup *cgrp, struct cgroup_subsys *ss)
28 struct res_counter *res_parent = NULL; 28 struct res_counter *res_parent = NULL;
29 struct cg_proto *cg_proto, *parent_cg; 29 struct cg_proto *cg_proto, *parent_cg;
30 struct tcp_memcontrol *tcp; 30 struct tcp_memcontrol *tcp;
31 struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
32 struct mem_cgroup *parent = parent_mem_cgroup(memcg); 31 struct mem_cgroup *parent = parent_mem_cgroup(memcg);
33 struct net *net = current->nsproxy->net_ns; 32 struct net *net = current->nsproxy->net_ns;
34 33
@@ -61,9 +60,8 @@ int tcp_init_cgroup(struct cgroup *cgrp, struct cgroup_subsys *ss)
61} 60}
62EXPORT_SYMBOL(tcp_init_cgroup); 61EXPORT_SYMBOL(tcp_init_cgroup);
63 62
64void tcp_destroy_cgroup(struct cgroup *cgrp) 63void tcp_destroy_cgroup(struct mem_cgroup *memcg)
65{ 64{
66 struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
67 struct cg_proto *cg_proto; 65 struct cg_proto *cg_proto;
68 struct tcp_memcontrol *tcp; 66 struct tcp_memcontrol *tcp;
69 u64 val; 67 u64 val;