aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2017-07-31 14:49:49 -0400
committerDavid S. Miller <davem@davemloft.net>2017-07-31 21:02:46 -0400
commit1daa8790d0280d2c719658e39bd59fce65efa909 (patch)
treefa2dbfb28b89a3f520c402f146b731e69f737e86
parentcfbcb61f6c2ac9aeb7731d2ec59fe3bf53786c49 (diff)
virtio_net: fix truesize for mergeable buffers
Seth Forshee noticed a performance degradation with some workloads. This turns out to be due to packet drops. Euan Kemp noticed that this is because we drop all packets where length exceeds the truesize, but for some packets we add in extra memory without updating the truesize. This in turn was kept around unchanged from ab7db91705e95 ("virtio-net: auto-tune mergeable rx buffer size for improved performance"). That commit had an internal reason not to account for the extra space: not enough bits to do it. No longer true so let's account for the allocated length exactly. Many thanks to Seth Forshee for the report and bisecting and Euan Kemp for debugging the issue. Fixes: 680557cf79f8 ("virtio_net: rework mergeable buffer handling") Reported-by: Euan Kemp <euan.kemp@coreos.com> Tested-by: Euan Kemp <euan.kemp@coreos.com> Reported-by: Seth Forshee <seth.forshee@canonical.com> Tested-by: Seth Forshee <seth.forshee@canonical.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/virtio_net.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 99a26a9efec1..075dc18829ab 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -889,21 +889,20 @@ static int add_recvbuf_mergeable(struct virtnet_info *vi,
889 889
890 buf = (char *)page_address(alloc_frag->page) + alloc_frag->offset; 890 buf = (char *)page_address(alloc_frag->page) + alloc_frag->offset;
891 buf += headroom; /* advance address leaving hole at front of pkt */ 891 buf += headroom; /* advance address leaving hole at front of pkt */
892 ctx = (void *)(unsigned long)len;
893 get_page(alloc_frag->page); 892 get_page(alloc_frag->page);
894 alloc_frag->offset += len + headroom; 893 alloc_frag->offset += len + headroom;
895 hole = alloc_frag->size - alloc_frag->offset; 894 hole = alloc_frag->size - alloc_frag->offset;
896 if (hole < len + headroom) { 895 if (hole < len + headroom) {
897 /* To avoid internal fragmentation, if there is very likely not 896 /* To avoid internal fragmentation, if there is very likely not
898 * enough space for another buffer, add the remaining space to 897 * enough space for another buffer, add the remaining space to
899 * the current buffer. This extra space is not included in 898 * the current buffer.
900 * the truesize stored in ctx.
901 */ 899 */
902 len += hole; 900 len += hole;
903 alloc_frag->offset += hole; 901 alloc_frag->offset += hole;
904 } 902 }
905 903
906 sg_init_one(rq->sg, buf, len); 904 sg_init_one(rq->sg, buf, len);
905 ctx = (void *)(unsigned long)len;
907 err = virtqueue_add_inbuf_ctx(rq->vq, rq->sg, 1, buf, ctx, gfp); 906 err = virtqueue_add_inbuf_ctx(rq->vq, rq->sg, 1, buf, ctx, gfp);
908 if (err < 0) 907 if (err < 0)
909 put_page(virt_to_head_page(buf)); 908 put_page(virt_to_head_page(buf));