From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: virtio-fs@redhat.com, Liu Bo <bo.liu@linux.alibaba.com>,
qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/4] virtiofsd: process requests in a thread pool
Date: Mon, 5 Aug 2019 13:02:31 +0100 [thread overview]
Message-ID: <20190805120231.GL13734@work-vm> (raw)
In-Reply-To: <20190801165409.20121-2-stefanha@redhat.com>
* Stefan Hajnoczi (stefanha@redhat.com) wrote:
> Introduce a thread pool so that fv_queue_thread() just pops
> VuVirtqElements and hands them to the thread pool. For the time being
> only one worker thread is allowed since passthrough_ll.c is not
> thread-safe yet. Future patches will lift this restriction so that
> multiple FUSE requests can be processed in parallel.
>
> The main new concept is struct FVRequest, which contains both
> VuVirtqElement and struct fuse_chan. We now have fv_VuDev for a device,
> fv_QueueInfo for a virtqueue, and FVRequest for a request. Some of
> fv_QueueInfo's fields are moved into FVRequest because they are
> per-request. The name FVRequest conforms to QEMU coding style and I
> expect the struct fv_* types will be renamed in a future refactoring.
>
> This patch series is not optimal. fbuf reuse is dropped so each request
> does malloc(se->bufsize), but there is no clean and cheap way to keep
> this with a thread pool. The vq_lock mutex is held for longer than
> necessary, especially during the eventfd_write() syscall. Performance
> can be improved in the future.
>
> prctl(2) had to be added to the seccomp whitelist because glib invokes
> it.
>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Thanks, applied; some comments below.
> +
> + pthread_rwlock_rdlock(&qi->virtio_dev->vu_dispatch_rwlock);
> + pthread_mutex_lock(&qi->vq_lock);
> + vu_queue_push(dev, q, elem, tosend_len);
> + vu_queue_notify(dev, q);
> + pthread_mutex_unlock(&qi->vq_lock);
> + pthread_rwlock_unlock(&qi->virtio_dev->vu_dispatch_rwlock);
It surprises me that these paired locks are so common.
>
> err:
>
> @@ -249,9 +268,12 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
> struct iovec *iov, int count,
> struct fuse_bufvec *buf, size_t len)
> {
> + FVRequest *req = container_of(ch, FVRequest, ch);
I can't think of a better answer than the container_of but it does make
me a bit nervous; I guess we need it because 'ch' comes from the generic
fs code so can't be FVRequest*
> + struct VuDev *dev = &qi->virtio_dev->dev;
> + FVRequest *req = data;
> + VuVirtqElement *elem = &req->elem;
> + struct fuse_buf fbuf = {};
> + bool allocated_bufv = false;
> + struct fuse_bufvec bufv;
> + struct fuse_bufvec *pbufv;
> +
> + assert(se->bufsize > sizeof(struct fuse_in_header));
> +
> + /* An element contains one request and the space to send our response
> + * They're spread over multiple descriptors in a scatter/gather set
> + * and we can't trust the guest to keep them still; so copy in/out.
> + */
> + fbuf.mem = malloc(se->bufsize);
> + assert(fbuf.mem);
Now we're using thread pools etc, maybe it's time to switch to glib's
g_new/g_malloc etc that never return NULL?
> + if (se->debug)
> + fuse_debug("%s: elem %d: with %d out desc of length %zd"
> + " bad_in_num=%u bad_out_num=%u\n",
> + __func__, elem->index, out_num,
> + out_len, req->bad_in_num, req->bad_out_num);
Are the debug/logging calls thread safe?
> diff --git a/contrib/virtiofsd/seccomp.c b/contrib/virtiofsd/seccomp.c
> index cea4cc5f60..5f1c873b82 100644
> --- a/contrib/virtiofsd/seccomp.c
> +++ b/contrib/virtiofsd/seccomp.c
> @@ -58,6 +58,7 @@ static const int syscall_whitelist[] = {
> SCMP_SYS(open),
> SCMP_SYS(openat),
> SCMP_SYS(ppoll),
> + SCMP_SYS(prctl), /* TODO restrict to just PR_SET_NAME? */
Would seem a good idea because prctl can do lots of crazy things.
Dave
> SCMP_SYS(preadv),
> SCMP_SYS(pwrite64),
> SCMP_SYS(read),
> --
> 2.21.0
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
next prev parent reply other threads:[~2019-08-05 12:04 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-01 16:54 [Qemu-devel] [PATCH 0/4] virtiofsd: multithreading preparation part 3 Stefan Hajnoczi
2019-08-01 16:54 ` [Qemu-devel] [PATCH 1/4] virtiofsd: process requests in a thread pool Stefan Hajnoczi
2019-08-05 12:02 ` Dr. David Alan Gilbert [this message]
2019-08-07 9:35 ` Stefan Hajnoczi
2019-08-01 16:54 ` [Qemu-devel] [PATCH 2/4] virtiofsd: prevent FUSE_INIT/FUSE_DESTROY races Stefan Hajnoczi
2019-08-05 12:26 ` Dr. David Alan Gilbert
2019-08-01 16:54 ` [Qemu-devel] [PATCH 3/4] virtiofsd: fix lo_destroy() resource leaks Stefan Hajnoczi
2019-08-05 15:17 ` Dr. David Alan Gilbert
2019-08-05 18:57 ` Dr. David Alan Gilbert
2019-08-06 18:58 ` Dr. David Alan Gilbert
2019-08-07 9:41 ` Stefan Hajnoczi
2019-08-01 16:54 ` [Qemu-devel] [PATCH 4/4] virtiofsd: add --thread-pool-size=NUM option Stefan Hajnoczi
2019-08-05 2:52 ` [Qemu-devel] [Virtio-fs] [PATCH 0/4] virtiofsd: multithreading preparation part 3 piaojun
2019-08-05 8:01 ` Stefan Hajnoczi
2019-08-05 9:40 ` piaojun
2019-08-07 18:03 ` [Qemu-devel] " Stefan Hajnoczi
2019-08-07 20:57 ` [Qemu-devel] [Virtio-fs] " Vivek Goyal
2019-08-08 9:02 ` Stefan Hajnoczi
2019-08-08 9:53 ` Dr. David Alan Gilbert
2019-08-08 12:53 ` Vivek Goyal
2019-08-09 8:23 ` Stefan Hajnoczi
2019-08-10 21:35 ` Liu Bo
2019-08-09 8:21 ` Stefan Hajnoczi
2019-08-10 21:34 ` Liu Bo
2019-08-11 2:26 ` piaojun
2019-08-12 10:05 ` Stefan Hajnoczi
2019-08-12 11:58 ` piaojun
2019-08-12 12:51 ` Dr. David Alan Gilbert
2019-08-08 8:10 ` piaojun
2019-08-08 9:53 ` Stefan Hajnoczi
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=20190805120231.GL13734@work-vm \
--to=dgilbert@redhat.com \
--cc=bo.liu@linux.alibaba.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=virtio-fs@redhat.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;
as well as URLs for NNTP newsgroup(s).