mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Eugenio Pérez" <eperezma@redhat.com>
To: linux-kernel@vger.kernel.org, mst@redhat.com,
	Hanna Reitz <hreitz@redhat.com>,
	Stefano Garzarella <sgarzare@redhat.com>,
	Xuan Zhuo <xuanzhuo@linux.alibaba.com>,
	Jason Wang <jasowang@redhat.com>, Vivek Goyal <vgoyal@redhat.com>,
	Miklos Szeredi <miklos@szeredi.hu>,
	German Maglione <gmaglione@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	virtualization@lists.linux.dev
Subject: [RFC 5/5] virtiofs: perform DMA operations out of the spinlock
Date: Wed, 22 Jan 2025 17:31:54 +0100	[thread overview]
Message-ID: <20250122163154.1225353-6-eperezma@redhat.com> (raw)
In-Reply-To: <20250122163154.1225353-1-eperezma@redhat.com>

This is useful for some setups like swiotlb or VDUSE where the DMA
operations are expensive and/or need to be performed with a write lock.

After applying this patch, fio read test goes from 1201MiB/s to 1211MiB/s.

Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
 drivers/virtio/virtio_ring.c |  2 ++
 fs/fuse/virtio_fs.c          | 25 +++++++++++++++++++++++--
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index e49912fa77c5..eb22bfcb9100 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -580,6 +580,7 @@ int virtqueue_map_sgs(struct virtqueue *_vq,
 				goto unmap_release;
 
 			sg_dma_address(sg) = addr;
+			sg_dma_len(sg) = sg->length;
 			mapped_sg++;
 		}
 	}
@@ -592,6 +593,7 @@ int virtqueue_map_sgs(struct virtqueue *_vq,
 				goto unmap_release;
 
 			sg_dma_address(sg) = addr;
+			sg_dma_len(sg) = sg->length;
 			mapped_sg++;
 		}
 	}
diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c
index 1344c5782a7c..2b558b05d0f8 100644
--- a/fs/fuse/virtio_fs.c
+++ b/fs/fuse/virtio_fs.c
@@ -836,8 +836,21 @@ static void virtio_fs_requests_done_work(struct work_struct *work)
 
 	/* End requests */
 	list_for_each_entry_safe(req, next, &reqs, list) {
+		struct scatterlist *stack_sgs[6];
+		struct scatterlist **sgs = stack_sgs;
+		unsigned int total_sgs = req->out_sgs + req->in_sgs;
+
 		list_del_init(&req->list);
 
+		/* TODO replace magic 6 by a macro */
+		if (total_sgs > 6)
+			sgs = kmalloc_array(total_sgs, sizeof(sgs[0]), GFP_ATOMIC);
+
+		for (unsigned int i = 0; i < total_sgs; ++i)
+			sgs[i] = &req->sg[i];
+
+		virtqueue_unmap_sgs(vq, sgs, req->out_sgs, req->in_sgs);
+
 		/* blocking async request completes in a worker context */
 		if (req->args->may_block) {
 			struct virtio_fs_req_work *w;
@@ -850,6 +863,9 @@ static void virtio_fs_requests_done_work(struct work_struct *work)
 		} else {
 			virtio_fs_request_complete(req, fsvq);
 		}
+
+		if (sgs != stack_sgs)
+			kfree(sgs);
 	}
 
 	/* Try to push previously queued requests, as the queue might no longer be full */
@@ -1426,6 +1442,11 @@ static int virtio_fs_enqueue_req(struct virtio_fs_vq *fsvq,
 		sgs[i] = &req->sg[i];
 	WARN_ON(req->out_sgs + req->in_sgs != total_sgs);
 
+	// TODO can we change this ptr out of the lock?
+	vq = fsvq->vq;
+	// TODO handle this and following errors
+	ret = virtqueue_map_sgs(vq, sgs, req->out_sgs, req->in_sgs);
+	BUG_ON(ret < 0);
 	spin_lock(&fsvq->lock);
 
 	if (!fsvq->connected) {
@@ -1434,8 +1455,8 @@ static int virtio_fs_enqueue_req(struct virtio_fs_vq *fsvq,
 		goto out;
 	}
 
-	vq = fsvq->vq;
-	ret = virtqueue_add_sgs(vq, sgs, req->out_sgs, req->in_sgs, req, GFP_ATOMIC);
+	ret = virtqueue_add_sgs_premapped(vq, sgs, req->out_sgs,
+					  req->in_sgs, req, GFP_ATOMIC);
 	if (ret < 0) {
 		spin_unlock(&fsvq->lock);
 		goto out;
-- 
2.48.1


  parent reply	other threads:[~2025-01-22 16:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-22 16:31 [RFC 0/5] virtiofs: map buffer out of virtqueue lock Eugenio Pérez
2025-01-22 16:31 ` [RFC 1/5] vduse: add virtio_fs to allowed dev id Eugenio Pérez
2025-01-23  1:48   ` Jason Wang
2025-01-22 16:31 ` [RFC 2/5] virtio_ring: introduce virtqueue_map/unmap_sgs() Eugenio Pérez
2025-01-23  1:51   ` Jason Wang
2025-01-23  7:31     ` Eugenio Perez Martin
2025-01-24  1:03       ` Jason Wang
2025-01-22 16:31 ` [RFC 3/5] virtiofs: Move stack sg to fuse_req Eugenio Pérez
2025-01-23  1:54   ` Jason Wang
2025-01-23  7:33     ` Eugenio Perez Martin
2025-01-22 16:31 ` [RFC 4/5] virtio_ring: add virtqueue premapped out/in buffers support Eugenio Pérez
2025-01-22 16:31 ` Eugenio Pérez [this message]
2025-01-23  1:56   ` [RFC 5/5] virtiofs: perform DMA operations out of the spinlock Jason Wang
2025-01-23  2:26     ` Jason Wang

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=20250122163154.1225353-6-eperezma@redhat.com \
    --to=eperezma@redhat.com \
    --cc=gmaglione@redhat.com \
    --cc=hreitz@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=mst@redhat.com \
    --cc=sgarzare@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=vgoyal@redhat.com \
    --cc=virtualization@lists.linux.dev \
    --cc=xuanzhuo@linux.alibaba.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®