diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2013-10-19 19:26:19 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-10-21 18:43:02 -0400 |
commit | 2e685cad57906e19add7189b5ff49dfb6aaa21d3 (patch) | |
tree | d8e382e4e7e0a684284542b6aab8187e18b10a91 /net/ipv4/tcp_memcontrol.c | |
parent | a4fe34bf902b8f709c635ab37f1f39de0b86cff2 (diff) |
tcp_memcontrol: Kill struct tcp_memcontrol
Replace the pointers in struct cg_proto with actual data fields and kill
struct tcp_memcontrol as it is not fully redundant.
This removes a confusing, unnecessary layer of abstraction.
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/tcp_memcontrol.c')
-rw-r--r-- | net/ipv4/tcp_memcontrol.c | 61 |
1 files changed, 18 insertions, 43 deletions
diff --git a/net/ipv4/tcp_memcontrol.c b/net/ipv4/tcp_memcontrol.c index 86feaa0d6d70..03e9154f7e68 100644 --- a/net/ipv4/tcp_memcontrol.c +++ b/net/ipv4/tcp_memcontrol.c | |||
@@ -6,15 +6,10 @@ | |||
6 | #include <linux/memcontrol.h> | 6 | #include <linux/memcontrol.h> |
7 | #include <linux/module.h> | 7 | #include <linux/module.h> |
8 | 8 | ||
9 | static inline struct tcp_memcontrol *tcp_from_cgproto(struct cg_proto *cg_proto) | ||
10 | { | ||
11 | return container_of(cg_proto, struct tcp_memcontrol, cg_proto); | ||
12 | } | ||
13 | |||
14 | static void memcg_tcp_enter_memory_pressure(struct sock *sk) | 9 | static void memcg_tcp_enter_memory_pressure(struct sock *sk) |
15 | { | 10 | { |
16 | if (sk->sk_cgrp->memory_pressure) | 11 | if (sk->sk_cgrp->memory_pressure) |
17 | *sk->sk_cgrp->memory_pressure = 1; | 12 | sk->sk_cgrp->memory_pressure = 1; |
18 | } | 13 | } |
19 | EXPORT_SYMBOL(memcg_tcp_enter_memory_pressure); | 14 | EXPORT_SYMBOL(memcg_tcp_enter_memory_pressure); |
20 | 15 | ||
@@ -27,33 +22,24 @@ int tcp_init_cgroup(struct mem_cgroup *memcg, struct cgroup_subsys *ss) | |||
27 | */ | 22 | */ |
28 | struct res_counter *res_parent = NULL; | 23 | struct res_counter *res_parent = NULL; |
29 | struct cg_proto *cg_proto, *parent_cg; | 24 | struct cg_proto *cg_proto, *parent_cg; |
30 | struct tcp_memcontrol *tcp; | ||
31 | struct mem_cgroup *parent = parent_mem_cgroup(memcg); | 25 | struct mem_cgroup *parent = parent_mem_cgroup(memcg); |
32 | 26 | ||
33 | cg_proto = tcp_prot.proto_cgroup(memcg); | 27 | cg_proto = tcp_prot.proto_cgroup(memcg); |
34 | if (!cg_proto) | 28 | if (!cg_proto) |
35 | return 0; | 29 | return 0; |
36 | 30 | ||
37 | tcp = tcp_from_cgproto(cg_proto); | 31 | cg_proto->sysctl_mem[0] = sysctl_tcp_mem[0]; |
38 | 32 | cg_proto->sysctl_mem[1] = sysctl_tcp_mem[1]; | |
39 | tcp->tcp_prot_mem[0] = sysctl_tcp_mem[0]; | 33 | cg_proto->sysctl_mem[2] = sysctl_tcp_mem[2]; |
40 | tcp->tcp_prot_mem[1] = sysctl_tcp_mem[1]; | 34 | cg_proto->memory_pressure = 0; |
41 | tcp->tcp_prot_mem[2] = sysctl_tcp_mem[2]; | 35 | cg_proto->memcg = memcg; |
42 | tcp->tcp_memory_pressure = 0; | ||
43 | 36 | ||
44 | parent_cg = tcp_prot.proto_cgroup(parent); | 37 | parent_cg = tcp_prot.proto_cgroup(parent); |
45 | if (parent_cg) | 38 | if (parent_cg) |
46 | res_parent = parent_cg->memory_allocated; | 39 | res_parent = &parent_cg->memory_allocated; |
47 | |||
48 | res_counter_init(&tcp->tcp_memory_allocated, res_parent); | ||
49 | percpu_counter_init(&tcp->tcp_sockets_allocated, 0); | ||
50 | 40 | ||
51 | cg_proto->enter_memory_pressure = memcg_tcp_enter_memory_pressure; | 41 | res_counter_init(&cg_proto->memory_allocated, res_parent); |
52 | cg_proto->memory_pressure = &tcp->tcp_memory_pressure; | 42 | percpu_counter_init(&cg_proto->sockets_allocated, 0); |
53 | cg_proto->sysctl_mem = tcp->tcp_prot_mem; | ||
54 | cg_proto->memory_allocated = &tcp->tcp_memory_allocated; | ||
55 | cg_proto->sockets_allocated = &tcp->tcp_sockets_allocated; | ||
56 | cg_proto->memcg = memcg; | ||
57 | 43 | ||
58 | return 0; | 44 | return 0; |
59 | } | 45 | } |
@@ -62,20 +48,17 @@ EXPORT_SYMBOL(tcp_init_cgroup); | |||
62 | void tcp_destroy_cgroup(struct mem_cgroup *memcg) | 48 | void tcp_destroy_cgroup(struct mem_cgroup *memcg) |
63 | { | 49 | { |
64 | struct cg_proto *cg_proto; | 50 | struct cg_proto *cg_proto; |
65 | struct tcp_memcontrol *tcp; | ||
66 | 51 | ||
67 | cg_proto = tcp_prot.proto_cgroup(memcg); | 52 | cg_proto = tcp_prot.proto_cgroup(memcg); |
68 | if (!cg_proto) | 53 | if (!cg_proto) |
69 | return; | 54 | return; |
70 | 55 | ||
71 | tcp = tcp_from_cgproto(cg_proto); | 56 | percpu_counter_destroy(&cg_proto->sockets_allocated); |
72 | percpu_counter_destroy(&tcp->tcp_sockets_allocated); | ||
73 | } | 57 | } |
74 | EXPORT_SYMBOL(tcp_destroy_cgroup); | 58 | EXPORT_SYMBOL(tcp_destroy_cgroup); |
75 | 59 | ||
76 | static int tcp_update_limit(struct mem_cgroup *memcg, u64 val) | 60 | static int tcp_update_limit(struct mem_cgroup *memcg, u64 val) |
77 | { | 61 | { |
78 | struct tcp_memcontrol *tcp; | ||
79 | struct cg_proto *cg_proto; | 62 | struct cg_proto *cg_proto; |
80 | u64 old_lim; | 63 | u64 old_lim; |
81 | int i; | 64 | int i; |
@@ -88,16 +71,14 @@ static int tcp_update_limit(struct mem_cgroup *memcg, u64 val) | |||
88 | if (val > RES_COUNTER_MAX) | 71 | if (val > RES_COUNTER_MAX) |
89 | val = RES_COUNTER_MAX; | 72 | val = RES_COUNTER_MAX; |
90 | 73 | ||
91 | tcp = tcp_from_cgproto(cg_proto); | 74 | old_lim = res_counter_read_u64(&cg_proto->memory_allocated, RES_LIMIT); |
92 | 75 | ret = res_counter_set_limit(&cg_proto->memory_allocated, val); | |
93 | old_lim = res_counter_read_u64(&tcp->tcp_memory_allocated, RES_LIMIT); | ||
94 | ret = res_counter_set_limit(&tcp->tcp_memory_allocated, val); | ||
95 | if (ret) | 76 | if (ret) |
96 | return ret; | 77 | return ret; |
97 | 78 | ||
98 | for (i = 0; i < 3; i++) | 79 | for (i = 0; i < 3; i++) |
99 | tcp->tcp_prot_mem[i] = min_t(long, val >> PAGE_SHIFT, | 80 | cg_proto->sysctl_mem[i] = min_t(long, val >> PAGE_SHIFT, |
100 | sysctl_tcp_mem[i]); | 81 | sysctl_tcp_mem[i]); |
101 | 82 | ||
102 | if (val == RES_COUNTER_MAX) | 83 | if (val == RES_COUNTER_MAX) |
103 | clear_bit(MEMCG_SOCK_ACTIVE, &cg_proto->flags); | 84 | clear_bit(MEMCG_SOCK_ACTIVE, &cg_proto->flags); |
@@ -154,28 +135,24 @@ static int tcp_cgroup_write(struct cgroup_subsys_state *css, struct cftype *cft, | |||
154 | 135 | ||
155 | static u64 tcp_read_stat(struct mem_cgroup *memcg, int type, u64 default_val) | 136 | static u64 tcp_read_stat(struct mem_cgroup *memcg, int type, u64 default_val) |
156 | { | 137 | { |
157 | struct tcp_memcontrol *tcp; | ||
158 | struct cg_proto *cg_proto; | 138 | struct cg_proto *cg_proto; |
159 | 139 | ||
160 | cg_proto = tcp_prot.proto_cgroup(memcg); | 140 | cg_proto = tcp_prot.proto_cgroup(memcg); |
161 | if (!cg_proto) | 141 | if (!cg_proto) |
162 | return default_val; | 142 | return default_val; |
163 | 143 | ||
164 | tcp = tcp_from_cgproto(cg_proto); | 144 | return res_counter_read_u64(&cg_proto->memory_allocated, type); |
165 | return res_counter_read_u64(&tcp->tcp_memory_allocated, type); | ||
166 | } | 145 | } |
167 | 146 | ||
168 | static u64 tcp_read_usage(struct mem_cgroup *memcg) | 147 | static u64 tcp_read_usage(struct mem_cgroup *memcg) |
169 | { | 148 | { |
170 | struct tcp_memcontrol *tcp; | ||
171 | struct cg_proto *cg_proto; | 149 | struct cg_proto *cg_proto; |
172 | 150 | ||
173 | cg_proto = tcp_prot.proto_cgroup(memcg); | 151 | cg_proto = tcp_prot.proto_cgroup(memcg); |
174 | if (!cg_proto) | 152 | if (!cg_proto) |
175 | return atomic_long_read(&tcp_memory_allocated) << PAGE_SHIFT; | 153 | return atomic_long_read(&tcp_memory_allocated) << PAGE_SHIFT; |
176 | 154 | ||
177 | tcp = tcp_from_cgproto(cg_proto); | 155 | return res_counter_read_u64(&cg_proto->memory_allocated, RES_USAGE); |
178 | return res_counter_read_u64(&tcp->tcp_memory_allocated, RES_USAGE); | ||
179 | } | 156 | } |
180 | 157 | ||
181 | static u64 tcp_cgroup_read(struct cgroup_subsys_state *css, struct cftype *cft) | 158 | static u64 tcp_cgroup_read(struct cgroup_subsys_state *css, struct cftype *cft) |
@@ -203,21 +180,19 @@ static u64 tcp_cgroup_read(struct cgroup_subsys_state *css, struct cftype *cft) | |||
203 | static int tcp_cgroup_reset(struct cgroup_subsys_state *css, unsigned int event) | 180 | static int tcp_cgroup_reset(struct cgroup_subsys_state *css, unsigned int event) |
204 | { | 181 | { |
205 | struct mem_cgroup *memcg; | 182 | struct mem_cgroup *memcg; |
206 | struct tcp_memcontrol *tcp; | ||
207 | struct cg_proto *cg_proto; | 183 | struct cg_proto *cg_proto; |
208 | 184 | ||
209 | memcg = mem_cgroup_from_css(css); | 185 | memcg = mem_cgroup_from_css(css); |
210 | cg_proto = tcp_prot.proto_cgroup(memcg); | 186 | cg_proto = tcp_prot.proto_cgroup(memcg); |
211 | if (!cg_proto) | 187 | if (!cg_proto) |
212 | return 0; | 188 | return 0; |
213 | tcp = tcp_from_cgproto(cg_proto); | ||
214 | 189 | ||
215 | switch (event) { | 190 | switch (event) { |
216 | case RES_MAX_USAGE: | 191 | case RES_MAX_USAGE: |
217 | res_counter_reset_max(&tcp->tcp_memory_allocated); | 192 | res_counter_reset_max(&cg_proto->memory_allocated); |
218 | break; | 193 | break; |
219 | case RES_FAILCNT: | 194 | case RES_FAILCNT: |
220 | res_counter_reset_failcnt(&tcp->tcp_memory_allocated); | 195 | res_counter_reset_failcnt(&cg_proto->memory_allocated); |
221 | break; | 196 | break; |
222 | } | 197 | } |
223 | 198 | ||