All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <levinsasha928@gmail.com>
To: Avi Kivity <avi@redhat.com>
Cc: markmc@redhat.com, kvm@vger.kernel.org,
	"Michael S. Tsirkin" <mst@redhat.com>,
	linux-kernel@vger.kernel.org,
	virtualization@lists.linux-foundation.org
Subject: Re: [PATCH] virtio-ring: Use threshold for switching to indirect descriptors
Date: Sun, 04 Dec 2011 20:23:59 +0200	[thread overview]
Message-ID: <1323023039.3256.7.camel@lappy> (raw)
In-Reply-To: <1323020374.3256.5.camel@lappy>

On Sun, 2011-12-04 at 19:39 +0200, Sasha Levin wrote:
> On Sun, 2011-12-04 at 19:37 +0200, Avi Kivity wrote:
> > On 12/04/2011 07:34 PM, Sasha Levin wrote:
> > > > 
> > > > I'm confused. didn't you see a bigger benefit for guest->host by
> > > > switching indirect off?
> > >
> > > The 5% improvement is over the 'regular' indirect on, not over indirect
> > > off. Sorry for the confusion there.
> > >
> > > I suggested this change regardless of the outcome of indirect descriptor
> > > threshold discussion, since it would help anyways.
> > 
> > For net, this makes sense.  For block, it reduces the effective queue
> > depth, so it's not a trivial change.  It probably makes sense there too,
> > though.
> 
> It doesn't have to be limited at that number, anything above that can go
> through the regular kmalloc() path.

Something like the following patch:

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index c7a2c20..3166ca0 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;
+	struct kmem_cache *indirect_cache;
 
 	/* Host publishes avail event idx */
 	bool event;
@@ -110,6 +111,9 @@ struct vring_virtqueue
 
 #define to_vvq(_vq) container_of(_vq, struct vring_virtqueue, vq)
 
+static unsigned int ind_alloc_thresh = 0;
+module_param(ind_alloc_thresh, uint, S_IRUGO);
+
 /* Set up an indirect table of descriptors and add it to the queue. */
 static int vring_add_indirect(struct vring_virtqueue *vq,
 			      struct scatterlist sg[],
@@ -121,7 +125,10 @@ static int vring_add_indirect(struct vring_virtqueue *vq,
 	unsigned head;
 	int i;
 
-	desc = kmalloc((out + in) * sizeof(struct vring_desc), gfp);
+	if ((out + in) <= ind_alloc_thresh)
+		desc = kmem_cache_alloc(vq->indirect_cache, gfp);
+	else
+		desc = kmalloc((out + in) * sizeof(struct vring_desc), gfp);
 	if (!desc)
 		return -ENOMEM;
 
@@ -479,6 +486,9 @@ struct virtqueue *vring_new_virtqueue(unsigned int num,
 	vq->broken = false;
 	vq->last_used_idx = 0;
 	vq->num_added = 0;
+	if (ind_alloc_thresh)
+		vq->indirect_cache = KMEM_CACHE(vring_desc[ind_alloc_thresh], 0);
 	list_add_tail(&vq->vq.list, &vdev->vqs);
 #ifdef DEBUG
 	vq->in_use = false;

-- 

Sasha.

WARNING: multiple messages have this Message-ID (diff)
From: Sasha Levin <levinsasha928@gmail.com>
To: Avi Kivity <avi@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	Rusty Russell <rusty@rustcorp.com.au>,
	linux-kernel@vger.kernel.org,
	virtualization@lists.linux-foundation.org, kvm@vger.kernel.org,
	markmc@redhat.com
Subject: Re: [PATCH] virtio-ring: Use threshold for switching to indirect descriptors
Date: Sun, 04 Dec 2011 20:23:59 +0200	[thread overview]
Message-ID: <1323023039.3256.7.camel@lappy> (raw)
In-Reply-To: <1323020374.3256.5.camel@lappy>

On Sun, 2011-12-04 at 19:39 +0200, Sasha Levin wrote:
> On Sun, 2011-12-04 at 19:37 +0200, Avi Kivity wrote:
> > On 12/04/2011 07:34 PM, Sasha Levin wrote:
> > > > 
> > > > I'm confused. didn't you see a bigger benefit for guest->host by
> > > > switching indirect off?
> > >
> > > The 5% improvement is over the 'regular' indirect on, not over indirect
> > > off. Sorry for the confusion there.
> > >
> > > I suggested this change regardless of the outcome of indirect descriptor
> > > threshold discussion, since it would help anyways.
> > 
> > For net, this makes sense.  For block, it reduces the effective queue
> > depth, so it's not a trivial change.  It probably makes sense there too,
> > though.
> 
> It doesn't have to be limited at that number, anything above that can go
> through the regular kmalloc() path.

Something like the following patch:

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index c7a2c20..3166ca0 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;
+	struct kmem_cache *indirect_cache;
 
 	/* Host publishes avail event idx */
 	bool event;
@@ -110,6 +111,9 @@ struct vring_virtqueue
 
 #define to_vvq(_vq) container_of(_vq, struct vring_virtqueue, vq)
 
+static unsigned int ind_alloc_thresh = 0;
+module_param(ind_alloc_thresh, uint, S_IRUGO);
+
 /* Set up an indirect table of descriptors and add it to the queue. */
 static int vring_add_indirect(struct vring_virtqueue *vq,
 			      struct scatterlist sg[],
@@ -121,7 +125,10 @@ static int vring_add_indirect(struct vring_virtqueue *vq,
 	unsigned head;
 	int i;
 
-	desc = kmalloc((out + in) * sizeof(struct vring_desc), gfp);
+	if ((out + in) <= ind_alloc_thresh)
+		desc = kmem_cache_alloc(vq->indirect_cache, gfp);
+	else
+		desc = kmalloc((out + in) * sizeof(struct vring_desc), gfp);
 	if (!desc)
 		return -ENOMEM;
 
@@ -479,6 +486,9 @@ struct virtqueue *vring_new_virtqueue(unsigned int num,
 	vq->broken = false;
 	vq->last_used_idx = 0;
 	vq->num_added = 0;
+	if (ind_alloc_thresh)
+		vq->indirect_cache = KMEM_CACHE(vring_desc[ind_alloc_thresh], 0);
 	list_add_tail(&vq->vq.list, &vdev->vqs);
 #ifdef DEBUG
 	vq->in_use = false;

-- 

Sasha.


  reply	other threads:[~2011-12-04 18:23 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-29  9:33 [PATCH] virtio-ring: Use threshold for switching to indirect descriptors Sasha Levin
2011-11-29  9:33 ` Sasha Levin
2011-11-29 12:56 ` Michael S. Tsirkin
2011-11-29 12:56   ` Michael S. Tsirkin
2011-11-29 13:34   ` Sasha Levin
2011-11-29 13:34     ` Sasha Levin
2011-11-29 13:54     ` Michael S. Tsirkin
2011-11-29 14:21       ` Sasha Levin
2011-11-29 14:21         ` Sasha Levin
2011-11-29 14:54         ` Michael S. Tsirkin
2011-11-29 14:54           ` Michael S. Tsirkin
2011-11-29 14:58           ` Avi Kivity
2011-11-29 14:58             ` Avi Kivity
2011-11-30 16:11             ` Sasha Levin
2011-11-30 16:11               ` Sasha Levin
2011-11-30 16:17               ` Sasha Levin
2011-11-30 16:17                 ` Sasha Levin
2011-12-01  2:42               ` Rusty Russell
2011-12-01  2:42                 ` Rusty Russell
2011-12-01  7:58                 ` Michael S. Tsirkin
2011-12-01  7:58                   ` Michael S. Tsirkin
2011-12-01  8:09                   ` Sasha Levin
2011-12-01  8:09                     ` Sasha Levin
2011-12-01 10:26                     ` Michael S. Tsirkin
2011-12-01 10:26                       ` Michael S. Tsirkin
2011-12-02  0:46                       ` Rusty Russell
2011-12-02  0:46                         ` Rusty Russell
2011-12-03 11:50                         ` Sasha Levin
2011-12-03 11:50                           ` Sasha Levin
2011-12-04 11:06                           ` Michael S. Tsirkin
2011-12-04 11:06                             ` Michael S. Tsirkin
2011-12-04 15:15                             ` Michael S. Tsirkin
2011-12-04 15:15                               ` Michael S. Tsirkin
2011-12-04 11:52                           ` Avi Kivity
2011-12-04 11:52                             ` Avi Kivity
2011-12-04 12:01                             ` Michael S. Tsirkin
2011-12-04 12:01                               ` Michael S. Tsirkin
2011-12-04 12:06                               ` Avi Kivity
2011-12-04 12:06                                 ` Avi Kivity
2011-12-04 15:11                                 ` Michael S. Tsirkin
2011-12-04 15:11                                   ` Michael S. Tsirkin
2011-12-04 15:16                                   ` Avi Kivity
2011-12-04 15:16                                     ` Avi Kivity
2011-12-04 16:00                                     ` Michael S. Tsirkin
2011-12-04 16:00                                       ` Michael S. Tsirkin
2011-12-04 16:33                                       ` Avi Kivity
2011-12-04 16:33                                         ` Avi Kivity
2011-12-05  0:10                                     ` Rusty Russell
2011-12-05  0:10                                       ` Rusty Russell
2011-12-05  9:52                                       ` Avi Kivity
2011-12-05  9:52                                         ` Avi Kivity
2011-12-06  5:07                                         ` Rusty Russell
2011-12-06  5:07                                           ` Rusty Russell
2011-12-06  9:58                                           ` Avi Kivity
2011-12-06  9:58                                             ` Avi Kivity
2011-12-06 12:03                                             ` Rusty Russell
2011-12-07 13:37                                               ` Avi Kivity
2011-12-07 13:37                                                 ` Avi Kivity
2011-12-06 12:03                                             ` Rusty Russell
2011-12-04 12:13                             ` Sasha Levin
2011-12-04 12:13                               ` Sasha Levin
2011-12-04 16:22                               ` Michael S. Tsirkin
2011-12-04 16:22                                 ` Michael S. Tsirkin
2011-12-04 17:34                                 ` Sasha Levin
2011-12-04 17:34                                   ` Sasha Levin
2011-12-04 17:37                                   ` Avi Kivity
2011-12-04 17:37                                     ` Avi Kivity
2011-12-04 17:39                                     ` Sasha Levin
2011-12-04 17:39                                       ` Sasha Levin
2011-12-04 18:23                                       ` Sasha Levin [this message]
2011-12-04 18:23                                         ` Sasha Levin
2011-12-07 14:02                                         ` Sasha Levin
2011-12-07 14:02                                           ` Sasha Levin
2011-12-07 15:48                                           ` Michael S. Tsirkin
2011-12-07 15:48                                             ` Michael S. Tsirkin
2011-12-08  9:44                                             ` Rusty Russell
2011-12-08 10:37                                               ` Sasha Levin
2011-12-08 10:37                                                 ` Sasha Levin
2011-12-09  5:33                                                 ` Rusty Russell
2011-12-09  5:33                                                 ` Rusty Russell
2011-12-08  9:44                                             ` Rusty Russell
2011-11-29 13:54     ` Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1323023039.3256.7.camel@lappy \
    --to=levinsasha928@gmail.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markmc@redhat.com \
    --cc=mst@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.