tcp: cleanups for linux-5.1
Subsystems (3)
cover tcp: cleanups for linux-5.1
This small patch series cleanups few things, and add a small timewait optimization for hosts not using md5.
Eric Dumazet (5):
tcp: get rid of tcp_check_send_head()
tcp: get rid of __tcp_add_write_queue_tail()
tcp: convert tcp_md5_needed to static_branch API
tcp: use tcp_md5_needed for timewait sockets
tcp: remove tcp_queue argument from tso_fragment()
include/net/tcp.h | 17 +++-------------- net/ipv4/tcp.c | 5 +++-- net/ipv4/tcp_ipv4.c | 2 +- net/ipv4/tcp_minisocks.c | 21 +++++++++++++-------- net/ipv4/tcp_output.c | 17 ++++++++--------- 5 files changed, 28 insertions(+), 34 deletions(-)
Signature · 1 line
2.21.0.rc2.261.ga7da99ff1b-goog
PATCH 1/5 tcp: get rid of tcp_check_send_head()
This helper is used only once, and its name is no longer relevant.
--- include/net/tcp.h | 6 ------ net/ipv4/tcp.c | 3 ++- 2 files changed, 2 insertions(+), 7 deletions(-)
include/net/tcp.h +0 -6
@@ -1716,12 +1716,6 @@ static inline bool tcp_rtx_and_write_queues_empty(const struct sock *sk)return tcp_rtx_queue_empty (sk) &&tcp_write_queue_empty (sk); } -static inline void tcp_check_send_head (struct sock *sk,struct sk_buff *skb_unlinked) -{ -if (tcp_write_queue_empty (sk)) -tcp_chrono_stop (sk,TCP_CHRONO_BUSY ); -} -static inline void __tcp_add_write_queue_tail (struct sock *sk,struct sk_buff *skb) {__skb_queue_tail (&sk->sk_write_queue, skb);
net/ipv4/tcp.c +2 -1
@@ -1412,7 +1412,8 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)/* It is the one place in all of TCP, except connection * reset, where we can be unlinking the send_head. */ -tcp_check_send_head (sk, skb); +if (tcp_write_queue_empty (sk)) +tcp_chrono_stop (sk,TCP_CHRONO_BUSY );sk_wmem_free_skb (sk, skb); }
Signature · 1 line
2.21.0.rc2.261.ga7da99ff1b-goog
PATCH 2/5 tcp: get rid of __tcp_add_write_queue_tail()
In reply to Eric DumazetThis helper is only used from tcp_add_write_queue_tail(), and does not make the code more readable.
--- include/net/tcp.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
include/net/tcp.h +1 -6
@@ -1716,14 +1716,9 @@ static inline bool tcp_rtx_and_write_queues_empty(const struct sock *sk)return tcp_rtx_queue_empty (sk) &&tcp_write_queue_empty (sk); } -static inline void __tcp_add_write_queue_tail (struct sock *sk,struct sk_buff *skb) -{ -__skb_queue_tail (&sk->sk_write_queue, skb); -} -static inline void tcp_add_write_queue_tail (struct sock *sk,struct sk_buff *skb) { -__tcp_add_write_queue_tail (sk, skb); +__skb_queue_tail (&sk->sk_write_queue, skb);/* Queue it, remembering where we must start sending. */ if (sk->sk_write_queue.next == skb)
Signature · 1 line
2.21.0.rc2.261.ga7da99ff1b-goog
PATCH 3/5 tcp: convert tcp_md5_needed to static_branch API
In reply to Eric DumazetWe prefer static_branch_unlikely() over static_key_false() these days.
--- include/net/tcp.h | 4 ++-- net/ipv4/tcp.c | 2 +- net/ipv4/tcp_ipv4.c | 2 +- net/ipv4/tcp_output.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-)
include/net/tcp.h +2 -2
@@ -1558,7 +1558,7 @@ struct tcp_md5sig_key *tcp_v4_md5_lookup(const struct sock *sk,#ifdef CONFIG_TCP_MD5SIG #include <linux/jump_label.h> -extern struct static_key tcp_md5_needed; +extern struct static_key_false tcp_md5_needed;struct tcp_md5sig_key *__tcp_md5_do_lookup (const struct sock *sk,const union tcp_md5_addr *addr,int family);
@@ -1567,7 +1567,7 @@ tcp_md5_do_lookup(const struct sock *sk, const union tcp_md5_addr *addr, int family) { - if (!static_key_false(&tcp_md5_needed)) + if (!static_branch_unlikely(&tcp_md5_needed)) return NULL;return __tcp_md5_do_lookup (sk, addr, family); }
net/ipv4/tcp.c +1 -1
@@ -3699,7 +3699,7 @@ bool tcp_alloc_md5sig_pool(void)if (!tcp_md5sig_pool_populated) {__tcp_alloc_md5sig_pool ();if (tcp_md5sig_pool_populated) -static_key_slow_inc (&tcp_md5_needed); +static_branch_inc (&tcp_md5_needed); }mutex_unlock (&tcp_md5sig_mutex);
net/ipv4/tcp_ipv4.c +1 -1
@@ -973,7 +973,7 @@ static void tcp_v4_reqsk_destructor(struct request_sock *req)* We need to maintain these in the sk structure. */ -struct static_key tcp_md5_needed__read_mostly ; +DEFINE_STATIC_KEY_FALSE (tcp_md5_needed);EXPORT_SYMBOL (tcp_md5_needed);/* Find the Key structure for an address. */
net/ipv4/tcp_output.c +2 -2
@@ -597,7 +597,7 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb, *md5 =NULL ;#ifdef CONFIG_TCP_MD5SIG -if (static_key_false (&tcp_md5_needed) && +if (static_branch_unlikely (&tcp_md5_needed) &&rcu_access_pointer (tp->md5sig_info)) { *md5 = tp->af_specific->md5_lookup (sk, sk);if (*md5) {
@@ -734,7 +734,7 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb *md5 =NULL ;#ifdef CONFIG_TCP_MD5SIG -if (static_key_false (&tcp_md5_needed) && +if (static_branch_unlikely (&tcp_md5_needed) &&rcu_access_pointer (tp->md5sig_info)) { *md5 = tp->af_specific->md5_lookup (sk, sk);if (*md5) {
Signature · 1 line
2.21.0.rc2.261.ga7da99ff1b-goog
PATCH 4/5 tcp: use tcp_md5_needed for timewait sockets
In reply to Eric DumazetThis might speedup tcp_twsk_destructor() a bit,
avoiding a cache line miss.
--- net/ipv4/tcp_minisocks.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
net/ipv4/tcp_minisocks.c +13 -8
@@ -294,12 +294,15 @@ void tcp_time_wait(struct sock *sk, int state, int timeo)* so the timewait ack generating code has the key. */ do { -struct tcp_md5sig_key *key; tcptw->tw_md5_key =NULL ; - key = tp->af_specific->md5_lookup (sk, sk); -if (key) { - tcptw->tw_md5_key =kmemdup (key,sizeof (*key),GFP_ATOMIC ); -BUG_ON (tcptw->tw_md5_key && !tcp_alloc_md5sig_pool ()); +if (static_branch_unlikely (&tcp_md5_needed)) { +struct tcp_md5sig_key *key; + + key = tp->af_specific->md5_lookup (sk, sk); +if (key) { + tcptw->tw_md5_key =kmemdup (key,sizeof (*key),GFP_ATOMIC ); +BUG_ON (tcptw->tw_md5_key && !tcp_alloc_md5sig_pool ()); + } } }while (0 );#endif
@@ -338,10 +341,12 @@ EXPORT_SYMBOL(tcp_time_wait);void tcp_twsk_destructor (struct sock *sk) {#ifdef CONFIG_TCP_MD5SIG -struct tcp_timewait_sock *twsk =tcp_twsk (sk); +if (static_branch_unlikely (&tcp_md5_needed)) { +struct tcp_timewait_sock *twsk =tcp_twsk (sk); -if (twsk->tw_md5_key) -kfree_rcu (twsk->tw_md5_key, rcu); +if (twsk->tw_md5_key) +kfree_rcu (twsk->tw_md5_key, rcu); + }#endif }EXPORT_SYMBOL_GPL (tcp_twsk_destructor);
Signature · 1 line
2.21.0.rc2.261.ga7da99ff1b-goog
PATCH 5/5 tcp: remove tcp_queue argument from tso_fragment()
In reply to Eric Dumazettso_fragment() is only called for packets still in write queue.
Remove the tcp_queue parameter to make this more obvious, even if the comment clearly states this.
--- net/ipv4/tcp_output.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
net/ipv4/tcp_output.c +6 -7
@@ -1846,17 +1846,17 @@ static bool tcp_snd_wnd_test(const struct tcp_sock *tp,* know that all the data is in scatter-gather pages, and that the * packet has never been sent out before (and thus is not cloned). */ -static int tso_fragment (struct sock *sk,enum tcp_queue tcp_queue, -struct sk_buff *skb,unsigned int len, +static int tso_fragment (struct sock *sk,struct sk_buff *skb,unsigned int len,unsigned int mss_now,gfp_t gfp) { -struct sk_buff *buff;int nlen = skb->len - len; +struct sk_buff *buff;u8 flags;/* All of a TSO frame must be composed of paged data. */ if (skb->len != skb->data_len) -return tcp_fragment (sk, tcp_queue, skb, len, mss_now, gfp); +return tcp_fragment (sk,TCP_FRAG_IN_WRITE_QUEUE , + skb, len, mss_now, gfp); buff =sk_stream_alloc_skb (sk,0 , gfp, true);if (unlikely (!buff))
@@ -1892,7 +1892,7 @@ static int tso_fragment(struct sock *sk, enum tcp_queue tcp_queue,/* Link BUFF into the send queue. */ __skb_header_release (buff); -tcp_insert_write_queue_after (skb, buff, sk, tcp_queue); +tcp_insert_write_queue_after (skb, buff, sk,TCP_FRAG_IN_WRITE_QUEUE );return 0 ; }
@@ -2391,8 +2391,7 @@ static bool tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle, nonagle);if (skb->len > limit && -unlikely (tso_fragment (sk,TCP_FRAG_IN_WRITE_QUEUE , - skb, limit, mss_now, gfp))) +unlikely (tso_fragment (sk, skb, limit, mss_now, gfp)))break ;if (tcp_small_queue_check (sk, skb,0 ))
Signature · 1 line
2.21.0.rc2.261.ga7da99ff1b-goog
David Miller
maintainerFrom: Eric Dumazet <[email protected]>
Date: Tue, 26 Feb 2019 09:49:08 -0800
Quoted 2 lines
This small patch series cleanups few things, and add a small timewait optimization for hosts not using md5.
Series applied, thanks Eric.