vhost: adaptively batch small guest memory copies
PATCH 1/1 vhost: adaptively batch small guest memory copies
This patch adaptively batches the small guest memory copies. By batching the small copies, the efficiency of executing the memory LOAD instructions can be improved greatly, because the memory LOAD latency can be effectively hidden by the pipeline. We saw great performance boosts for small packets PVP test.
This patch improves the performance for small packets, and has distinguished the packets by size. So although the performance for big packets doesn't change, it makes it relatively easy to do some special optimizations for the big packets too.
---
This optimization depends on the CPU internal pipeline design. So further tests (e.g. ARM) from the community is appreciated.
lib/librte_vhost/vhost.c | 2 +- lib/librte_vhost/vhost.h | 13 +++ lib/librte_vhost/vhost_user.c | 12 +++ lib/librte_vhost/virtio_net.c | 240 ++++++++++++++++++++++++++++++++---------- 4 files changed, 209 insertions(+), 58 deletions(-)
lib/librte_vhost/vhost.c +1 -1
@@ -102,7 +102,7 @@ free_device(struct virtio_net *dev) vq = dev->virtqueue[i];rte_free (vq->shadow_used_ring); - +rte_free (vq->burst_copy_elems);rte_free (vq); }
lib/librte_vhost/vhost.h +13 -0
@@ -81,6 +81,16 @@ struct zcopy_mbuf { };TAILQ_HEAD (zcopy_mbuf_list, zcopy_mbuf); +/* +* Structure contains the info for each batched memory copy. +*/ +struct burst_copy_elem { +void *dst; +void *src; +uint32_t len; +uint64_t log_addr; +}; +/** * Structure contains variables relevant to RX/TX virtqueues. */
@@ -114,6 +124,9 @@ struct vhost_virtqueue {struct vring_used_elem *shadow_used_ring;uint16_t shadow_used_idx; + +struct burst_copy_elem *burst_copy_elems; +uint16_t burst_copy_nb_elems; } __rte_cache_aligned;/* Old kernels have no such macros defined */
lib/librte_vhost/vhost_user.c +12 -0
@@ -230,6 +230,15 @@ vhost_user_set_vring_num(struct virtio_net *dev,return -1 ; } + vq->burst_copy_elems =rte_malloc (NULL , + vq->size *sizeof (struct burst_copy_elem ), +RTE_CACHE_LINE_SIZE ); +if (!vq->burst_copy_elems) { +RTE_LOG (ERR ,VHOST_CONFIG , +"failed to allocate memory for batching copy.\n" ); +return -1 ; + } +return 0 ; }
@@ -741,6 +750,9 @@ vhost_user_get_vring_base(struct virtio_net *dev,rte_free (vq->shadow_used_ring); vq->shadow_used_ring =NULL ; +rte_free (vq->burst_copy_elems); + vq->burst_copy_elems =NULL ; +return 0 ; }
lib/librte_vhost/virtio_net.c +183 -57
431 lines not on this page · raw message
Signature · 1 line
2.7.4
Hi Tiwei,
Quoted 5 lines · Tiwei Bie
This patch adaptively batches the small guest memory copies. By batching the small copies, the efficiency of executing the memory LOAD instructions can be improved greatly, because the memory LOAD latency can be effectively hidden by the pipeline. We saw great performance boosts for small packets PVP test.
this sounds interesting. Do you have numbers showing how much performance improved for small packets?
regards,
Jens
Quoted 21 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Jens Freimann
Sent: Monday, August 28, 2017 2:31 PM
To: Bie, Tiwei <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Wang, Zhihong <[email protected]>; Yang, Zhiyong <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] vhost: adaptively batch small guest memory copiesHi Tiwei,
Quoted 5 lines · Tiwei Bie
This patch adaptively batches the small guest memory copies. By batching the small copies, the efficiency of executing the memory LOAD instructions can be improved greatly, because the memory LOAD latency can be effectively hidden by the pipeline. We saw great performance boosts for small packets PVP test.
Quoted 5 lines
this sounds interesting. Do you have numbers showing how much performance improved for small packets?
regards,
Jens
Hi, Jens
On my test bench, the performance gain as following for 64B small packets
Mergeable: 19%
Vector : 21%
No-mergeable: 21%
CPU info: Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
OS: Ubuntu 16.04
Quoted 10 lines · Tiwei Bie
This patch adaptively batches the small guest memory copies. By batching the small copies, the efficiency of executing the memory LOAD instructions can be improved greatly, because the memory LOAD latency can be effectively hidden by the pipeline. We saw great performance boosts for small packets PVP test.
This patch improves the performance for small packets, and has distinguished the packets by size. So although the performance for big packets doesn't change, it makes it relatively easy to do some special optimizations for the big packets too.
Do you mean that if we would batch unconditionnaly whatever the size, we see performance drop for larger (>256) packets?
Other question is about indirect descriptors, my understanding of the patch is that the number of batched copies is limited to the queue size. In theory, we could have more than that with indirect descriptors (first indirect desc for the vnet header, second one for the packet).
So in the worst case, we would have the first small copies being batched, but not the last ones if there are more than queue size. So, I think it works, but I'd like your confirmation.
Quoted 7 lines
Signed-off-by Tiwei Bie <[email protected]>Signed-off-by Zhihong Wang <[email protected]>Signed-off-by Zhiyong Yang <[email protected]>---
This optimization depends on the CPU internal pipeline design. So further tests (e.g. ARM) from the community is appreciated.
Agree, I think this is important to have it tested on ARM platforms at least to ensure it doesn't introduce a regression.
Adding Santosh, Jerin & Hemant in cc, who might know who could do the test.
Quoted 5 lines
lib/librte_vhost/vhost.c | 2 +- lib/librte_vhost/vhost.h | 13 +++ lib/librte_vhost/vhost_user.c | 12 +++ lib/librte_vhost/virtio_net.c | 240 ++++++++++++++++++++++++++++++++---------- 4 files changed, 209 insertions(+), 58 deletions(-)
Quoted 7 lines · Maxime Coquelin
Quoted 6 lines · Tiwei Bie
This patch adaptively batches the small guest memory copies. By batching the small copies, the efficiency of executing the memory LOAD instructions can be improved greatly, because the memory LOAD latency can be effectively hidden by the pipeline. We saw great performance boosts for small packets PVP test.
Quoted 8 lines
Quoted 4 lines
This patch improves the performance for small packets, and has distinguished the packets by size. So although the performance for big packets doesn't change, it makes it relatively easy to do some special optimizations for the big packets too.
Do you mean that if we would batch unconditionnaly whatever the size, we see performance drop for larger (>256) packets?
Yeah, you are right.
Quoted 9 lines
Other question is about indirect descriptors, my understanding of the patch is that the number of batched copies is limited to the queue size. In theory, we could have more than that with indirect descriptors (first indirect desc for the vnet header, second one for the packet).
So in the worst case, we would have the first small copies being batched, but not the last ones if there are more than queue size. So, I think it works, but I'd like your confirmation.
Yeah, you are right. If the number of small copies is larger than the queue size, the last ones won't be batched any more.
Quoted 8 lines
Quoted 7 lines
Signed-off-by Tiwei Bie <[email protected]>Signed-off-by Zhihong Wang <[email protected]>Signed-off-by Zhiyong Yang <[email protected]>---
This optimization depends on the CPU internal pipeline design. So further tests (e.g. ARM) from the community is appreciated.
Quoted 6 lines
Agree, I think this is important to have it tested on ARM platforms at least to ensure it doesn't introduce a regression.
Adding Santosh, Jerin & Hemant in cc, who might know who could do the test.
Thank you very much! :-)
Best regards,
Tiwei Bie
Hi Tiwei,
Quoted 18 lines · Tiwei Bie
This patch adaptively batches the small guest memory copies. By batching the small copies, the efficiency of executing the memory LOAD instructions can be improved greatly, because the memory LOAD latency can be effectively hidden by the pipeline. We saw great performance boosts for small packets PVP test.
This patch improves the performance for small packets, and has distinguished the packets by size. So although the performance for big packets doesn't change, it makes it relatively easy to do some special optimizations for the big packets too.
Signed-off-by Tiwei Bie<[email protected]>Signed-off-by Zhihong Wang<[email protected]>Signed-off-by Zhiyong Yang<[email protected]>---
This optimization depends on the CPU internal pipeline design. So further tests (e.g. ARM) from the community is appreciated.
Quoted 5 lines
lib/librte_vhost/vhost.c | 2 +- lib/librte_vhost/vhost.h | 13 +++ lib/librte_vhost/vhost_user.c | 12 +++ lib/librte_vhost/virtio_net.c | 240 ++++++++++++++++++++++++++++++++---------- 4 files changed, 209 insertions(+), 58 deletions(-)
I did some PVP benchmark with your patch.
First I tried my standard PVP setup, with io forwarding on host and macswap on guest in bidirectional mode.
With this, I notice no improvement (18.8Mpps), but I think it explains because guest is the bottleneck here.
So I change my setup to do csum forwarding on host side, so that host's PMD threads are more loaded.
In this case, I notice a great improvement, I get 18.8Mpps with your patch instead of 14.8Mpps without! Great work!
Thanks,
Maxime
Hi Maxime,
Quoted 36 lines · Maxime Coquelin
Hi Tiwei,
Quoted 18 lines · Tiwei Bie
This patch adaptively batches the small guest memory copies. By batching the small copies, the efficiency of executing the memory LOAD instructions can be improved greatly, because the memory LOAD latency can be effectively hidden by the pipeline. We saw great performance boosts for small packets PVP test.
This patch improves the performance for small packets, and has distinguished the packets by size. So although the performance for big packets doesn't change, it makes it relatively easy to do some special optimizations for the big packets too.
Signed-off-by Tiwei Bie<[email protected]>Signed-off-by Zhihong Wang<[email protected]>Signed-off-by Zhiyong Yang<[email protected]>---
This optimization depends on the CPU internal pipeline design. So further tests (e.g. ARM) from the community is appreciated.Quoted 5 lines
lib/librte_vhost/vhost.c | 2 +- lib/librte_vhost/vhost.h | 13 +++ lib/librte_vhost/vhost_user.c | 12 +++ lib/librte_vhost/virtio_net.c | 240 ++++++++++++++++++++++++++++++++---------- 4 files changed, 209 insertions(+), 58 deletions(-)I did some PVP benchmark with your patch.
First I tried my standard PVP setup, with io forwarding on host and macswap on guest in bidirectional mode.With this, I notice no improvement (18.8Mpps), but I think it explains because guest is the bottleneck here.
So I change my setup to do csum forwarding on host side, so that host's PMD threads are more loaded.
Quoted 5 lines
In this case, I notice a great improvement, I get 18.8Mpps with your patch instead of 14.8Mpps without! Great work!
Reviewed-by Maxime Coquelin <[email protected]>
Thank you very much for taking time to review and test this patch! :-)
Best regards,
Tiwei Bie
Quoted 10 lines · Tiwei Bie
This patch adaptively batches the small guest memory copies. By batching the small copies, the efficiency of executing the memory LOAD instructions can be improved greatly, because the memory LOAD latency can be effectively hidden by the pipeline. We saw great performance boosts for small packets PVP test.
This patch improves the performance for small packets, and has distinguished the packets by size. So although the performance for big packets doesn't change, it makes it relatively easy to do some special optimizations for the big packets too.
The number showed in other replies looks really impressive. Great work! This patch also looks good to me. I have one minor comment though.
[...]
lib/librte_vhost/vhost.h struct zcopy_mbuf { · line 92
Quoted 9 lines
lib/librte_vhost/vhost.h +9
-0+/* +* Structure contains the info for each batched memory copy. +*/ +struct burst_copy_elem { +void *dst; +void *src; +uint32_t len; +uint64_t log_addr; +};
Like the title says, it's more about batch (but not burst). Also, it's not a good idea to mix burst and batch. I'd suggest you to use the term "batch" consistently.
--yliu
Quoted 16 lines · Yuanhan Liu
Quoted 10 lines · Tiwei Bie
This patch adaptively batches the small guest memory copies. By batching the small copies, the efficiency of executing the memory LOAD instructions can be improved greatly, because the memory LOAD latency can be effectively hidden by the pipeline. We saw great performance boosts for small packets PVP test.
This patch improves the performance for small packets, and has distinguished the packets by size. So although the performance for big packets doesn't change, it makes it relatively easy to do some special optimizations for the big packets too.
The number showed in other replies looks really impressive. Great work! This patch also looks good to me. I have one minor comment though.
[...]
Quoted 14 lines
lib/librte_vhost/vhost.h struct zcopy_mbuf { · line 92
Quoted 9 lines
lib/librte_vhost/vhost.h +9
-0+/* +* Structure contains the info for each batched memory copy. +*/ +struct burst_copy_elem { +void *dst; +void *src; +uint32_t len; +uint64_t log_addr; +};Like the title says, it's more about batch (but not burst). Also, it's not a good idea to mix burst and batch. I'd suggest you to use the term "batch" consistently.
Okay, I'll change it. Thank you! :-)
Best regards,
Tiwei Bie
PATCH v2 1/1 vhost: adaptively batch small guest memory copies
In reply to Tiwei BieThis patch adaptively batches the small guest memory copies. By batching the small copies, the efficiency of executing the memory LOAD instructions can be improved greatly, because the memory LOAD latency can be effectively hidden by the pipeline. We saw great performance boosts for small packets PVP test.
This patch improves the performance for small packets, and has distinguished the packets by size. So although the performance for big packets doesn't change, it makes it relatively easy to do some special optimizations for the big packets too.
---
This optimization depends on the CPU internal pipeline design. So further tests (e.g. ARM) from the community is appreciated.
v2: s/burst_copy/batch_copy/g
lib/librte_vhost/vhost.c | 2 +- lib/librte_vhost/vhost.h | 13 +++ lib/librte_vhost/vhost_user.c | 12 +++ lib/librte_vhost/virtio_net.c | 240 ++++++++++++++++++++++++++++++++---------- 4 files changed, 209 insertions(+), 58 deletions(-)
lib/librte_vhost/vhost.c +1 -1
@@ -102,7 +102,7 @@ free_device(struct virtio_net *dev) vq = dev->virtqueue[i];rte_free (vq->shadow_used_ring); - +rte_free (vq->batch_copy_elems);rte_free (vq); }
lib/librte_vhost/vhost.h +13 -0
@@ -81,6 +81,16 @@ struct zcopy_mbuf { };TAILQ_HEAD (zcopy_mbuf_list, zcopy_mbuf); +/* +* Structure contains the info for each batched memory copy. +*/ +struct batch_copy_elem { +void *dst; +void *src; +uint32_t len; +uint64_t log_addr; +}; +/** * Structure contains variables relevant to RX/TX virtqueues. */
@@ -114,6 +124,9 @@ struct vhost_virtqueue {struct vring_used_elem *shadow_used_ring;uint16_t shadow_used_idx; + +struct batch_copy_elem *batch_copy_elems; +uint16_t batch_copy_nb_elems; } __rte_cache_aligned;/* Old kernels have no such macros defined */
lib/librte_vhost/vhost_user.c +12 -0
@@ -230,6 +230,15 @@ vhost_user_set_vring_num(struct virtio_net *dev,return -1 ; } + vq->batch_copy_elems =rte_malloc (NULL , + vq->size *sizeof (struct batch_copy_elem ), +RTE_CACHE_LINE_SIZE ); +if (!vq->batch_copy_elems) { +RTE_LOG (ERR ,VHOST_CONFIG , +"failed to allocate memory for batching copy.\n" ); +return -1 ; + } +return 0 ; }
@@ -741,6 +750,9 @@ vhost_user_get_vring_base(struct virtio_net *dev,rte_free (vq->shadow_used_ring); vq->shadow_used_ring =NULL ; +rte_free (vq->batch_copy_elems); + vq->batch_copy_elems =NULL ; +return 0 ; }
lib/librte_vhost/virtio_net.c +183 -57
431 lines not on this page · raw message
Signature · 1 line
2.7.4
Quoted 15 lines · Tiwei Bie
This patch adaptively batches the small guest memory copies. By batching the small copies, the efficiency of executing the memory LOAD instructions can be improved greatly, because the memory LOAD latency can be effectively hidden by the pipeline. We saw great performance boosts for small packets PVP test.
This patch improves the performance for small packets, and has distinguished the packets by size. So although the performance for big packets doesn't change, it makes it relatively easy to do some special optimizations for the big packets too.
Signed-off-by Tiwei Bie <[email protected]>Signed-off-by Zhihong Wang <[email protected]>Signed-off-by Zhiyong Yang <[email protected]>Reviewed-by Maxime Coquelin <[email protected]>
Quoted 5 lines
---
This optimization depends on the CPU internal pipeline design. So further tests (e.g. ARM) from the community is appreciated.v2: s/burst_copy/batch_copy/g
In pvp setup for arm64 platform, no performance drop noticed with this patch but no significant performance gain either. Tested-by: Santosh Shukla <[email protected]>
Quoted 20 lines · santosh
Quoted 19 lines · Tiwei Bie
This patch adaptively batches the small guest memory copies. By batching the small copies, the efficiency of executing the memory LOAD instructions can be improved greatly, because the memory LOAD latency can be effectively hidden by the pipeline. We saw great performance boosts for small packets PVP test.
This patch improves the performance for small packets, and has distinguished the packets by size. So although the performance for big packets doesn't change, it makes it relatively easy to do some special optimizations for the big packets too.
Signed-off-by Tiwei Bie <[email protected]>Signed-off-by Zhihong Wang <[email protected]>Signed-off-by Zhiyong Yang <[email protected]>Reviewed-by Maxime Coquelin <[email protected]>---
This optimization depends on the CPU internal pipeline design. So further tests (e.g. ARM) from the community is appreciated.
Quoted 4 lines
Quoted 1 line
v2: s/burst_copy/batch_copy/g
In pvp setup for arm64 platform, no performance drop noticed with this patch but no significant performance gain either. Tested-by: Santosh Shukla <[email protected]>
Thank you very much for testing this patch!
Best regards,
Tiwei Bie
Yuanhan Liu
AppliedQuoted 20 lines · santosh
Quoted 19 lines · Tiwei Bie
This patch adaptively batches the small guest memory copies. By batching the small copies, the efficiency of executing the memory LOAD instructions can be improved greatly, because the memory LOAD latency can be effectively hidden by the pipeline. We saw great performance boosts for small packets PVP test.
This patch improves the performance for small packets, and has distinguished the packets by size. So although the performance for big packets doesn't change, it makes it relatively easy to do some special optimizations for the big packets too.
Signed-off-by Tiwei Bie <[email protected]>Signed-off-by Zhihong Wang <[email protected]>Signed-off-by Zhiyong Yang <[email protected]>Reviewed-by Maxime Coquelin <[email protected]>---
This optimization depends on the CPU internal pipeline design. So further tests (e.g. ARM) from the community is appreciated.
Quoted 3 lines
Quoted 1 line
v2: s/burst_copy/batch_copy/g
In pvp setup for arm64 platform, no performance drop noticed with this patch but no significant performance gain either. Tested-by: Santosh Shukla <[email protected]>
Applied to dpdk-next-virtio.
Thanks.
--yliu