All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] tcp: generalize MAX_TCP_HEADER usage
@ 2014-03-27 20:19 Eric Dumazet
  2014-03-29 21:56 ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2014-03-27 20:19 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

From: Eric Dumazet <edumazet@google.com>

There are a lot of call sites in TCP stack assuming maximal size of
headers is MAX_TCP_HEADER.

Both IPv6 and IPv4 share same max_header, so we can avoid some picky
usages in TCP stack and use a constant.

In tcp_xmit_size_goal() for example we do not care if we reserve 100
extra bytes, this has little/no impact on the max number of segments per
GSO packet. (Note that sk_stream_alloc_skb() uses MAX_TCP_HEADER
anyway...)

tcp_connect() do not need to allocate 15 bytes more than MAX_TCP_HEADER,
it is cooking a SYN packet without payload.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/ipv4/tcp.c        |   12 ++++--------
 net/ipv4/tcp_output.c |    3 +--
 2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 4bd6d52eeffb..c5a3c0876e80 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -802,10 +802,10 @@ struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp)
 	/* The TCP header must be at least 32-bit aligned.  */
 	size = ALIGN(size, 4);
 
-	skb = alloc_skb_fclone(size + sk->sk_prot->max_header, gfp);
+	skb = alloc_skb_fclone(size + MAX_TCP_HEADER, gfp);
 	if (skb) {
 		if (sk_wmem_schedule(sk, skb->truesize)) {
-			skb_reserve(skb, sk->sk_prot->max_header);
+			skb_reserve(skb, MAX_TCP_HEADER);
 			/*
 			 * Make sure that we have exactly size bytes
 			 * available to the caller, no more, no less.
@@ -830,12 +830,8 @@ static unsigned int tcp_xmit_size_goal(struct sock *sk, u32 mss_now,
 	xmit_size_goal = mss_now;
 
 	if (large_allowed && sk_can_gso(sk)) {
-		u32 gso_size, hlen;
-
-		/* Maybe we should/could use sk->sk_prot->max_header here ? */
-		hlen = inet_csk(sk)->icsk_af_ops->net_header_len +
-		       inet_csk(sk)->icsk_ext_hdr_len +
-		       tp->tcp_header_len;
+		const u32 hlen = MAX_TCP_HEADER;
+		u32 gso_size;
 
 		/* Goal is to send at least one packet per ms,
 		 * not one big TSO packet every 100 ms.
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 699fb102e971..b528dea70392 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -3023,11 +3023,10 @@ int tcp_connect(struct sock *sk)
 		return 0;
 	}
 
-	buff = alloc_skb_fclone(MAX_TCP_HEADER + 15, sk->sk_allocation);
+	buff = alloc_skb_fclone(MAX_TCP_HEADER, sk->sk_allocation);
 	if (unlikely(buff == NULL))
 		return -ENOBUFS;
 
-	/* Reserve space for headers. */
 	skb_reserve(buff, MAX_TCP_HEADER);
 
 	tcp_init_nondata_skb(buff, tp->write_seq++, TCPHDR_SYN);

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

* Re: [PATCH net-next] tcp: generalize MAX_TCP_HEADER usage
  2014-03-27 20:19 [PATCH net-next] tcp: generalize MAX_TCP_HEADER usage Eric Dumazet
@ 2014-03-29 21:56 ` David Miller
  2014-03-29 22:47   ` Eric Dumazet
  0 siblings, 1 reply; 3+ messages in thread
From: David Miller @ 2014-03-29 21:56 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Thu, 27 Mar 2014 13:19:06 -0700

> (Note that sk_stream_alloc_skb() uses MAX_TCP_HEADER anyway...)

But only after your changes.

Please make this clear in the commit message, I had to go check to see
if there were in fact MAX_TCP_HEADER uses in sk_stream_alloc_skb in
the current tree.

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

* Re: [PATCH net-next] tcp: generalize MAX_TCP_HEADER usage
  2014-03-29 21:56 ` David Miller
@ 2014-03-29 22:47   ` Eric Dumazet
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2014-03-29 22:47 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

On Sat, 2014-03-29 at 17:56 -0400, David Miller wrote:
> From: Eric Dumazet <eric.dumazet@gmail.com>
> Date: Thu, 27 Mar 2014 13:19:06 -0700
> 
> > (Note that sk_stream_alloc_skb() uses MAX_TCP_HEADER anyway...)
> 
> But only after your changes.
> 
> Please make this clear in the commit message, I had to go check to see
> if there were in fact MAX_TCP_HEADER uses in sk_stream_alloc_skb in
> the current tree.

Yeah, lets leave sk_stream_alloc_skb() as it is (even it is only used by
TCP).

What I meant is that sk_stream_alloc_skb() uses MAX_TCP_HEADER (for
TCP), so tcp_xmit_size_goal() should not be picky.

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

end of thread, other threads:[~2014-03-29 22:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-27 20:19 [PATCH net-next] tcp: generalize MAX_TCP_HEADER usage Eric Dumazet
2014-03-29 21:56 ` David Miller
2014-03-29 22:47   ` Eric Dumazet

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.