diff mbox series

[103/104] virtiofsd: add --thread-pool-size=NUM option

Message ID 20191212163904.159893-104-dgilbert@redhat.com
State New
Headers show
Series virtiofs daemon [all] | expand

Commit Message

Dr. David Alan Gilbert Dec. 12, 2019, 4:39 p.m. UTC
From: Stefan Hajnoczi <stefanha@redhat.com>

Add an option to control the size of the thread pool.  Requests are now
processed in parallel by default.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 tools/virtiofsd/fuse_i.h        | 1 +
 tools/virtiofsd/fuse_lowlevel.c | 7 ++++++-
 tools/virtiofsd/fuse_virtio.c   | 5 +++--
 3 files changed, 10 insertions(+), 3 deletions(-)

Comments

Daniel P. Berrangé Jan. 7, 2020, 12:25 p.m. UTC | #1
On Thu, Dec 12, 2019 at 04:39:03PM +0000, Dr. David Alan Gilbert (git) wrote:
> From: Stefan Hajnoczi <stefanha@redhat.com>
> 
> Add an option to control the size of the thread pool.  Requests are now
> processed in parallel by default.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  tools/virtiofsd/fuse_i.h        | 1 +
>  tools/virtiofsd/fuse_lowlevel.c | 7 ++++++-
>  tools/virtiofsd/fuse_virtio.c   | 5 +++--
>  3 files changed, 10 insertions(+), 3 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
Philippe Mathieu-Daudé Jan. 17, 2020, 1:35 p.m. UTC | #2
On 12/12/19 5:39 PM, Dr. David Alan Gilbert (git) wrote:
> From: Stefan Hajnoczi <stefanha@redhat.com>
> 
> Add an option to control the size of the thread pool.  Requests are now
> processed in parallel by default.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>   tools/virtiofsd/fuse_i.h        | 1 +
>   tools/virtiofsd/fuse_lowlevel.c | 7 ++++++-
>   tools/virtiofsd/fuse_virtio.c   | 5 +++--
>   3 files changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/virtiofsd/fuse_i.h b/tools/virtiofsd/fuse_i.h
> index 8a4a05b319..4da6a242ba 100644
> --- a/tools/virtiofsd/fuse_i.h
> +++ b/tools/virtiofsd/fuse_i.h
> @@ -72,6 +72,7 @@ struct fuse_session {
>       int   vu_listen_fd;
>       int   vu_socketfd;
>       struct fv_VuDev *virtio_dev;
> +    int thread_pool_size;
>   };
>   
>   struct fuse_chan {
> diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowlevel.c
> index 9f01c05e3e..09a7b23726 100644
> --- a/tools/virtiofsd/fuse_lowlevel.c
> +++ b/tools/virtiofsd/fuse_lowlevel.c
> @@ -27,6 +27,7 @@
>   #include <sys/file.h>
>   #include <unistd.h>
>   
> +#define THREAD_POOL_SIZE 64
>   
>   #define OFFSET_MAX 0x7fffffffffffffffLL
>   
> @@ -2523,6 +2524,7 @@ static const struct fuse_opt fuse_ll_opts[] = {
>       LL_OPTION("--socket-path=%s", vu_socket_path, 0),
>       LL_OPTION("vhost_user_socket=%s", vu_socket_path, 0),
>       LL_OPTION("--fd=%d", vu_listen_fd, 0),
> +    LL_OPTION("--thread-pool-size=%d", thread_pool_size, 0),
>       FUSE_OPT_END
>   };
>   
> @@ -2544,7 +2546,9 @@ void fuse_lowlevel_help(void)
>           "    --socket-path=PATH         path for the vhost-user socket\n"
>           "    -o vhost_user_socket=PATH  path for the vhost-user socket\n"
>           "    --fd=FDNUM                 fd number of vhost-user socket\n"
> -        "    -o auto_unmount            auto unmount on process termination\n");
> +        "    -o auto_unmount            auto unmount on process termination\n"
> +        "    --thread-pool-size=NUM     thread pool size limit (default %d)\n",
> +        THREAD_POOL_SIZE);
>   }
>   
>   void fuse_session_destroy(struct fuse_session *se)
> @@ -2598,6 +2602,7 @@ struct fuse_session *fuse_session_new(struct fuse_args *args,
>       }
>       se->fd = -1;
>       se->vu_listen_fd = -1;
> +    se->thread_pool_size = THREAD_POOL_SIZE;
>       se->conn.max_write = UINT_MAX;
>       se->conn.max_readahead = UINT_MAX;
>   
> diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c
> index b696ac3135..7bc6ff2f19 100644
> --- a/tools/virtiofsd/fuse_virtio.c
> +++ b/tools/virtiofsd/fuse_virtio.c
> @@ -570,10 +570,11 @@ static void *fv_queue_thread(void *opaque)
>       struct fv_QueueInfo *qi = opaque;
>       struct VuDev *dev = &qi->virtio_dev->dev;
>       struct VuVirtq *q = vu_get_queue(dev, qi->qidx);
> +    struct fuse_session *se = qi->virtio_dev->se;
>       GThreadPool *pool;
>   
> -    pool = g_thread_pool_new(fv_queue_worker, qi, 1 /* TODO max_threads */,
> -                             TRUE, NULL);
> +    pool = g_thread_pool_new(fv_queue_worker, qi, se->thread_pool_size, TRUE,
> +                             NULL);
>       if (!pool) {
>           fuse_log(FUSE_LOG_ERR, "%s: g_thread_pool_new failed\n", __func__);
>           return NULL;
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
diff mbox series

Patch

diff --git a/tools/virtiofsd/fuse_i.h b/tools/virtiofsd/fuse_i.h
index 8a4a05b319..4da6a242ba 100644
--- a/tools/virtiofsd/fuse_i.h
+++ b/tools/virtiofsd/fuse_i.h
@@ -72,6 +72,7 @@  struct fuse_session {
     int   vu_listen_fd;
     int   vu_socketfd;
     struct fv_VuDev *virtio_dev;
+    int thread_pool_size;
 };
 
 struct fuse_chan {
diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowlevel.c
index 9f01c05e3e..09a7b23726 100644
--- a/tools/virtiofsd/fuse_lowlevel.c
+++ b/tools/virtiofsd/fuse_lowlevel.c
@@ -27,6 +27,7 @@ 
 #include <sys/file.h>
 #include <unistd.h>
 
+#define THREAD_POOL_SIZE 64
 
 #define OFFSET_MAX 0x7fffffffffffffffLL
 
@@ -2523,6 +2524,7 @@  static const struct fuse_opt fuse_ll_opts[] = {
     LL_OPTION("--socket-path=%s", vu_socket_path, 0),
     LL_OPTION("vhost_user_socket=%s", vu_socket_path, 0),
     LL_OPTION("--fd=%d", vu_listen_fd, 0),
+    LL_OPTION("--thread-pool-size=%d", thread_pool_size, 0),
     FUSE_OPT_END
 };
 
@@ -2544,7 +2546,9 @@  void fuse_lowlevel_help(void)
         "    --socket-path=PATH         path for the vhost-user socket\n"
         "    -o vhost_user_socket=PATH  path for the vhost-user socket\n"
         "    --fd=FDNUM                 fd number of vhost-user socket\n"
-        "    -o auto_unmount            auto unmount on process termination\n");
+        "    -o auto_unmount            auto unmount on process termination\n"
+        "    --thread-pool-size=NUM     thread pool size limit (default %d)\n",
+        THREAD_POOL_SIZE);
 }
 
 void fuse_session_destroy(struct fuse_session *se)
@@ -2598,6 +2602,7 @@  struct fuse_session *fuse_session_new(struct fuse_args *args,
     }
     se->fd = -1;
     se->vu_listen_fd = -1;
+    se->thread_pool_size = THREAD_POOL_SIZE;
     se->conn.max_write = UINT_MAX;
     se->conn.max_readahead = UINT_MAX;
 
diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c
index b696ac3135..7bc6ff2f19 100644
--- a/tools/virtiofsd/fuse_virtio.c
+++ b/tools/virtiofsd/fuse_virtio.c
@@ -570,10 +570,11 @@  static void *fv_queue_thread(void *opaque)
     struct fv_QueueInfo *qi = opaque;
     struct VuDev *dev = &qi->virtio_dev->dev;
     struct VuVirtq *q = vu_get_queue(dev, qi->qidx);
+    struct fuse_session *se = qi->virtio_dev->se;
     GThreadPool *pool;
 
-    pool = g_thread_pool_new(fv_queue_worker, qi, 1 /* TODO max_threads */,
-                             TRUE, NULL);
+    pool = g_thread_pool_new(fv_queue_worker, qi, se->thread_pool_size, TRUE,
+                             NULL);
     if (!pool) {
         fuse_log(FUSE_LOG_ERR, "%s: g_thread_pool_new failed\n", __func__);
         return NULL;