]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
net: tcp_memcontrol: protect all tcp_memcontrol calls by jump-label
authorJohannes Weiner <hannes@cmpxchg.org>
Thu, 14 Jan 2016 23:21:05 +0000 (15:21 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 15 Jan 2016 00:00:49 +0000 (16:00 -0800)
Move the jump-label from sock_update_memcg() and sock_release_memcg() to
the callsite, and so eliminate those function calls when socket
accounting is not enabled.

This also eliminates the need for dummy functions because the calls will
be optimized away if the Kconfig options are not enabled.

Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: David S. Miller <davem@davemloft.net>
Reviewed-by: Vladimir Davydov <vdavydov@virtuozzo.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/memcontrol.h
mm/memcontrol.c
net/core/sock.c
net/ipv4/tcp.c
net/ipv4/tcp_ipv4.c

index d0c724f53691e9de36a8959331271e7989764f88..85c437b0cbc0a96292e57bd5ff0e23af16f79aed 100644 (file)
@@ -694,17 +694,8 @@ static inline void mem_cgroup_wb_stats(struct bdi_writeback *wb,
 #endif /* CONFIG_CGROUP_WRITEBACK */
 
 struct sock;
-#if defined(CONFIG_INET) && defined(CONFIG_MEMCG_KMEM)
 void sock_update_memcg(struct sock *sk);
 void sock_release_memcg(struct sock *sk);
-#else
-static inline void sock_update_memcg(struct sock *sk)
-{
-}
-static inline void sock_release_memcg(struct sock *sk)
-{
-}
-#endif /* CONFIG_INET && CONFIG_MEMCG_KMEM */
 
 #ifdef CONFIG_MEMCG_KMEM
 extern struct static_key memcg_kmem_enabled_key;
index 44ed2dee8f0cdafaf0b6b2469fa1817eab22d9ca..d9344dad207e0941f63060137a4effbf12daa76b 100644 (file)
@@ -293,46 +293,40 @@ static inline struct mem_cgroup *mem_cgroup_from_id(unsigned short id)
 
 void sock_update_memcg(struct sock *sk)
 {
-       if (mem_cgroup_sockets_enabled) {
-               struct mem_cgroup *memcg;
-               struct cg_proto *cg_proto;
+       struct mem_cgroup *memcg;
+       struct cg_proto *cg_proto;
 
-               BUG_ON(!sk->sk_prot->proto_cgroup);
+       BUG_ON(!sk->sk_prot->proto_cgroup);
 
-               /* Socket cloning can throw us here with sk_cgrp already
-                * filled. It won't however, necessarily happen from
-                * process context. So the test for root memcg given
-                * the current task's memcg won't help us in this case.
-                *
-                * Respecting the original socket's memcg is a better
-                * decision in this case.
-                */
-               if (sk->sk_cgrp) {
-                       BUG_ON(mem_cgroup_is_root(sk->sk_cgrp->memcg));
-                       css_get(&sk->sk_cgrp->memcg->css);
-                       return;
-               }
+       /* Socket cloning can throw us here with sk_cgrp already
+        * filled. It won't however, necessarily happen from
+        * process context. So the test for root memcg given
+        * the current task's memcg won't help us in this case.
+        *
+        * Respecting the original socket's memcg is a better
+        * decision in this case.
+        */
+       if (sk->sk_cgrp) {
+               BUG_ON(mem_cgroup_is_root(sk->sk_cgrp->memcg));
+               css_get(&sk->sk_cgrp->memcg->css);
+               return;
+       }
 
-               rcu_read_lock();
-               memcg = mem_cgroup_from_task(current);
-               cg_proto = sk->sk_prot->proto_cgroup(memcg);
-               if (cg_proto && cg_proto->active &&
-                   css_tryget_online(&memcg->css)) {
-                       sk->sk_cgrp = cg_proto;
-               }
-               rcu_read_unlock();
+       rcu_read_lock();
+       memcg = mem_cgroup_from_task(current);
+       cg_proto = sk->sk_prot->proto_cgroup(memcg);
+       if (cg_proto && cg_proto->active &&
+           css_tryget_online(&memcg->css)) {
+               sk->sk_cgrp = cg_proto;
        }
+       rcu_read_unlock();
 }
 EXPORT_SYMBOL(sock_update_memcg);
 
 void sock_release_memcg(struct sock *sk)
 {
-       if (mem_cgroup_sockets_enabled && sk->sk_cgrp) {
-               struct mem_cgroup *memcg;
-               WARN_ON(!sk->sk_cgrp->memcg);
-               memcg = sk->sk_cgrp->memcg;
-               css_put(&sk->sk_cgrp->memcg->css);
-       }
+       WARN_ON(!sk->sk_cgrp->memcg);
+       css_put(&sk->sk_cgrp->memcg->css);
 }
 
 struct cg_proto *tcp_proto_cgroup(struct mem_cgroup *memcg)
index 51270238e269290549f9f6e0eb37f660ec533890..6c5dab01105bb384fd304327776214382380934d 100644 (file)
@@ -1507,12 +1507,6 @@ void sk_free(struct sock *sk)
 }
 EXPORT_SYMBOL(sk_free);
 
-static void sk_update_clone(const struct sock *sk, struct sock *newsk)
-{
-       if (mem_cgroup_sockets_enabled && sk->sk_cgrp)
-               sock_update_memcg(newsk);
-}
-
 /**
  *     sk_clone_lock - clone a socket, and lock its clone
  *     @sk: the socket to clone
@@ -1607,7 +1601,8 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority)
                sk_set_socket(newsk, NULL);
                newsk->sk_wq = NULL;
 
-               sk_update_clone(sk, newsk);
+               if (mem_cgroup_sockets_enabled && sk->sk_cgrp)
+                       sock_update_memcg(newsk);
 
                if (newsk->sk_prot->sockets_allocated)
                        sk_sockets_allocated_inc(newsk);
index 7bb1b091efd17e12cf574b5e874428aa4590336a..fd17eec9352517f68b86fcd08bf5b215bfa6fa46 100644 (file)
@@ -422,7 +422,8 @@ void tcp_init_sock(struct sock *sk)
        sk->sk_rcvbuf = sysctl_tcp_rmem[1];
 
        local_bh_disable();
-       sock_update_memcg(sk);
+       if (mem_cgroup_sockets_enabled)
+               sock_update_memcg(sk);
        sk_sockets_allocated_inc(sk);
        local_bh_enable();
 }
index 65947c1f4733a109b2f57b9c1e929b595ac9c5c7..eb39e02899e58e2eb249f177bec36d5f17710e33 100644 (file)
@@ -1818,7 +1818,9 @@ void tcp_v4_destroy_sock(struct sock *sk)
        tcp_saved_syn_free(tp);
 
        sk_sockets_allocated_dec(sk);
-       sock_release_memcg(sk);
+
+       if (mem_cgroup_sockets_enabled && sk->sk_cgrp)
+               sock_release_memcg(sk);
 }
 EXPORT_SYMBOL(tcp_v4_destroy_sock);