virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] virtio-ring: Use threshold for switching to indirect descriptors
@ 2011-11-29  9:33 Sasha Levin
  2011-11-29 12:56 ` Michael S. Tsirkin
  0 siblings, 1 reply; 41+ messages in thread
From: Sasha Levin @ 2011-11-29  9:33 UTC (permalink / raw)
  To: linux-kernel; +Cc: virtualization, Sasha Levin, kvm, Michael S. Tsirkin

Currently if VIRTIO_RING_F_INDIRECT_DESC is enabled we will use indirect
descriptors even if we have plenty of space in the ring. This means that
we take a performance hit at all times due to the overhead of creating
indirect descriptors.

With this patch, we will use indirect descriptors only if we have less than
either 16, or 12% of the total amount of descriptors available.

I did basic performance benchmark on virtio-net with vhost enabled.

Before:
	Recv   Send    Send
	Socket Socket  Message  Elapsed
	Size   Size    Size     Time     Throughput
	bytes  bytes   bytes    secs.    10^6bits/sec

	 87380  16384  16384    10.00    4563.92

After:
	Recv   Send    Send
	Socket Socket  Message  Elapsed
	Size   Size    Size     Time     Throughput
	bytes  bytes   bytes    secs.    10^6bits/sec

	 87380  16384  16384    10.00    5353.28

Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: virtualization@lists.linux-foundation.org
Cc: kvm@vger.kernel.org
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 drivers/virtio/virtio_ring.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index c7a2c20..5e0ce15 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -82,6 +82,7 @@ struct vring_virtqueue
 
 	/* Host supports indirect buffers */
 	bool indirect;
+	unsigned int indirect_threshold;
 
 	/* Host publishes avail event idx */
 	bool event;
@@ -176,8 +177,9 @@ int virtqueue_add_buf_gfp(struct virtqueue *_vq,
 	BUG_ON(data == NULL);
 
 	/* If the host supports indirect descriptor tables, and we have multiple
-	 * buffers, then go indirect. FIXME: tune this threshold */
-	if (vq->indirect && (out + in) > 1 && vq->num_free) {
+	 * buffers, then go indirect. */
+	if (vq->indirect && (out + in) > 1 &&
+	   (vq->num_free < vq->indirect_threshold)) {
 		head = vring_add_indirect(vq, sg, out, in, gfp);
 		if (likely(head >= 0))
 			goto add_head;
@@ -485,6 +487,12 @@ struct virtqueue *vring_new_virtqueue(unsigned int num,
 #endif
 
 	vq->indirect = virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC);
+	/*
+	 * Use indirect descriptors only when we have less than either 12%
+	 * or 16 of the descriptors in the ring available.
+	 */
+	if (vq->indirect)
+		vq->indirect_threshold = max(16U, num >> 3);
 	vq->event = virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX);
 
 	/* No callback?  Tell other side not to bother us. */
-- 
1.7.8.rc3

^ permalink raw reply related	[flat|nested] 41+ messages in thread

end of thread, other threads:[~2011-12-09  5:33 UTC | newest]

Thread overview: 41+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-29  9:33 [PATCH] virtio-ring: Use threshold for switching to indirect descriptors Sasha Levin
2011-11-29 12:56 ` Michael S. Tsirkin
2011-11-29 13:34   ` Sasha Levin
2011-11-29 13:54     ` Michael S. Tsirkin
     [not found]     ` <20111129135406.GB30966@redhat.com>
2011-11-29 14:21       ` Sasha Levin
2011-11-29 14:54         ` Michael S. Tsirkin
2011-11-29 14:58           ` Avi Kivity
2011-11-30 16:11             ` Sasha Levin
2011-11-30 16:17               ` Sasha Levin
2011-12-01  2:42               ` Rusty Russell
2011-12-01  7:58                 ` Michael S. Tsirkin
2011-12-01  8:09                   ` Sasha Levin
2011-12-01 10:26                     ` Michael S. Tsirkin
2011-12-02  0:46                       ` Rusty Russell
2011-12-03 11:50                         ` Sasha Levin
2011-12-04 11:06                           ` Michael S. Tsirkin
2011-12-04 15:15                             ` Michael S. Tsirkin
2011-12-04 11:52                           ` Avi Kivity
2011-12-04 12:01                             ` Michael S. Tsirkin
2011-12-04 12:06                               ` Avi Kivity
2011-12-04 15:11                                 ` Michael S. Tsirkin
2011-12-04 15:16                                   ` Avi Kivity
2011-12-04 16:00                                     ` Michael S. Tsirkin
2011-12-04 16:33                                       ` Avi Kivity
2011-12-05  0:10                                     ` Rusty Russell
2011-12-05  9:52                                       ` Avi Kivity
2011-12-06  5:07                                         ` Rusty Russell
2011-12-06  9:58                                           ` Avi Kivity
2011-12-06 12:03                                             ` Rusty Russell
     [not found]                                             ` <87pqg1kiuu.fsf@rustcorp.com.au>
2011-12-07 13:37                                               ` Avi Kivity
2011-12-04 12:13                             ` Sasha Levin
2011-12-04 16:22                               ` Michael S. Tsirkin
2011-12-04 17:34                                 ` Sasha Levin
2011-12-04 17:37                                   ` Avi Kivity
2011-12-04 17:39                                     ` Sasha Levin
2011-12-04 18:23                                       ` Sasha Levin
2011-12-07 14:02                                         ` Sasha Levin
2011-12-07 15:48                                           ` Michael S. Tsirkin
2011-12-08  9:44                                             ` Rusty Russell
     [not found]                                             ` <87r50fgzyj.fsf@rustcorp.com.au>
2011-12-08 10:37                                               ` Sasha Levin
2011-12-09  5:33                                                 ` Rusty Russell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).