Commit 3d596f7b authored by Johannes Weiner's avatar Johannes Weiner Committed by Linus Torvalds

net: tcp_memcontrol: protect all tcp_memcontrol calls by jump-label

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: default avatarJohannes Weiner <hannes@cmpxchg.org>
Acked-by: default avatarDavid S. Miller <davem@davemloft.net>
Reviewed-by: default avatarVladimir Davydov <vdavydov@virtuozzo.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 931f3f4b
...@@ -694,17 +694,8 @@ static inline void mem_cgroup_wb_stats(struct bdi_writeback *wb, ...@@ -694,17 +694,8 @@ static inline void mem_cgroup_wb_stats(struct bdi_writeback *wb,
#endif /* CONFIG_CGROUP_WRITEBACK */ #endif /* CONFIG_CGROUP_WRITEBACK */
struct sock; struct sock;
#if defined(CONFIG_INET) && defined(CONFIG_MEMCG_KMEM)
void sock_update_memcg(struct sock *sk); void sock_update_memcg(struct sock *sk);
void sock_release_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 #ifdef CONFIG_MEMCG_KMEM
extern struct static_key memcg_kmem_enabled_key; extern struct static_key memcg_kmem_enabled_key;
......
...@@ -293,7 +293,6 @@ static inline struct mem_cgroup *mem_cgroup_from_id(unsigned short id) ...@@ -293,7 +293,6 @@ static inline struct mem_cgroup *mem_cgroup_from_id(unsigned short id)
void sock_update_memcg(struct sock *sk) void sock_update_memcg(struct sock *sk)
{ {
if (mem_cgroup_sockets_enabled) {
struct mem_cgroup *memcg; struct mem_cgroup *memcg;
struct cg_proto *cg_proto; struct cg_proto *cg_proto;
...@@ -321,18 +320,13 @@ void sock_update_memcg(struct sock *sk) ...@@ -321,18 +320,13 @@ void sock_update_memcg(struct sock *sk)
sk->sk_cgrp = cg_proto; sk->sk_cgrp = cg_proto;
} }
rcu_read_unlock(); rcu_read_unlock();
}
} }
EXPORT_SYMBOL(sock_update_memcg); EXPORT_SYMBOL(sock_update_memcg);
void sock_release_memcg(struct sock *sk) 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); WARN_ON(!sk->sk_cgrp->memcg);
memcg = sk->sk_cgrp->memcg;
css_put(&sk->sk_cgrp->memcg->css); css_put(&sk->sk_cgrp->memcg->css);
}
} }
struct cg_proto *tcp_proto_cgroup(struct mem_cgroup *memcg) struct cg_proto *tcp_proto_cgroup(struct mem_cgroup *memcg)
......
...@@ -1507,12 +1507,6 @@ void sk_free(struct sock *sk) ...@@ -1507,12 +1507,6 @@ void sk_free(struct sock *sk)
} }
EXPORT_SYMBOL(sk_free); 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_clone_lock - clone a socket, and lock its clone
* @sk: the socket to clone * @sk: the socket to clone
...@@ -1607,7 +1601,8 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority) ...@@ -1607,7 +1601,8 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority)
sk_set_socket(newsk, NULL); sk_set_socket(newsk, NULL);
newsk->sk_wq = 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) if (newsk->sk_prot->sockets_allocated)
sk_sockets_allocated_inc(newsk); sk_sockets_allocated_inc(newsk);
......
...@@ -422,6 +422,7 @@ void tcp_init_sock(struct sock *sk) ...@@ -422,6 +422,7 @@ void tcp_init_sock(struct sock *sk)
sk->sk_rcvbuf = sysctl_tcp_rmem[1]; sk->sk_rcvbuf = sysctl_tcp_rmem[1];
local_bh_disable(); local_bh_disable();
if (mem_cgroup_sockets_enabled)
sock_update_memcg(sk); sock_update_memcg(sk);
sk_sockets_allocated_inc(sk); sk_sockets_allocated_inc(sk);
local_bh_enable(); local_bh_enable();
......
...@@ -1818,6 +1818,8 @@ void tcp_v4_destroy_sock(struct sock *sk) ...@@ -1818,6 +1818,8 @@ void tcp_v4_destroy_sock(struct sock *sk)
tcp_saved_syn_free(tp); tcp_saved_syn_free(tp);
sk_sockets_allocated_dec(sk); sk_sockets_allocated_dec(sk);
if (mem_cgroup_sockets_enabled && sk->sk_cgrp)
sock_release_memcg(sk); sock_release_memcg(sk);
} }
EXPORT_SYMBOL(tcp_v4_destroy_sock); EXPORT_SYMBOL(tcp_v4_destroy_sock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment