netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] tcp: avoid frag allocation for small frames
@ 2011-10-22 12:23 Eric Dumazet
  2011-10-24  5:53 ` David Miller
  2011-11-29  1:04 ` Vijay Subramanian
  0 siblings, 2 replies; 7+ messages in thread
From: Eric Dumazet @ 2011-10-22 12:23 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

tcp_sendmsg() uses select_size() helper to choose skb head size when a
new skb must be allocated.

If GSO is enabled for the socket, current strategy is to force all
payload data to be outside of headroom, in PAGE fragments.

This strategy is not welcome for small packets, wasting memory.

Experiments show that best results are obtained when using 2048 bytes
for skb head (This includes the skb overhead and various headers)

This patch provides better len/truesize ratios for packets sent to
loopback device, and reduce memory needs for in-flight loopback packets,
particularly on arches with big pages.

If a sender sends many 1-byte packets to an unresponsive application,
receiver rmem_alloc will grow faster and will stop queuing these packets
sooner, or will collapse its receive queue to free excess memory.

netperf -t TCP_RR results are improved by ~4 %, and many workloads are
improved as well (tbench, mysql...)

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
 net/ipv4/tcp.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 704adad..cd45b44 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -897,9 +897,12 @@ static inline int select_size(const struct sock *sk, int sg)
 	int tmp = tp->mss_cache;
 
 	if (sg) {
-		if (sk_can_gso(sk))
-			tmp = 0;
-		else {
+		if (sk_can_gso(sk)) {
+			/* Small frames wont use a full page:
+			 * Payload will immediately follow tcp header.
+			 */
+			tmp = SKB_WITH_OVERHEAD(2048 - MAX_TCP_HEADER);
+		} else {
 			int pgbreak = SKB_MAX_HEAD(MAX_TCP_HEADER);
 
 			if (tmp >= pgbreak &&

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

* Re: [PATCH net-next] tcp: avoid frag allocation for small frames
  2011-10-22 12:23 Eric Dumazet
@ 2011-10-24  5:53 ` David Miller
  2011-11-29  1:04 ` Vijay Subramanian
  1 sibling, 0 replies; 7+ messages in thread
From: David Miller @ 2011-10-24  5:53 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Sat, 22 Oct 2011 14:23:57 +0200

> tcp_sendmsg() uses select_size() helper to choose skb head size when a
> new skb must be allocated.
> 
> If GSO is enabled for the socket, current strategy is to force all
> payload data to be outside of headroom, in PAGE fragments.
> 
> This strategy is not welcome for small packets, wasting memory.
> 
> Experiments show that best results are obtained when using 2048 bytes
> for skb head (This includes the skb overhead and various headers)
> 
> This patch provides better len/truesize ratios for packets sent to
> loopback device, and reduce memory needs for in-flight loopback packets,
> particularly on arches with big pages.
> 
> If a sender sends many 1-byte packets to an unresponsive application,
> receiver rmem_alloc will grow faster and will stop queuing these packets
> sooner, or will collapse its receive queue to free excess memory.
> 
> netperf -t TCP_RR results are improved by ~4 %, and many workloads are
> improved as well (tbench, mysql...)
> 
> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>

Applied, thanks Eric.

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

* Re: [PATCH net-next] tcp: avoid frag allocation for small frames
  2011-10-22 12:23 Eric Dumazet
  2011-10-24  5:53 ` David Miller
@ 2011-11-29  1:04 ` Vijay Subramanian
  2011-11-29  7:51   ` Eric Dumazet
  1 sibling, 1 reply; 7+ messages in thread
From: Vijay Subramanian @ 2011-11-29  1:04 UTC (permalink / raw)
  To: netdev

On 22 October 2011 05:23, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> tcp_sendmsg() uses select_size() helper to choose skb head size when a
> new skb must be allocated.
>
> If GSO is enabled for the socket, current strategy is to force all
> payload data to be outside of headroom, in PAGE fragments.
>
> This strategy is not welcome for small packets, wasting memory.
>
> Experiments show that best results are obtained when using 2048 bytes
> for skb head (This includes the skb overhead and various headers)
>
> This patch provides better len/truesize ratios for packets sent to
> loopback device, and reduce memory needs for in-flight loopback packets,
> particularly on arches with big pages.
>
> If a sender sends many 1-byte packets to an unresponsive application,
> receiver rmem_alloc will grow faster and will stop queuing these packets
> sooner, or will collapse its receive queue to free excess memory.
>
> netperf -t TCP_RR results are improved by ~4 %, and many workloads are
> improved as well (tbench, mysql...)
>
> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
> ---
>  net/ipv4/tcp.c |    9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index 704adad..cd45b44 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -897,9 +897,12 @@ static inline int select_size(const struct sock *sk, int sg)
>        int tmp = tp->mss_cache;
>
>        if (sg) {
> -               if (sk_can_gso(sk))
> -                       tmp = 0;
> -               else {
> +               if (sk_can_gso(sk)) {
> +                       /* Small frames wont use a full page:
> +                        * Payload will immediately follow tcp header.
> +                        */
> +                       tmp = SKB_WITH_OVERHEAD(2048 - MAX_TCP_HEADER);
> +               } else {
>                        int pgbreak = SKB_MAX_HEAD(MAX_TCP_HEADER);
>
>                        if (tmp >= pgbreak &&
>
>



This patch from Eric fixing select_size in tcp.c was queued to be
applied but does not seem to be in net-next tree. Was this somehow
overlooked or have I missed something?

Regards,
Vijay Subramanian

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

* Re: [PATCH net-next] tcp: avoid frag allocation for small frames
  2011-11-29  1:04 ` Vijay Subramanian
@ 2011-11-29  7:51   ` Eric Dumazet
  2011-11-29  8:13     ` David Miller
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Dumazet @ 2011-11-29  7:51 UTC (permalink / raw)
  To: Vijay Subramanian; +Cc: netdev

Le lundi 28 novembre 2011 à 17:04 -0800, Vijay Subramanian a écrit :
> On 22 October 2011 05:23, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> > tcp_sendmsg() uses select_size() helper to choose skb head size when a
> > new skb must be allocated.
> >
> > If GSO is enabled for the socket, current strategy is to force all
> > payload data to be outside of headroom, in PAGE fragments.
> >
> > This strategy is not welcome for small packets, wasting memory.
> >
> > Experiments show that best results are obtained when using 2048 bytes
> > for skb head (This includes the skb overhead and various headers)
> >
> > This patch provides better len/truesize ratios for packets sent to
> > loopback device, and reduce memory needs for in-flight loopback packets,
> > particularly on arches with big pages.
> >
> > If a sender sends many 1-byte packets to an unresponsive application,
> > receiver rmem_alloc will grow faster and will stop queuing these packets
> > sooner, or will collapse its receive queue to free excess memory.
> >
> > netperf -t TCP_RR results are improved by ~4 %, and many workloads are
> > improved as well (tbench, mysql...)
> >
> > Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
> > ---
> >  net/ipv4/tcp.c |    9 ++++++---
> >  1 file changed, 6 insertions(+), 3 deletions(-)
> >
> > diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> > index 704adad..cd45b44 100644
> > --- a/net/ipv4/tcp.c
> > +++ b/net/ipv4/tcp.c
> > @@ -897,9 +897,12 @@ static inline int select_size(const struct sock *sk, int sg)
> >        int tmp = tp->mss_cache;
> >
> >        if (sg) {
> > -               if (sk_can_gso(sk))
> > -                       tmp = 0;
> > -               else {
> > +               if (sk_can_gso(sk)) {
> > +                       /* Small frames wont use a full page:
> > +                        * Payload will immediately follow tcp header.
> > +                        */
> > +                       tmp = SKB_WITH_OVERHEAD(2048 - MAX_TCP_HEADER);
> > +               } else {
> >                        int pgbreak = SKB_MAX_HEAD(MAX_TCP_HEADER);
> >
> >                        if (tmp >= pgbreak &&
> >
> >
> 
> 
> 
> This patch from Eric fixing select_size in tcp.c was queued to be
> applied but does not seem to be in net-next tree. Was this somehow
> overlooked or have I missed something?
> 

Good catch Vijay, thanks for noticing !

David, do you want me to respin this ?

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

* Re: [PATCH net-next] tcp: avoid frag allocation for small frames
  2011-11-29  7:51   ` Eric Dumazet
@ 2011-11-29  8:13     ` David Miller
  0 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2011-11-29  8:13 UTC (permalink / raw)
  To: eric.dumazet; +Cc: subramanian.vijay, netdev

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Tue, 29 Nov 2011 08:51:50 +0100

> David, do you want me to respin this ?

Please do, thank you.

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

* [PATCH net-next] tcp: avoid frag allocation for small frames
@ 2011-11-29  8:41 Eric Dumazet
  2011-11-29 18:23 ` David Miller
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Dumazet @ 2011-11-29  8:41 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, subramanian.vijay

tcp_sendmsg() uses select_size() helper to choose skb head size when a
new skb must be allocated.

If GSO is enabled for the socket, current strategy is to force all
payload data to be outside of headroom, in PAGE fragments.

This strategy is not welcome for small packets, wasting memory.

Experiments show that best results are obtained when using 2048 bytes
for skb head (This includes the skb overhead and various headers)

This patch provides better len/truesize ratios for packets sent to
loopback device, and reduce memory needs for in-flight loopback packets,
particularly on arches with big pages.

If a sender sends many 1-byte packets to an unresponsive application,
receiver rmem_alloc will grow faster and will stop queuing these packets
sooner, or will collapse its receive queue to free excess memory.

netperf -t TCP_RR results are improved by ~4 %, and many workloads are
improved as well (tbench, mysql...)

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
 net/ipv4/tcp.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 704adad..cd45b44 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -897,9 +897,12 @@ static inline int select_size(const struct sock *sk, int sg)
 	int tmp = tp->mss_cache;
 
 	if (sg) {
-		if (sk_can_gso(sk))
-			tmp = 0;
-		else {
+		if (sk_can_gso(sk)) {
+			/* Small frames wont use a full page:
+			 * Payload will immediately follow tcp header.
+			 */
+			tmp = SKB_WITH_OVERHEAD(2048 - MAX_TCP_HEADER);
+		} else {
 			int pgbreak = SKB_MAX_HEAD(MAX_TCP_HEADER);
 
 			if (tmp >= pgbreak &&

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

* Re: [PATCH net-next] tcp: avoid frag allocation for small frames
  2011-11-29  8:41 [PATCH net-next] tcp: avoid frag allocation for small frames Eric Dumazet
@ 2011-11-29 18:23 ` David Miller
  0 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2011-11-29 18:23 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev, subramanian.vijay

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Tue, 29 Nov 2011 09:41:47 +0100

> tcp_sendmsg() uses select_size() helper to choose skb head size when a
> new skb must be allocated.
> 
> If GSO is enabled for the socket, current strategy is to force all
> payload data to be outside of headroom, in PAGE fragments.
> 
> This strategy is not welcome for small packets, wasting memory.
> 
> Experiments show that best results are obtained when using 2048 bytes
> for skb head (This includes the skb overhead and various headers)
> 
> This patch provides better len/truesize ratios for packets sent to
> loopback device, and reduce memory needs for in-flight loopback packets,
> particularly on arches with big pages.
> 
> If a sender sends many 1-byte packets to an unresponsive application,
> receiver rmem_alloc will grow faster and will stop queuing these packets
> sooner, or will collapse its receive queue to free excess memory.
> 
> netperf -t TCP_RR results are improved by ~4 %, and many workloads are
> improved as well (tbench, mysql...)
> 
> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>

Applied.

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

end of thread, other threads:[~2011-11-29 18:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-29  8:41 [PATCH net-next] tcp: avoid frag allocation for small frames Eric Dumazet
2011-11-29 18:23 ` David Miller
  -- strict thread matches above, loose matches on Subject: below --
2011-10-22 12:23 Eric Dumazet
2011-10-24  5:53 ` David Miller
2011-11-29  1:04 ` Vijay Subramanian
2011-11-29  7:51   ` Eric Dumazet
2011-11-29  8:13     ` 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).