aboutsummaryrefslogtreecommitdiffstats
path: root/mm/memcontrol.c
diff options
context:
space:
mode:
authorGlauber Costa <glommer@parallels.com>2012-01-05 15:16:39 -0500
committerDavid S. Miller <davem@davemloft.net>2012-01-07 13:16:34 -0500
commitf3f511e1ce6f1a6f0a5bb8320e9f802e76f6b999 (patch)
treebedb8b38bec1bdb3fa7159bc61822488984d3ce0 /mm/memcontrol.c
parent356b95424cfb456e14a59eaa579422ce014c424b (diff)
net: fix sock_clone reference mismatch with tcp memcontrol
Sockets can also be created through sock_clone. Because it copies all data in the sock structure, it also copies the memcg-related pointer, and all should be fine. However, since we now use reference counts in socket creation, we are left with some sockets that have no reference counts. It matters when we destroy them, since it leads to a mismatch. Signed-off-by: Glauber Costa <glommer@parallels.com> CC: David S. Miller <davem@davemloft.net> CC: Greg Thelen <gthelen@google.com> CC: Hiroyouki Kamezawa <kamezawa.hiroyu@jp.fujitsu.com> CC: Laurent Chavey <chavey@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'mm/memcontrol.c')
-rw-r--r--mm/memcontrol.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 94da8ee9e2c2..9c72d5d5372a 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -381,16 +381,25 @@ static void mem_cgroup_put(struct mem_cgroup *memcg);
381static bool mem_cgroup_is_root(struct mem_cgroup *memcg); 381static bool mem_cgroup_is_root(struct mem_cgroup *memcg);
382void sock_update_memcg(struct sock *sk) 382void sock_update_memcg(struct sock *sk)
383{ 383{
384 /* A socket spends its whole life in the same cgroup */
385 if (sk->sk_cgrp) {
386 WARN_ON(1);
387 return;
388 }
389 if (static_branch(&memcg_socket_limit_enabled)) { 384 if (static_branch(&memcg_socket_limit_enabled)) {
390 struct mem_cgroup *memcg; 385 struct mem_cgroup *memcg;
391 386
392 BUG_ON(!sk->sk_prot->proto_cgroup); 387 BUG_ON(!sk->sk_prot->proto_cgroup);
393 388
389 /* Socket cloning can throw us here with sk_cgrp already
390 * filled. It won't however, necessarily happen from
391 * process context. So the test for root memcg given
392 * the current task's memcg won't help us in this case.
393 *
394 * Respecting the original socket's memcg is a better
395 * decision in this case.
396 */
397 if (sk->sk_cgrp) {
398 BUG_ON(mem_cgroup_is_root(sk->sk_cgrp->memcg));
399 mem_cgroup_get(sk->sk_cgrp->memcg);
400 return;
401 }
402
394 rcu_read_lock(); 403 rcu_read_lock();
395 memcg = mem_cgroup_from_task(current); 404 memcg = mem_cgroup_from_task(current);
396 if (!mem_cgroup_is_root(memcg)) { 405 if (!mem_cgroup_is_root(memcg)) {