netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/5] tcp: cleanups for linux-5.1
@ 2019-02-26 17:49 Eric Dumazet
  2019-02-26 17:49 ` [PATCH net-next 1/5] tcp: get rid of tcp_check_send_head() Eric Dumazet
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Eric Dumazet @ 2019-02-26 17:49 UTC (permalink / raw)
  To: David S . Miller; +Cc: netdev, Eric Dumazet, Eric Dumazet

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(-)

-- 
2.21.0.rc2.261.ga7da99ff1b-goog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next 1/5] tcp: get rid of tcp_check_send_head()
  2019-02-26 17:49 [PATCH net-next 0/5] tcp: cleanups for linux-5.1 Eric Dumazet
@ 2019-02-26 17:49 ` Eric Dumazet
  2019-02-26 17:49 ` [PATCH net-next 2/5] tcp: get rid of __tcp_add_write_queue_tail() Eric Dumazet
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Eric Dumazet @ 2019-02-26 17:49 UTC (permalink / raw)
  To: David S . Miller; +Cc: netdev, Eric Dumazet, Eric Dumazet

This helper is used only once, and its name is no longer relevant.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 include/net/tcp.h | 6 ------
 net/ipv4/tcp.c    | 3 ++-
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/include/net/tcp.h b/include/net/tcp.h
index a6e0355921e1d0cf6df3bb20fba8b3d4e9d9ef08..813042c08dc5a7438279821890439b02490391d1 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -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);
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 769508c75dce5a39bd78766d801ca01abb77f4bb..e2fa6eb9f81aa0244ea05d99e2870a3d9294673b 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -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);
 	}
 
-- 
2.21.0.rc2.261.ga7da99ff1b-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next 2/5] tcp: get rid of __tcp_add_write_queue_tail()
  2019-02-26 17:49 [PATCH net-next 0/5] tcp: cleanups for linux-5.1 Eric Dumazet
  2019-02-26 17:49 ` [PATCH net-next 1/5] tcp: get rid of tcp_check_send_head() Eric Dumazet
@ 2019-02-26 17:49 ` Eric Dumazet
  2019-02-26 17:49 ` [PATCH net-next 3/5] tcp: convert tcp_md5_needed to static_branch API Eric Dumazet
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Eric Dumazet @ 2019-02-26 17:49 UTC (permalink / raw)
  To: David S . Miller; +Cc: netdev, Eric Dumazet, Eric Dumazet

This helper is only used from tcp_add_write_queue_tail(), and does
not make the code more readable.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 include/net/tcp.h | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/include/net/tcp.h b/include/net/tcp.h
index 813042c08dc5a7438279821890439b02490391d1..d66ac76a33d1298e48bb9dcef217beaedc8a7968 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -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)
-- 
2.21.0.rc2.261.ga7da99ff1b-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next 3/5] tcp: convert tcp_md5_needed to static_branch API
  2019-02-26 17:49 [PATCH net-next 0/5] tcp: cleanups for linux-5.1 Eric Dumazet
  2019-02-26 17:49 ` [PATCH net-next 1/5] tcp: get rid of tcp_check_send_head() Eric Dumazet
  2019-02-26 17:49 ` [PATCH net-next 2/5] tcp: get rid of __tcp_add_write_queue_tail() Eric Dumazet
@ 2019-02-26 17:49 ` Eric Dumazet
  2019-02-26 17:49 ` [PATCH net-next 4/5] tcp: use tcp_md5_needed for timewait sockets Eric Dumazet
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Eric Dumazet @ 2019-02-26 17:49 UTC (permalink / raw)
  To: David S . Miller; +Cc: netdev, Eric Dumazet, Eric Dumazet

We prefer static_branch_unlikely() over static_key_false() these days.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 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(-)

diff --git a/include/net/tcp.h b/include/net/tcp.h
index d66ac76a33d1298e48bb9dcef217beaedc8a7968..68ee02523b873db037aa9d6707edb14592e763fd 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -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);
 }
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index e2fa6eb9f81aa0244ea05d99e2870a3d9294673b..ad07dd71063da09843ccfbd3e00d3f41567e1205 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -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);
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 4010ae3644f3101d01ee984c21256ca381588a3e..831d844a27ca20b52d590e17cb3eb2b2f8a697ce 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -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.  */
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index e72aa0ff5785f177eb28ba8a3e4714997e58f35b..91f5cc5a3f88953da1043d051af9c5971c6006de 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -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) {
-- 
2.21.0.rc2.261.ga7da99ff1b-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next 4/5] tcp: use tcp_md5_needed for timewait sockets
  2019-02-26 17:49 [PATCH net-next 0/5] tcp: cleanups for linux-5.1 Eric Dumazet
                   ` (2 preceding siblings ...)
  2019-02-26 17:49 ` [PATCH net-next 3/5] tcp: convert tcp_md5_needed to static_branch API Eric Dumazet
@ 2019-02-26 17:49 ` Eric Dumazet
  2019-02-26 17:49 ` [PATCH net-next 5/5] tcp: remove tcp_queue argument from tso_fragment() Eric Dumazet
  2019-02-26 21:16 ` [PATCH net-next 0/5] tcp: cleanups for linux-5.1 David Miller
  5 siblings, 0 replies; 7+ messages in thread
From: Eric Dumazet @ 2019-02-26 17:49 UTC (permalink / raw)
  To: David S . Miller; +Cc: netdev, Eric Dumazet, Eric Dumazet

This might speedup tcp_twsk_destructor() a bit,
avoiding a cache line miss.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/ipv4/tcp_minisocks.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index 182595e2d40ff5b48cd6d095d4bd97b4cb26d3c0..79900f783e0d8a713712b0bf47700f16eebab4db 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -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);
-- 
2.21.0.rc2.261.ga7da99ff1b-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next 5/5] tcp: remove tcp_queue argument from tso_fragment()
  2019-02-26 17:49 [PATCH net-next 0/5] tcp: cleanups for linux-5.1 Eric Dumazet
                   ` (3 preceding siblings ...)
  2019-02-26 17:49 ` [PATCH net-next 4/5] tcp: use tcp_md5_needed for timewait sockets Eric Dumazet
@ 2019-02-26 17:49 ` Eric Dumazet
  2019-02-26 21:16 ` [PATCH net-next 0/5] tcp: cleanups for linux-5.1 David Miller
  5 siblings, 0 replies; 7+ messages in thread
From: Eric Dumazet @ 2019-02-26 17:49 UTC (permalink / raw)
  To: David S . Miller; +Cc: netdev, Eric Dumazet, Eric Dumazet

tso_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.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/ipv4/tcp_output.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 91f5cc5a3f88953da1043d051af9c5971c6006de..4522579aaca2d24b7be61abac658a3c8cbd2b960 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -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))
-- 
2.21.0.rc2.261.ga7da99ff1b-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next 0/5] tcp: cleanups for linux-5.1
  2019-02-26 17:49 [PATCH net-next 0/5] tcp: cleanups for linux-5.1 Eric Dumazet
                   ` (4 preceding siblings ...)
  2019-02-26 17:49 ` [PATCH net-next 5/5] tcp: remove tcp_queue argument from tso_fragment() Eric Dumazet
@ 2019-02-26 21:16 ` David Miller
  5 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2019-02-26 21:16 UTC (permalink / raw)
  To: edumazet; +Cc: netdev, eric.dumazet

From: Eric Dumazet <edumazet@google.com>
Date: Tue, 26 Feb 2019 09:49:08 -0800

> This small patch series cleanups few things, and add a small
> timewait optimization for hosts not using md5.

Series applied, thanks Eric.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-02-26 21:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-26 17:49 [PATCH net-next 0/5] tcp: cleanups for linux-5.1 Eric Dumazet
2019-02-26 17:49 ` [PATCH net-next 1/5] tcp: get rid of tcp_check_send_head() Eric Dumazet
2019-02-26 17:49 ` [PATCH net-next 2/5] tcp: get rid of __tcp_add_write_queue_tail() Eric Dumazet
2019-02-26 17:49 ` [PATCH net-next 3/5] tcp: convert tcp_md5_needed to static_branch API Eric Dumazet
2019-02-26 17:49 ` [PATCH net-next 4/5] tcp: use tcp_md5_needed for timewait sockets Eric Dumazet
2019-02-26 17:49 ` [PATCH net-next 5/5] tcp: remove tcp_queue argument from tso_fragment() Eric Dumazet
2019-02-26 21:16 ` [PATCH net-next 0/5] tcp: cleanups for linux-5.1 David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).