Skip to content

Commit ba27524

Browse files
jasowangdavem330
authored andcommitted
virtio-net: coalesce rx frags when possible during rx
Commit 2613af0 (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 before commit 2613af0). 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 Cc: Rusty Russell <[email protected]> Cc: Michael S. Tsirkin <[email protected]> Cc: Michael Dalton <[email protected]> Cc: Eric Dumazet <[email protected]> Acked-by: Michael S. Tsirkin <[email protected]> Acked-by: Eric Dumazet <[email protected]> Signed-off-by: Jason Wang <[email protected]> Acked-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f8e617e commit ba27524

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

drivers/net/virtio_net.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ static int receive_mergeable(struct receive_queue *rq, struct sk_buff *head_skb)
305305
struct sk_buff *curr_skb = head_skb;
306306
char *buf;
307307
struct page *page;
308-
int num_buf, len;
308+
int num_buf, len, offset;
309309

310310
num_buf = hdr->mhdr.num_buffers;
311311
while (--num_buf) {
@@ -342,9 +342,16 @@ static int receive_mergeable(struct receive_queue *rq, struct sk_buff *head_skb)
342342
head_skb->truesize += MAX_PACKET_LEN;
343343
}
344344
page = virt_to_head_page(buf);
345-
skb_add_rx_frag(curr_skb, num_skb_frags, page,
346-
buf - (char *)page_address(page), len,
347-
MAX_PACKET_LEN);
345+
offset = buf - (char *)page_address(page);
346+
if (skb_can_coalesce(curr_skb, num_skb_frags, page, offset)) {
347+
put_page(page);
348+
skb_coalesce_rx_frag(curr_skb, num_skb_frags - 1,
349+
len, MAX_PACKET_LEN);
350+
} else {
351+
skb_add_rx_frag(curr_skb, num_skb_frags, page,
352+
offset, len,
353+
MAX_PACKET_LEN);
354+
}
348355
--rq->num;
349356
}
350357
return 0;

0 commit comments

Comments
 (0)