net: introduce skb_coalesce_rx_frag()
Subsystems (4)
PATCH 1/2 net: introduce skb_coalesce_rx_frag()
Sometimes we need to coalesce the rx frags to avoid frag list. One example is virtio-net driver which tries to use small frags for both MTU sized packet and GSO packet. So this patch introduce skb_coalesce_rx_frag() to do this.
--- include/linux/skbuff.h | 3 +++ net/core/skbuff.c | 13 +++++++++++++ 2 files changed, 16 insertions(+)
include/linux/skbuff.h +3 -0
@@ -1372,6 +1372,9 @@ static inline void skb_fill_page_desc(struct sk_buff *skb, int i,void skb_add_rx_frag (struct sk_buff *skb,int i,struct page *page,int off,int size,unsigned int truesize); +void skb_coalesce_rx_frag (struct sk_buff *skb,int i,int off,int size, +unsigned int truesize); +#define SKB_PAGE_ASSERT (skb) BUG_ON(skb_shinfo(skb)->nr_frags)#define SKB_FRAG_ASSERT (skb) BUG_ON(skb_has_frag_list(skb))#define SKB_LINEAR_ASSERT (skb) BUG_ON(skb_is_nonlinear(skb))
net/core/skbuff.c +13 -0
@@ -476,6 +476,19 @@ void skb_add_rx_frag(struct sk_buff *skb, int i, struct page *page, int off, }EXPORT_SYMBOL (skb_add_rx_frag); +void skb_coalesce_rx_frag (struct sk_buff *skb,int i,int off,int size, +unsigned int truesize) +{ +skb_frag_t *frag = &skb_shinfo (skb)->frags[i]; + +skb_frag_size_add (frag, size); + skb->len += size; + skb->data_len += size; + skb->truesize += truesize; +skb_frag_unref (skb, i); +} +EXPORT_SYMBOL (skb_coalesce_rx_frag); +static void skb_drop_list (struct sk_buff **listp) {kfree_skb_list (*listp);
Signature · 1 line
1.8.1.2
PATCH 2/2 virtio-net: coalesce rx frags when possible during rx
Commit 2613af0ed18a11d5c566a81f9a6510b73180660a (virtio_net: migrate mergeable rx buffers to page frag allocators) try to increase the payload/truesize for MTU-sized traffic. But this will introduce the extra overhead for GSO packets received because of the frag list. This commit tries to reduce this issue by coalesce the possible rx frags when possible during rx. Test result shows the about 15% improvement on full size GSO packet receiving (and even better than commit 2613af0ed18a11d5c566a81f9a6510b73180660a).
Before this commit:
./netperf -H 192.168.100.4
MIGRATED TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.100.4 () port 0 AF_INET : demo
Recv Send Send Socket Socket Message Elapsed Size Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec
87380 16384 16384 10.00 20303.87
After this commit:
./netperf -H 192.168.100.4
MIGRATED TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.100.4 () port 0 AF_INET : demo
Recv Send Send Socket Socket Message Elapsed Size Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec
87380 16384 16384 10.00 23841.26
--- drivers/net/virtio_net.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/net/virtio_net.c +10 -4
@@ -305,7 +305,7 @@ static int receive_mergeable(struct receive_queue *rq, struct sk_buff *head_skb)struct sk_buff *curr_skb = head_skb;char *buf;struct page *page; -int num_buf, len; +int num_buf, len, offset; num_buf = hdr->mhdr.num_buffers;while (--num_buf) {
@@ -342,9 +342,15 @@ static int receive_mergeable(struct receive_queue *rq, struct sk_buff *head_skb) head_skb->truesize +=MAX_PACKET_LEN ; } page =virt_to_head_page (buf); -skb_add_rx_frag (curr_skb, num_skb_frags, page, - buf - (char *)page_address (page), len, -MAX_PACKET_LEN ); + offset = buf - (char *)page_address (page); +if (skb_can_coalesce (curr_skb, num_skb_frags, page, offset)) { +skb_coalesce_rx_frag (curr_skb, num_skb_frags -1 , + offset, len,MAX_PACKET_LEN ); + }else { +skb_add_rx_frag (curr_skb, num_skb_frags, page, + offset, len, +MAX_PACKET_LEN ); + } --rq->num; }return 0 ;
Signature · 1 line
1.8.1.2
Quoted 37 lines · Jason Wang
Sometimes we need to coalesce the rx frags to avoid frag list. One example is virtio-net driver which tries to use small frags for both MTU sized packet and GSO packet. So this patch introduce
skb_coalesce_rx_frag()to do this.Cc Rusty Russell <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Michael Dalton <[email protected]>Cc Eric Dumazet <[email protected]>Signed-off-by Jason Wang <[email protected]>--- include/linux/skbuff.h | 3 +++ net/core/skbuff.c | 13 +++++++++++++ 2 files changed, 16 insertions(+)include/linux/skbuff.h +3
-0@@ -1372,6 +1372,9 @@ static inline void skb_fill_page_desc(struct sk_buff *skb, int i,void skb_add_rx_frag (struct sk_buff *skb,int i,struct page *page,int off,int size,unsigned int truesize); +void skb_coalesce_rx_frag (struct sk_buff *skb,int i,int off,int size, +unsigned int truesize); +#define SKB_PAGE_ASSERT (skb) BUG_ON(skb_shinfo(skb)->nr_frags)#define SKB_FRAG_ASSERT (skb) BUG_ON(skb_has_frag_list(skb))#define SKB_LINEAR_ASSERT (skb) BUG_ON(skb_is_nonlinear(skb))net/core/skbuff.c +1
-0@@ -476,6 +476,19 @@ void skb_add_rx_frag(struct sk_buff *skb, int i, struct page *page, int off, }EXPORT_SYMBOL (skb_add_rx_frag); +void skb_coalesce_rx_frag(struct sk_buff *skb, int i, int off, int size,
net/core/skbuff.c void skb_add_rx_frag(struct sk_buff *skb, int i, struct page *page, int off, · line 489
Quoted 10 lines
net/core/skbuff.c +10
-0+ unsigned int truesize) +{ +skb_frag_t *frag = &skb_shinfo (skb)->frags[i]; + +skb_frag_size_add (frag, size); + skb->len += size; + skb->data_len += size; + skb->truesize += truesize; +skb_frag_unref (skb, i); +}
I didn't see you use "off" in skb_coalesce_rx_frag.
Quoted 12 lines
net/core/skbuff.c +2
-1+EXPORT_SYMBOL (skb_coalesce_rx_frag); +static void skb_drop_list (struct sk_buff **listp) {kfree_skb_list (*listp); --1.8.1.2
--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 37 lines · Jason Wang
Sometimes we need to coalesce the rx frags to avoid frag list. One example is virtio-net driver which tries to use small frags for both MTU sized packet and GSO packet. So this patch introduce
skb_coalesce_rx_frag()to do this.Cc Rusty Russell <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Michael Dalton <[email protected]>Cc Eric Dumazet <[email protected]>Signed-off-by Jason Wang <[email protected]>--- include/linux/skbuff.h | 3 +++ net/core/skbuff.c | 13 +++++++++++++ 2 files changed, 16 insertions(+)include/linux/skbuff.h +3
-0@@ -1372,6 +1372,9 @@ static inline void skb_fill_page_desc(struct sk_buff *skb, int i,void skb_add_rx_frag (struct sk_buff *skb,int i,struct page *page,int off,int size,unsigned int truesize); +void skb_coalesce_rx_frag (struct sk_buff *skb,int i,int off,int size, +unsigned int truesize); +#define SKB_PAGE_ASSERT (skb) BUG_ON(skb_shinfo(skb)->nr_frags)#define SKB_FRAG_ASSERT (skb) BUG_ON(skb_has_frag_list(skb))#define SKB_LINEAR_ASSERT (skb) BUG_ON(skb_is_nonlinear(skb))net/core/skbuff.c +1
-0@@ -476,6 +476,19 @@ void skb_add_rx_frag(struct sk_buff *skb, int i, struct page *page, int off, }EXPORT_SYMBOL (skb_add_rx_frag); +void skb_coalesce_rx_frag(struct sk_buff *skb, int i, int off, int size,
net/core/skbuff.c void skb_add_rx_frag(struct sk_buff *skb, int i, struct page *page, int off, · line 489
Quoted 10 lines
net/core/skbuff.c +10
-0+ unsigned int truesize) +{ +skb_frag_t *frag = &skb_shinfo (skb)->frags[i]; + +skb_frag_size_add (frag, size); + skb->len += size; + skb->data_len += size; + skb->truesize += truesize; +skb_frag_unref (skb, i); +}
I didn't see you use "off" in skb_coalesce_rx_frag.
Quoted 12 lines
net/core/skbuff.c +2
-1+EXPORT_SYMBOL (skb_coalesce_rx_frag); +static void skb_drop_list (struct sk_buff **listp) {kfree_skb_list (*listp); --1.8.1.2
--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 37 lines · Kmindg G
Quoted 36 lines · Jason Wang
Quoted 36 lines
Sometimes we need to coalesce the rx frags to avoid frag list. One example is virtio-net driver which tries to use small frags for both MTU sized packet and GSO packet. So this patch introduce
skb_coalesce_rx_frag()to do this.Cc Rusty Russell <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Michael Dalton <[email protected]>Cc Eric Dumazet <[email protected]>Signed-off-by Jason Wang <[email protected]>--- include/linux/skbuff.h | 3 +++ net/core/skbuff.c | 13 +++++++++++++ 2 files changed, 16 insertions(+)include/linux/skbuff.h +3
-0@@ -1372,6 +1372,9 @@ static inline void skb_fill_page_desc(struct sk_buff *skb, int i,void skb_add_rx_frag (struct sk_buff *skb,int i,struct page *page,int off,int size,unsigned int truesize); +void skb_coalesce_rx_frag (struct sk_buff *skb,int i,int off,int size, +unsigned int truesize); +#define SKB_PAGE_ASSERT (skb) BUG_ON(skb_shinfo(skb)->nr_frags)#define SKB_FRAG_ASSERT (skb) BUG_ON(skb_has_frag_list(skb))#define SKB_LINEAR_ASSERT (skb) BUG_ON(skb_is_nonlinear(skb))net/core/skbuff.c +0
-0@@ -476,6 +476,19 @@ void skb_add_rx_frag(struct sk_buff *skb, int i, struct page *page, int off, }EXPORT_SYMBOL (skb_add_rx_frag);
Quoted 13 lines
Quoted 11 lines
net/core/skbuff.c void skb_add_rx_frag(struct sk_buff *skb, int i, struct page *page, int off, · line 489
Quoted 11 lines
net/core/skbuff.c +11
-0+void skb_coalesce_rx_frag (struct sk_buff *skb,int i,int off,int size, +unsigned int truesize) +{ +skb_frag_t *frag = &skb_shinfo (skb)->frags[i]; + +skb_frag_size_add (frag, size); + skb->len += size; + skb->data_len += size; + skb->truesize += truesize; +skb_frag_unref (skb, i); +}I didn't see you use "off" in
skb_coalesce_rx_frag.
Ture, it's useless. Will post V2.
Thanks
Quoted 9 lines · Jason Wang
Sometimes we need to coalesce the rx frags to avoid frag list. One example is virtio-net driver which tries to use small frags for both MTU sized packet and GSO packet. So this patch introduce
skb_coalesce_rx_frag()to do this.Cc Rusty Russell <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Michael Dalton <[email protected]>Cc Eric Dumazet <[email protected]>Signed-off-by Jason Wang <[email protected]>
Quoted 45 lines
--- include/linux/skbuff.h | 3 +++ net/core/skbuff.c | 13 +++++++++++++ 2 files changed, 16 insertions(+)include/linux/skbuff.h +3
-0@@ -1372,6 +1372,9 @@ static inline void skb_fill_page_desc(struct sk_buff *skb, int i,void skb_add_rx_frag (struct sk_buff *skb,int i,struct page *page,int off,int size,unsigned int truesize); +void skb_coalesce_rx_frag (struct sk_buff *skb,int i,int off,int size, +unsigned int truesize); +#define SKB_PAGE_ASSERT (skb) BUG_ON(skb_shinfo(skb)->nr_frags)#define SKB_FRAG_ASSERT (skb) BUG_ON(skb_has_frag_list(skb))#define SKB_LINEAR_ASSERT (skb) BUG_ON(skb_is_nonlinear(skb))net/core/skbuff.c +13
-0@@ -476,6 +476,19 @@ void skb_add_rx_frag(struct sk_buff *skb, int i, struct page *page, int off, }EXPORT_SYMBOL (skb_add_rx_frag); +void skb_coalesce_rx_frag (struct sk_buff *skb,int i,int off,int size, +unsigned int truesize) +{ +skb_frag_t *frag = &skb_shinfo (skb)->frags[i]; + +skb_frag_size_add (frag, size); + skb->len += size; + skb->data_len += size; + skb->truesize += truesize; +skb_frag_unref (skb, i); +} +EXPORT_SYMBOL (skb_coalesce_rx_frag); +static void skb_drop_list (struct sk_buff **listp) {kfree_skb_list (*listp);Signature · 1 line
1.8.1.2
Re: [PATCH net-next 2/2] virtio-net: coalesce rx frags when possible during rx
In reply to Jason WangQuoted 27 lines · Jason Wang
Commit
2613af0ed18a11d5c566a81f9a6510b73180660a(virtio_net: migrate mergeable rx buffers to page frag allocators) try to increase the payload/truesize for MTU-sized traffic. But this will introduce the extra overhead for GSO packets received because of the frag list. This commit tries to reduce this issue by coalesce the possible rx frags when possible during rx. Test result shows the about 15% improvement on full size GSO packet receiving (and even better than commit2613af0ed18a11d5c566a81f9a6510b73180660a).Before this commit:
./netperf -H 192.168.100.4
MIGRATED TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0AF_INETto 192.168.100.4 () port 0AF_INET: demoRecv Send Send Socket Socket Message Elapsed Size Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec87380 16384 16384 10.00 20303.87
After this commit:
./netperf -H 192.168.100.4
MIGRATED TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0AF_INETto 192.168.100.4 () port 0AF_INET: demoRecv Send Send Socket Socket Message Elapsed Size Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec
Quoted 7 lines
87380 16384 16384 10.00 23841.26
Cc Rusty Russell <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Michael Dalton <[email protected]>Cc Eric Dumazet <[email protected]>Signed-off-by Jason Wang <[email protected]>
Good idea.
Quoted 38 lines
--- drivers/net/virtio_net.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)drivers/net/virtio_net.c +10
-4@@ -305,7 +305,7 @@ static int receive_mergeable(struct receive_queue *rq, struct sk_buff *head_skb)struct sk_buff *curr_skb = head_skb;char *buf;struct page *page; -int num_buf, len; +int num_buf, len, offset; num_buf = hdr->mhdr.num_buffers;while (--num_buf) {@@ -342,9 +342,15 @@ static int receive_mergeable(struct receive_queue *rq, struct sk_buff *head_skb) head_skb->truesize +=MAX_PACKET_LEN ; } page =virt_to_head_page (buf); -skb_add_rx_frag (curr_skb, num_skb_frags, page, - buf - (char *)page_address (page), len, -MAX_PACKET_LEN ); + offset = buf - (char *)page_address (page); +if (skb_can_coalesce (curr_skb, num_skb_frags, page, offset)) { +skb_coalesce_rx_frag (curr_skb, num_skb_frags -1 , + offset, len,MAX_PACKET_LEN ); + }else { +skb_add_rx_frag (curr_skb, num_skb_frags, page, + offset, len, +MAX_PACKET_LEN ); + } --rq->num; }return 0 ;Signature · 1 line
1.8.1.2
Re: [PATCH net-next 2/2] virtio-net: coalesce rx frags when possible during rx
In reply to Jason WangQuoted 7 lines · Jason Wang
Commit
2613af0ed18a11d5c566a81f9a6510b73180660a(virtio_net: migrate mergeable rx buffers to page frag allocators) try to increase the payload/truesize for MTU-sized traffic. But this will introduce the extra overhead for GSO packets received because of the frag list. This commit tries to reduce this issue by coalesce the possible rx frags when possible during rx. Test result shows the about 15% improvement on full size GSO packet receiving (and even better than commit2613af0ed18a11d5c566a81f9a6510b73180660a).
I don't know about the other users of skb_add_rx_frag, but should this coalesce-if-possible code be built into that?
Thanks,
Rusty.
Re: [PATCH net-next 2/2] virtio-net: coalesce rx frags when possible during rx
Quoted 10 lines · Rusty Russell
Quoted 7 lines · Jason Wang
Commit
2613af0ed18a11d5c566a81f9a6510b73180660a(virtio_net: migrate mergeable rx buffers to page frag allocators) try to increase the payload/truesize for MTU-sized traffic. But this will introduce the extra overhead for GSO packets received because of the frag list. This commit tries to reduce this issue by coalesce the possible rx frags when possible during rx. Test result shows the about 15% improvement on full size GSO packet receiving (and even better than commit2613af0ed18a11d5c566a81f9a6510b73180660a).I don't know about the other users of
skb_add_rx_frag, but should this coalesce-if-possible code be built into that?
There're several other users without the possibility check. And Eric point out in do_tcp_sendpages() skb_add_rx_frag() and skb_can_coalesce() were used separatedly which can allows us to do some other things in the middle. So it was ok here.
Quoted 3 lines
Thanks,
Rusty.