netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] tcp: tcp_sendmsg() page recycling
@ 2011-12-04 17:05 Eric Dumazet
  2011-12-04 17:20 ` Joe Perches
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Eric Dumazet @ 2011-12-04 17:05 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

If our TCP_PAGE(sk) is not shared (page_count() == 1), we can set page
offset to 0.

This permits better filling of the pages on small to medium tcp writes.

"tbench 16" results on my dev server (2x4x2 machine) :

Before : 3072 MB/s
After  : 3146 MB/s  (2.4 % gain)

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

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 45156be..a09fe25 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1009,7 +1009,12 @@ new_segment:
 				int merge = 0;
 				int i = skb_shinfo(skb)->nr_frags;
 				struct page *page = TCP_PAGE(sk);
-				int off = TCP_OFF(sk);
+				int off;
+
+				if (page && page_count(page) == 1)
+					TCP_OFF(sk) = 0;
+
+				off = TCP_OFF(sk);
 
 				if (skb_can_coalesce(skb, i, page, off) &&
 				    off != PAGE_SIZE) {

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

* Re: [PATCH net-next] tcp: tcp_sendmsg() page recycling
  2011-12-04 17:05 [PATCH net-next] tcp: tcp_sendmsg() page recycling Eric Dumazet
@ 2011-12-04 17:20 ` Joe Perches
  2011-12-04 18:27   ` Nicolas de Pesloüan
  2011-12-05 11:07   ` [PATCH net-next] tcp: remove TCP_OFF and TCP_PAGE macros Eric Dumazet
  2011-12-04 17:36 ` [PATCH net-next] tcp: tcp_sendmsg() page recycling Eric Dumazet
  2011-12-04 18:21 ` David Miller
  2 siblings, 2 replies; 9+ messages in thread
From: Joe Perches @ 2011-12-04 17:20 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: David Miller, netdev

On Sun, 2011-12-04 at 18:05 +0100, Eric Dumazet wrote:
> If our TCP_PAGE(sk) is not shared (page_count() == 1), we can set page
> offset to 0.
[]
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
[]
> @@ -1009,7 +1009,12 @@ new_segment:
>  				int merge = 0;
>  				int i = skb_shinfo(skb)->nr_frags;
>  				struct page *page = TCP_PAGE(sk);
> -				int off = TCP_OFF(sk);
> +				int off;
> +
> +				if (page && page_count(page) == 1)
> +					TCP_OFF(sk) = 0;
> +
> +				off = TCP_OFF(sk);

This might be clearer and take one less indirection as

				if (page && page_count(page) == 1) {
					TCP_OFF(sk) = 0;
					off = 0;
				} else {
					off = 0;
				}

or maybe

				if (page && page_count(page) == 1)
					off = TCP_OFF(sk) = 0;
				else
					off = 0;

And maybe the TCP_OFF and TCP_PAGE macros should be removed.

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

* Re: [PATCH net-next] tcp: tcp_sendmsg() page recycling
  2011-12-04 17:05 [PATCH net-next] tcp: tcp_sendmsg() page recycling Eric Dumazet
  2011-12-04 17:20 ` Joe Perches
@ 2011-12-04 17:36 ` Eric Dumazet
  2011-12-04 18:14   ` David Miller
  2011-12-04 18:21 ` David Miller
  2 siblings, 1 reply; 9+ messages in thread
From: Eric Dumazet @ 2011-12-04 17:36 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

Le dimanche 04 décembre 2011 à 18:05 +0100, Eric Dumazet a écrit :
> If our TCP_PAGE(sk) is not shared (page_count() == 1), we can set page
> offset to 0.
> 
> This permits better filling of the pages on small to medium tcp writes.
> 
> "tbench 16" results on my dev server (2x4x2 machine) :
> 
> Before : 3072 MB/s
> After  : 3146 MB/s  (2.4 % gain)

By the way current linux tree on the same machine gets 2957 MB/s

So the combination of select_size() patch and this one gives
a 6.4 % gain.

Definitely worth the pain, isnt it ?

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

* Re: [PATCH net-next] tcp: tcp_sendmsg() page recycling
  2011-12-04 17:36 ` [PATCH net-next] tcp: tcp_sendmsg() page recycling Eric Dumazet
@ 2011-12-04 18:14   ` David Miller
  0 siblings, 0 replies; 9+ messages in thread
From: David Miller @ 2011-12-04 18:14 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Sun, 04 Dec 2011 18:36:52 +0100

> Definitely worth the pain, isnt it ?

As long as such gains aren't lost in the noise when talking over
real devices.

I'm not a big fan of tbench over loopback numbers, frankly :-)

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

* Re: [PATCH net-next] tcp: tcp_sendmsg() page recycling
  2011-12-04 17:05 [PATCH net-next] tcp: tcp_sendmsg() page recycling Eric Dumazet
  2011-12-04 17:20 ` Joe Perches
  2011-12-04 17:36 ` [PATCH net-next] tcp: tcp_sendmsg() page recycling Eric Dumazet
@ 2011-12-04 18:21 ` David Miller
  2 siblings, 0 replies; 9+ messages in thread
From: David Miller @ 2011-12-04 18:21 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Sun, 04 Dec 2011 18:05:17 +0100

> If our TCP_PAGE(sk) is not shared (page_count() == 1), we can set page
> offset to 0.
> 
> This permits better filling of the pages on small to medium tcp writes.
> 
> "tbench 16" results on my dev server (2x4x2 machine) :
> 
> Before : 3072 MB/s
> After  : 3146 MB/s  (2.4 % gain)
> 
> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>

Applied.

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

* Re: [PATCH net-next] tcp: tcp_sendmsg() page recycling
  2011-12-04 17:20 ` Joe Perches
@ 2011-12-04 18:27   ` Nicolas de Pesloüan
  2011-12-04 18:54     ` Joe Perches
  2011-12-05 11:07   ` [PATCH net-next] tcp: remove TCP_OFF and TCP_PAGE macros Eric Dumazet
  1 sibling, 1 reply; 9+ messages in thread
From: Nicolas de Pesloüan @ 2011-12-04 18:27 UTC (permalink / raw)
  To: Joe Perches; +Cc: Eric Dumazet, David Miller, netdev

Le 04/12/2011 18:20, Joe Perches a écrit :
> On Sun, 2011-12-04 at 18:05 +0100, Eric Dumazet wrote:
>> If our TCP_PAGE(sk) is not shared (page_count() == 1), we can set page
>> offset to 0.
> []
>> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> []
>> @@ -1009,7 +1009,12 @@ new_segment:
>>   				int merge = 0;
>>   				int i = skb_shinfo(skb)->nr_frags;
>>   				struct page *page = TCP_PAGE(sk);
>> -				int off = TCP_OFF(sk);
>> +				int off;
>> +
>> +				if (page&&  page_count(page) == 1)
>> +					TCP_OFF(sk) = 0;
>> +
>> +				off = TCP_OFF(sk);
>
> This might be clearer and take one less indirection as
>
> 				if (page&&  page_count(page) == 1) {
> 					TCP_OFF(sk) = 0;
> 					off = 0;
> 				} else {
> 					off = 0;
> 				}
>
> or maybe
>
> 				if (page&&  page_count(page) == 1)
> 					off = TCP_OFF(sk) = 0;
> 				else
> 					off = 0;

Well, those two fragments don't look equivalent to the original one, unless TCP_OFF(sk) happens to 
be 0 before the test. But if this is true, then the whole thing seems useless. Do I miss something?

For as far as I understand, the following should be equivalent to Eric's original, but I don't 
consider it better than the original.

  				if (page&&  page_count(page) == 1)
  					off = TCP_OFF(sk) = 0;
  				else
  					off = TCP_OFF(sk);

	Nicolas.

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

* Re: [PATCH net-next] tcp: tcp_sendmsg() page recycling
  2011-12-04 18:27   ` Nicolas de Pesloüan
@ 2011-12-04 18:54     ` Joe Perches
  0 siblings, 0 replies; 9+ messages in thread
From: Joe Perches @ 2011-12-04 18:54 UTC (permalink / raw)
  To: Nicolas de Pesloüan; +Cc: Eric Dumazet, netdev, David Miller

On Sun, 2011-12-04 at 19:27 +0100, Nicolas de Pesloüan wrote:
> Well, those two fragments don't look equivalent to the original one, unless TCP_OFF(sk) happens to 
> be 0 before the test. But if this is true, then the whole thing seems useless. Do I miss something?

Nope, you're completely correct.  It's just me not typing correctly.

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

* [PATCH net-next] tcp: remove TCP_OFF and TCP_PAGE macros
  2011-12-04 17:20 ` Joe Perches
  2011-12-04 18:27   ` Nicolas de Pesloüan
@ 2011-12-05 11:07   ` Eric Dumazet
  2011-12-05 23:47     ` David Miller
  1 sibling, 1 reply; 9+ messages in thread
From: Eric Dumazet @ 2011-12-05 11:07 UTC (permalink / raw)
  To: Joe Perches; +Cc: David Miller, netdev

Le dimanche 04 décembre 2011 à 09:20 -0800, Joe Perches a écrit :
> And maybe the TCP_OFF and TCP_PAGE macros should be removed.
> 

Agreed, thanks.

[PATCH net-next] tcp: remove TCP_OFF and TCP_PAGE macros

As mentioned by Joe Perches, TCP_OFF() and TCP_PAGE() macros are
useless.

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

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index a09fe25..43dfccc 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -888,9 +888,6 @@ int tcp_sendpage(struct sock *sk, struct page *page, int offset,
 }
 EXPORT_SYMBOL(tcp_sendpage);
 
-#define TCP_PAGE(sk)	(sk->sk_sndmsg_page)
-#define TCP_OFF(sk)	(sk->sk_sndmsg_off)
-
 static inline int select_size(const struct sock *sk, bool sg)
 {
 	const struct tcp_sock *tp = tcp_sk(sk);
@@ -1008,13 +1005,13 @@ new_segment:
 			} else {
 				int merge = 0;
 				int i = skb_shinfo(skb)->nr_frags;
-				struct page *page = TCP_PAGE(sk);
+				struct page *page = sk->sk_sndmsg_page;
 				int off;
 
 				if (page && page_count(page) == 1)
-					TCP_OFF(sk) = 0;
+					sk->sk_sndmsg_off = 0;
 
-				off = TCP_OFF(sk);
+				off = sk->sk_sndmsg_off;
 
 				if (skb_can_coalesce(skb, i, page, off) &&
 				    off != PAGE_SIZE) {
@@ -1031,7 +1028,7 @@ new_segment:
 				} else if (page) {
 					if (off == PAGE_SIZE) {
 						put_page(page);
-						TCP_PAGE(sk) = page = NULL;
+						sk->sk_sndmsg_page = page = NULL;
 						off = 0;
 					}
 				} else
@@ -1057,9 +1054,9 @@ new_segment:
 					/* If this page was new, give it to the
 					 * socket so it does not get leaked.
 					 */
-					if (!TCP_PAGE(sk)) {
-						TCP_PAGE(sk) = page;
-						TCP_OFF(sk) = 0;
+					if (!sk->sk_sndmsg_page) {
+						sk->sk_sndmsg_page = page;
+						sk->sk_sndmsg_off = 0;
 					}
 					goto do_error;
 				}
@@ -1069,15 +1066,15 @@ new_segment:
 					skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], copy);
 				} else {
 					skb_fill_page_desc(skb, i, page, off, copy);
-					if (TCP_PAGE(sk)) {
+					if (sk->sk_sndmsg_page) {
 						get_page(page);
 					} else if (off + copy < PAGE_SIZE) {
 						get_page(page);
-						TCP_PAGE(sk) = page;
+						sk->sk_sndmsg_page = page;
 					}
 				}
 
-				TCP_OFF(sk) = off + copy;
+				sk->sk_sndmsg_off = off + copy;
 			}
 
 			if (!copied)

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

* Re: [PATCH net-next] tcp: remove TCP_OFF and TCP_PAGE macros
  2011-12-05 11:07   ` [PATCH net-next] tcp: remove TCP_OFF and TCP_PAGE macros Eric Dumazet
@ 2011-12-05 23:47     ` David Miller
  0 siblings, 0 replies; 9+ messages in thread
From: David Miller @ 2011-12-05 23:47 UTC (permalink / raw)
  To: eric.dumazet; +Cc: joe, netdev

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Mon, 05 Dec 2011 12:07:15 +0100

> Le dimanche 04 décembre 2011 à 09:20 -0800, Joe Perches a écrit :
>> And maybe the TCP_OFF and TCP_PAGE macros should be removed.
>> 
> 
> Agreed, thanks.
> 
> [PATCH net-next] tcp: remove TCP_OFF and TCP_PAGE macros
> 
> As mentioned by Joe Perches, TCP_OFF() and TCP_PAGE() macros are
> useless.
> 
> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>

Applied.

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

end of thread, other threads:[~2011-12-05 23:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-04 17:05 [PATCH net-next] tcp: tcp_sendmsg() page recycling Eric Dumazet
2011-12-04 17:20 ` Joe Perches
2011-12-04 18:27   ` Nicolas de Pesloüan
2011-12-04 18:54     ` Joe Perches
2011-12-05 11:07   ` [PATCH net-next] tcp: remove TCP_OFF and TCP_PAGE macros Eric Dumazet
2011-12-05 23:47     ` David Miller
2011-12-04 17:36 ` [PATCH net-next] tcp: tcp_sendmsg() page recycling Eric Dumazet
2011-12-04 18:14   ` David Miller
2011-12-04 18:21 ` 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).