skbuff: optimize the pull_pages code in __pskb_pull_tail()
Subsystems (2)
PATCH 1/1 skbuff: optimize the pull_pages code in __pskb_pull_tail()
In the pull_pages code block, if the first frag size > eat, we can end the loop in advance to avoid extra copy.
--- net/core/skbuff.c | 4 ++++ 1 file changed, 4 insertions(+)
net/core/skbuff.c +4 -0
@@ -1720,6 +1720,10 @@ void *__pskb_pull_tail(struct sk_buff *skb, int delta)skb_shinfo (skb)->frags[k].page_offset += eat;skb_frag_size_sub (&skb_shinfo (skb)->frags[k], eat); eat =0 ; +if (!i) { + k =skb_shinfo (skb)->nr_frags; +break ; + } } k++; }
Signature · 1 line
1.8.3.1
Quoted 13 lines · Lin Zhang
In the
pull_pagescode block, if the first frag size > eat, we can end the loop in advance to avoid extra copy.Signed-off-by Lin Zhang <[email protected]>--- net/core/skbuff.c | 4 ++++ 1 file changed, 4 insertions(+)net/core/skbuff.c +0
-0
net/core/skbuff.c void *__pskb_pull_tail(struct sk_buff *skb, int delta) · line 1729
Quoted 10 lines
net/core/skbuff.c +4
-0@@ -1720,6 +1720,10 @@ void *__pskb_pull_tail(struct sk_buff *skb, int delta)skb_shinfo (skb)->frags[k].page_offset += eat;skb_frag_size_sub (&skb_shinfo (skb)->frags[k], eat); eat =0 ; +if (!i) { + k =skb_shinfo (skb)->nr_frags; +break ; + } } k++; }
-CC lkml (no need to spam lkml for netdev patches )
Why even reading skb_shinfo(skb)->nr_frags to write it again ?
I would use something like :
net/core/skbuff.c +3 -1
@@ -1719,13 +1719,15 @@ 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++; } }skb_shinfo (skb)->nr_frags = k; - +end: skb->tail += delta; skb->data_len -= delta;
2017-07-17 15:32 GMT+08:00 Eric Dumazet <[email protected]>:
Quoted 46 lines · Lin Zhang
Quoted 13 lines
In the
pull_pagescode block, if the first frag size > eat, we can end the loop in advance to avoid extra copy.Signed-off-by Lin Zhang <[email protected]>--- net/core/skbuff.c | 4 ++++ 1 file changed, 4 insertions(+)net/core/skbuff.c +0
-0net/core/skbuff.c void *__pskb_pull_tail(struct sk_buff *skb, int delta) · line 1729
Quoted 10 lines
net/core/skbuff.c +4
-0@@ -1720,6 +1720,10 @@ void *__pskb_pull_tail(struct sk_buff *skb, int delta)skb_shinfo (skb)->frags[k].page_offset += eat;skb_frag_size_sub (&skb_shinfo (skb)->frags[k], eat); eat =0 ; +if (!i) { + k =skb_shinfo (skb)->nr_frags; +break ; + } } k++; }-CC lkml (no need to spam lkml for netdev patches )
Why even reading skb_shinfo(skb)->nr_frags to write it again ?
I would use something like :
net/core/skbuff.c +2
-0@@ -1719,13 +1719,15 @@ 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 ;
net/core/skbuff.c void *__pskb_pull_tail(struct sk_buff *skb, int delta) · line 1733
Quoted 10 lines
net/core/skbuff.c +1
-1} k++; } }skb_shinfo (skb)->nr_frags = k; - +end: skb->tail += delta; skb->data_len -= delta;
Yes, this change it is looks like better than me. :)
Signature · 1 line
Lin Zhang