[net-next,v2,resubmit] skbuff: optimize the pull_pages code in __pskb_pull_tail()

Message ID 1500283502-36546-1-git-send-email-xiaolou4617@gmail.com
State Accepted
Delegated to: David Miller
Headers show

Commit Message

Lin Zhang July 17, 2017, 9:25 a.m.
In the pull_pages code block, if the first frag size > eat,
we can end the loop in advance to avoid extra copy.

Signed-off-by: Lin Zhang <xiaolou4617@gmail.com>
---
v1 -> v2:
	* no need to rewrite skb_shinfo(skb)->nr_frags, per Eric Dumazet.
---
 net/core/skbuff.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Eric Dumazet July 17, 2017, 9:47 a.m. | #1
On Mon, 2017-07-17 at 17:25 +0800, Lin Zhang wrote:
> In the pull_pages code block, if the first frag size > eat,
> we can end the loop in advance to avoid extra copy.
> 
> Signed-off-by: Lin Zhang <xiaolou4617@gmail.com>

Acked-by: Eric Dumazet <edumazet@google.com>
David Miller July 17, 2017, 3:57 p.m. | #2
From: Lin Zhang <xiaolou4617@gmail.com>
Date: Mon, 17 Jul 2017 17:25:02 +0800

> In the pull_pages code block, if the first frag size > eat,
> we can end the loop in advance to avoid extra copy.
> 
> Signed-off-by: Lin Zhang <xiaolou4617@gmail.com>

Applied, thanks.

Patch

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index f990eb8..af61065 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -1719,6 +1719,8 @@  void *__pskb_pull_tail(struct sk_buff *skb, int delta)
 			if (eat) {
 				skb_shinfo(skb)->frags[k].page_offset += eat;
 				skb_frag_size_sub(&skb_shinfo(skb)->frags[k], eat);
+				if (!i)
+					goto end;
 				eat = 0;
 			}
 			k++;
@@ -1726,6 +1728,7 @@  void *__pskb_pull_tail(struct sk_buff *skb, int delta)
 	}
 	skb_shinfo(skb)->nr_frags = k;
 
+end:
 	skb->tail     += delta;
 	skb->data_len -= delta;