kvm tools: Support virtio indirect buffers
PATCH 1/1 kvm tools: Support virtio indirect buffers
Indirect buffers are ring descriptors which point to more (even more) descriptors.
This can be used to increase the effective ring capacity, which helps the guest to batch large requests - very useful for blk devices.
This patch also enables indirect buffers for virtio-net and virtio-blk.
The patch is based on the lguest's code which does the same.
--- tools/kvm/virtio/blk.c | 3 ++- tools/kvm/virtio/core.c | 47 ++++++++++++++++++++++++++++++++++++++--------- tools/kvm/virtio/net.c | 3 ++- 3 files changed, 42 insertions(+), 11 deletions(-)
tools/kvm/virtio/blk.c +2 -1
@@ -148,7 +148,8 @@ static u32 get_host_features(struct kvm *kvm, void *dev) {return 1UL <<VIRTIO_BLK_F_SEG_MAX |1UL <<VIRTIO_BLK_F_FLUSH - |1UL <<VIRTIO_RING_F_EVENT_IDX ; + |1UL <<VIRTIO_RING_F_EVENT_IDX + |1UL <<VIRTIO_RING_F_INDIRECT_DESC ; }static void set_guest_features (struct kvm *kvm,void *dev,u32 features)
tools/kvm/virtio/core.c +38 -9
65 lines not on this page · raw message
tools/kvm/virtio/net.c +2 -1
@@ -318,7 +318,8 @@ static u32 get_host_features(struct kvm *kvm, void *dev) | 1UL << VIRTIO_NET_F_GUEST_UFO |1UL <<VIRTIO_NET_F_GUEST_TSO4 |1UL <<VIRTIO_NET_F_GUEST_TSO6 - |1UL <<VIRTIO_RING_F_EVENT_IDX ; + |1UL <<VIRTIO_RING_F_EVENT_IDX + |1UL <<VIRTIO_RING_F_INDIRECT_DESC ; }static void set_guest_features (struct kvm *kvm,void *dev,u32 features)
Signature · 1 line
1.7.8.rc3
Quoted 11 lines · Sasha Levin
Indirect buffers are ring descriptors which point to more (even more) descriptors.
This can be used to increase the effective ring capacity, which helps the guest to batch large requests - very useful for blk devices.
This patch also enables indirect buffers for virtio-net and virtio-blk.
The patch is based on the lguest's code which does the same.
Signed-off-by Sasha Levin <[email protected]>
In what exact way is it useful? Improved throughput? Will this have negative impact on virtio block or virtio net latency?
Pekka
Quoted 7 lines · Pekka Enberg
Quoted 6 lines · Sasha Levin
Indirect buffers are ring descriptors which point to more (even more) descriptors.
This can be used to increase the effective ring capacity, which helps the guest to batch large requests - very useful for blk devices.
Quoted 8 lines
Quoted 5 lines
This patch also enables indirect buffers for virtio-net and virtio-blk.
The patch is based on the lguest's code which does the same.
Signed-off-by Sasha Levin <[email protected]>In what exact way is it useful? Improved throughput? Will this have negative impact on virtio block or virtio net latency?
The total size of requests is limited by the size of the virtio ring. This makes it hard to squeeze large requests (like the ones you usually see with blk devices) into the ring. This patch simply makes each entry in the virtio ring point to another descriptor list, thus it allows to squeeze much more requests into a singe virtio ring.
It shouldn't hurt latency.
I tried getting benchmarks with it, but the results I get from fio are all over the place and I can't seem to get a steady result (bad sign for my poor spindle disk).
Signature · 1 line
Sasha.
Quoted 23 lines · Sasha Levin
Quoted 7 lines · Pekka Enberg
Quoted 6 lines · Sasha Levin
Indirect buffers are ring descriptors which point to more (even more) descriptors.
This can be used to increase the effective ring capacity, which helps the guest to batch large requests - very useful for blk devices.
Quoted 8 lines
Quoted 5 lines
This patch also enables indirect buffers for virtio-net and virtio-blk.
The patch is based on the lguest's code which does the same.
Signed-off-by Sasha Levin <[email protected]>In what exact way is it useful? Improved throughput? Will this have negative impact on virtio block or virtio net latency?
The total size of requests is limited by the size of the virtio ring. This makes it hard to squeeze large requests (like the ones you usually see with blk devices) into the ring. This patch simply makes each entry in the virtio ring point to another descriptor list, thus it allows to squeeze much more requests into a singe virtio ring.
Quoted 5 lines
It shouldn't hurt latency.
I tried getting benchmarks with it, but the results I get from fio are all over the place and I can't seem to get a steady result (bad sign for my poor spindle disk).
btw, on an unrelated subject, I think that with this patch we've fully covered the virtio spec, and as far as I know it's the first userspace implementation which covers the entire spec :)
Signature · 1 line
Sasha.
Quoted 4 lines · Sasha Levin
On Mon, 2011-11-28 at 22:17 +0200, Sasha Levin wrote:
btw, on an unrelated subject, I think that with this patch we've fully covered the virtio spec, and as far as I know it's the first userspace implementation which covers the entire spec :)
BTW, why did you bother implementing virtio-mmio? It seems like gratuitous bloat. I hope you're not going the same way as qemu :(
Thanks,
Rusty.
Quoted 13 lines · Sasha Levin
tools/kvm/virtio/core.c +12
-0+/* +* Each buffer in the virtqueues is actually a chain of descriptors. This +* function returns the next descriptor in the chain, or vq->vring.num if we're +* at the end. +*/ +static unsigned next_desc (struct vring_desc *desc, +unsigned int i,unsigned int max) +{ +unsigned int next; + +/* If this descriptor says it doesn't chain, we're done. */ +if (!(desc[i].flags &VRING_DESC_F_NEXT ))
tools/kvm/virtio/core.c struct vring_used_elem *virt_queue__set_used_elem(struct virt_queue *queue, u32 · line 57
Quoted 10 lines
tools/kvm/virtio/core.c +10
-0+return max; + +/* Check they're not leading us off end of descriptors. */ + next = desc[i].next; +/* Make sure compiler knows to grab that: we don't want it changing! */ +wmb (); + +return next; +} +
Hi Sasha, where the rmb() then? Or maybe you wanted plain barrier() here?
Quoted 18 lines · Cyrill Gorcunov
Quoted 17 lines · Sasha Levin
tools/kvm/virtio/core.c +16
-0+/* +* Each buffer in the virtqueues is actually a chain of descriptors. This +* function returns the next descriptor in the chain, or vq->vring.num if we're +* at the end. +*/ +static unsigned next_desc (struct vring_desc *desc, +unsigned int i,unsigned int max) +{ +unsigned int next; + +/* If this descriptor says it doesn't chain, we're done. */ +if (!(desc[i].flags &VRING_DESC_F_NEXT )) +return max; + +/* Check they're not leading us off end of descriptors. */ + next = desc[i].next;
Quoted 8 lines
tools/kvm/virtio/core.c struct vring_used_elem *virt_queue__set_used_elem(struct virt_queue *queue, u32 · line 57
Quoted 6 lines
tools/kvm/virtio/core.c +6
-0+/* Make sure compiler knows to grab that: we don't want it changing! */ +wmb (); + +return next; +} +Hi Sasha, where the
rmb()then? Or maybe you wanted plainbarrier()here?
On the kernel side.
Theres a mb there which happens there during the kick.
Signature · 1 line
Sasha.
Quoted 25 lines · Sasha Levin
Quoted 16 lines
Quoted 16 lines
tools/kvm/virtio/core.c +16
-0+/* +* Each buffer in the virtqueues is actually a chain of descriptors. This +* function returns the next descriptor in the chain, or vq->vring.num if we're +* at the end. +*/ +static unsigned next_desc (struct vring_desc *desc, +unsigned int i,unsigned int max) +{ +unsigned int next; + +/* If this descriptor says it doesn't chain, we're done. */ +if (!(desc[i].flags &VRING_DESC_F_NEXT )) +return max; + +/* Check they're not leading us off end of descriptors. */ + next = desc[i].next;Quoted 8 lines
tools/kvm/virtio/core.c struct vring_used_elem *virt_queue__set_used_elem(struct virt_queue *queue, u32 · line 57
Quoted 6 lines
tools/kvm/virtio/core.c +6
-0+/* Make sure compiler knows to grab that: we don't want it changing! */ +wmb (); + +return next; +} +Hi Sasha, where the
rmb()then? Or maybe you wanted plainbarrier()here?
Quoted 2 lines
On the kernel side.
Theres a mb there which happens there during the kick.
I guess we need to improve the comment in next_desc()?
Quoted 8 lines · Pekka Enberg
Quoted 5 lines
Quoted 2 lines
Hi Sasha, where the
rmb()then? Or maybe you wanted plainbarrier()here?On the kernel side.
Theres a mb there which happens there during the kick.I guess we need to improve the comment in
next_desc()?
Kernel's code has pretty good aliases for virtio barriers I think
#ifdef CONFIG_SMP
/* Where possible, use SMP barriers which are more lightweight than mandatory
* barriers, because mandatory barriers control MMIO effects on accesses
* through relaxed memory I/O windows (which virtio does not use). */
#define virtio_mb() smp_mb()
#define virtio_rmb() smp_rmb()
#define virtio_wmb() smp_wmb()
#else
/* We must force memory ordering even if guest is UP since host could be
* running on another CPU, but SMP barriers are defined to barrier() in that
* configuration. So fall back to mandatory barriers instead. */
#define virtio_mb() mb()
#define virtio_rmb() rmb()
#define virtio_wmb() wmb()
#endif
Maybe we could use somethig similar?