Skip to contentSkip to conversation

fuse: per-queue background request accounting for io-uring

RFC PATCH In review Aleksander Trofimowicz 2 participants 3 messages Oct 16

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover fuse: per-queue background request accounting for io-uring

fuse: per-queue background request accounting for io-uring

This RFC proposes an opt-in path to replace the connection-wide background request accounting in fuse io-uring with per-queue budgeting.

AFAIR the concept has already floated on the list, but nothing has come to fruition. Nonetheless the problem is obvious: the existing implementation relies on a single connection-wide spinlock (fch->bg_lock) that is taken twice while servicing background requests. That severely hampers the scalability of fuse io-uring for certain types of workload (e.g. direct async I/O). Suffice it to say, with this patch applied I can easily cross the 1M 4k random read IOPS barrier, while the baseline gives a mere 600k IOPS (caeteris paribus).

I envision this enhancement being negotiated with a daemon, but for your convenience the feature can currently be activated unconditionally via the uring_max_bg_per_queue_force parameter. Mind that the value of uring_max_bg_per_queue must also be increased to obtain any meaningful results.

I am looking forward to your feedback. Thanks in advance.

Aleksander Trofimowicz (1):
fuse: per-queue background request accounting for io-uring

 fs/fuse/control.c         |   5 +-
 fs/fuse/dev.c             |  93 ++++++++++++++++---
 fs/fuse/dev.h             |  22 ++++-
 fs/fuse/dev_uring.c       | 187 ++++++++++++++++++++++++++++++++++----
 fs/fuse/dev_uring_i.h     |  32 +++++++
 fs/fuse/fuse_dev_i.h      |  18 ++++
 fs/fuse/inode.c           |  13 ++-
 include/uapi/linux/fuse.h |  11 ++-
 8 files changed, 347 insertions(+), 34 deletions(-)

base-commit: 2f2f7eeef8b0a1a9b9ca998231419873ccae8d4e --
2.56.0

#1 lore raw

RFC PATCH 1/1 fuse: per-queue background request accounting for io-uring

On many-core systems the connection-wide background request accounting is the dominant scaling bottleneck for fuse io-uring. This change addresses the problem by the means of per-queue background request limiters.

---
 fs/fuse/control.c         |   5 +-
 fs/fuse/dev.c             |  93 ++++++++++++++++---
 fs/fuse/dev.h             |  22 ++++-
 fs/fuse/dev_uring.c       | 187 ++++++++++++++++++++++++++++++++++----
 fs/fuse/dev_uring_i.h     |  32 +++++++
 fs/fuse/fuse_dev_i.h      |  18 ++++
 fs/fuse/inode.c           |  13 ++-
 include/uapi/linux/fuse.h |  11 ++-
 8 files changed, 347 insertions(+), 34 deletions(-)
fs/fuse/control.c +4 -1
index 21ffde596d61..611a9e93da5f 100644
@@ -126,8 +126,11 @@ static ssize_t fuse_conn_max_background_write(struct file *file,
 	if (ret > 0) {
 		struct fuse_conn *fc = fuse_ctl_file_conn_get(file);
 		if (fc) {
-			fuse_chan_max_background_set(fc->chan, val);
+			int err = fuse_chan_max_background_set(fc->chan, val);
+
 			fuse_conn_put(fc);
+			if (err)
+				ret = err;
 		}
 	}
 
fs/fuse/dev.c +82 -11

147 lines not on this page · raw message

fs/fuse/dev.h +21 -1
index 8d25378c0918..e2730105ff13 100644
@@ -4,10 +4,14 @@
 #define _FS_FUSE_DEV_H
 
 #include <linux/cleanup.h>
+#include <linux/types.h>
 
 /** Maximum number of outstanding background requests */
 #define FUSE_DEFAULT_MAX_BACKGROUND 12
 
+/** Maximum number of outstanding background requests per io-uring queue */
+#define FUSE_URING_MAX_BG_PER_QUEUE 4096
+
 struct fuse_conn;
 struct fuse_chan;
 struct fuse_dev;
@@ -31,7 +35,8 @@ void fuse_chan_release(struct fuse_chan *fch);
 void fuse_chan_free(struct fuse_chan *fch);
 unsigned int fuse_chan_num_background(struct fuse_chan *fch);
 unsigned int fuse_chan_max_background(struct fuse_chan *fch);
-void fuse_chan_max_background_set(struct fuse_chan *fch, unsigned int val);
+int fuse_chan_max_background_set(struct fuse_chan *fch, unsigned int val);
+void fuse_chan_per_queue_bg_enable(struct fuse_chan *fch, unsigned int max_bg);
 unsigned int fuse_chan_num_waiting(struct fuse_chan *fch);
 void fuse_chan_set_fc(struct fuse_chan *fch, struct fuse_conn *fc);
 void fuse_chan_set_initialized(struct fuse_chan *fch, struct fuse_chan_param *param);
@@ -95,6 +100,9 @@ void fuse_copy_finish(struct fuse_copy_state *cs);
 
 #ifdef CONFIG_FUSE_IO_URING
 bool fuse_uring_enabled(void);
+bool fuse_uring_per_queue_bg_advertise(void);
+unsigned int fuse_uring_per_queue_bg_budget(u64 flags, u16 daemon_max_bg,
+					    unsigned int user_bg_limit);
 void fuse_uring_destruct(struct fuse_chan *fch);
 #else /* CONFIG_FUSE_IO_URING */
 static inline bool fuse_uring_enabled(void)
@@ -102,6 +110,18 @@ static inline bool fuse_uring_enabled(void)
 	return false;
 }
 
+static inline bool fuse_uring_per_queue_bg_advertise(void)
+{
+	return false;
+}
+
+static inline unsigned int
+fuse_uring_per_queue_bg_budget(u64 flags, u16 daemon_max_bg,
+			       unsigned int user_bg_limit)
+{
+	return 0;
+}
+
 static inline void fuse_uring_destruct(struct fuse_chan *fch)
 {
 }
fs/fuse/dev_uring.c +169 -18

264 lines not on this page · raw message

fs/fuse/dev_uring_i.h +32 -0
index 263d0f8b9714..5f066ea9735a 100644
@@ -139,6 +139,11 @@ struct fuse_ring_queue {
 
 	unsigned int active_background;
 
+	/* Per-queue background budget and accounting (FUSE_BG_MODE_PER_QUEUE) */
+	unsigned int max_bg;
+	unsigned int bg_local;
+	wait_queue_head_t bg_waitq;
+
 	bool stopped;
 
 	/* how this queue's payload buffers are provided */
@@ -192,6 +197,9 @@ void fuse_uring_queue_fuse_req(struct fuse_iqueue *fiq, struct fuse_req *req);
 bool fuse_uring_queue_bq_req(struct fuse_req *req);
 bool fuse_uring_remove_pending_req(struct fuse_req *req);
 bool fuse_uring_request_expired(struct fuse_chan *fch);
+struct fuse_ring_queue *fuse_uring_bg_admit(struct fuse_chan *fch);
+void fuse_uring_bg_req_release(struct fuse_ring_queue *queue);
+unsigned int fuse_uring_num_background(struct fuse_chan *fch);
 
 static inline void fuse_uring_abort(struct fuse_chan *fch)
 {
@@ -222,6 +230,11 @@ static inline bool fuse_uring_ready(struct fuse_chan *fch)
 	return ring && smp_load_acquire(&ring->ready);
 }
 
+static inline bool fuse_uring_per_queue_bg(struct fuse_chan *fch)
+{
+	return fch->bg_mode == FUSE_BG_MODE_PER_QUEUE && fuse_uring_ready(fch);
+}
+
 #else /* CONFIG_FUSE_IO_URING */
 
 static inline void fuse_uring_conn_init(struct fuse_chan *fch)
@@ -251,6 +264,25 @@ static inline bool fuse_uring_request_expired(struct fuse_chan *fch)
 	return false;
 }
 
+static inline bool fuse_uring_per_queue_bg(struct fuse_chan *fch)
+{
+	return false;
+}
+
+static inline struct fuse_ring_queue *fuse_uring_bg_admit(struct fuse_chan *fch)
+{
+	return NULL;
+}
+
+static inline void fuse_uring_bg_req_release(void *queue)
+{
+}
+
+static inline unsigned int fuse_uring_num_background(struct fuse_chan *fch)
+{
+	return 0;
+}
+
 #endif /* CONFIG_FUSE_IO_URING */
 
 #endif /* _FS_FUSE_DEV_URING_I_H */
fs/fuse/fuse_dev_i.h +18 -0
index 4b412a76225f..4ca724994af9 100644
@@ -17,6 +17,18 @@
 #define FUSE_INT_REQ_BIT (1ULL << 0)
 #define FUSE_REQ_ID_STEP (1ULL << 1)
 
+/**
+ * Background request accounting mode
+ *
+ * @FUSE_BG_MODE_GLOBAL: legacy accounting, a single global spinlock
+ *	protects the background accounting of all queues
+ * @FUSE_BG_MODE_PER_QUEUE: each fuse_ring_queue owns its own budget.
+ */
+enum fuse_bg_mode {
+	FUSE_BG_MODE_GLOBAL,
+	FUSE_BG_MODE_PER_QUEUE,
+};
+
 struct fuse_arg;
 struct fuse_args;
 struct fuse_pqueue;
@@ -223,6 +235,12 @@ struct fuse_chan {
 	/** Protects: max_background, num_background, active_background, bg_queue, blocked */
 	spinlock_t bg_lock;
 
+	/** Background accounting mode, set at INIT, read-only afterwards */
+	enum fuse_bg_mode bg_mode;
+
+	/** Per-queue background budget (FUSE_BG_MODE_PER_QUEUE only) */
+	unsigned int uring_max_bg_per_queue;
+
 	/** Flag indicating that INIT reply has been received. Allocating
 	 * any fuse request will be suspended until the flag is set */
 	int initialized;
fs/fuse/inode.c +12 -1
index e9552be3637b..a899ef069e0c 100644
@@ -1276,6 +1276,7 @@ static void process_init_reply(struct fuse_args *args, int error)
 	struct fuse_conn *fc = fm->fc;
 	struct fuse_init_out *arg = &ia->out;
 	bool io_uring_enabled = false;
+	unsigned int max_bg = 0;
 	bool ok = true;
 
 	if (error || arg->major != FUSE_KERNEL_VERSION)
@@ -1408,6 +1409,10 @@ static void process_init_reply(struct fuse_args *args, int error)
 			if (flags & FUSE_OVER_IO_URING && fuse_uring_enabled())
 				io_uring_enabled = true;
 
+			max_bg = fuse_uring_per_queue_bg_budget(flags,
+								arg->max_bg_per_queue,
+								max_user_bgreq);
+
 			if (flags & FUSE_REQUEST_TIMEOUT)
 				timeout = arg->request_timeout;
 		} else {
@@ -1418,6 +1423,9 @@ static void process_init_reply(struct fuse_args *args, int error)
 
 		fuse_init_server_timeout(fc->chan, timeout);
 
+		if (max_bg)
+			fuse_chan_per_queue_bg_enable(fc->chan, max_bg);
+
 		fm->sb->s_bdi->ra_pages =
 				min(fm->sb->s_bdi->ra_pages, ra_pages);
 		fm->sb->s_bdi->io_pages = fc->max_pages;
@@ -1480,8 +1488,11 @@ static struct fuse_init_args *fuse_new_init(struct fuse_mount *fm)
 	if (IS_ENABLED(CONFIG_FUSE_PASSTHROUGH))
 		flags |= FUSE_PASSTHROUGH;
 
-	if (fuse_uring_enabled())
+	if (fuse_uring_enabled()) {
 		flags |= FUSE_OVER_IO_URING | FUSE_HAS_IO_URING_BUFPOOL;
+		if (fuse_uring_per_queue_bg_advertise())
+			flags |= FUSE_PER_QUEUE_BG;
+	}
 
 	ia->in.flags = flags;
 	ia->in.flags2 = flags >> 32;
include/uapi/linux/fuse.h +9 -2
index 7435e09c87fe..847c93a8c746 100644
@@ -248,6 +248,9 @@
  *  - add bufpool offset field to fuse_uring_ent_in_out struct
  *  - add FUSE_URING_ZERO_COPY, FUSE_URING_ENT_ZERO_COPY, and
  *    FOPEN_IO_URING_ZERO_COPY flag
+ *
+ *  7.47
+ *  - add FUSE_PER_QUEUE_BG
  */
 
 #ifndef _LINUX_FUSE_H
@@ -283,7 +286,7 @@
 #define FUSE_KERNEL_VERSION 7
 
 /** Minor version number of this interface */
-#define FUSE_KERNEL_MINOR_VERSION 46
+#define FUSE_KERNEL_MINOR_VERSION 47
 
 /** The node ID of the root inode */
 #define FUSE_ROOT_ID 1
@@ -464,6 +467,8 @@ struct fuse_file_lock {
  * FUSE_REQUEST_TIMEOUT: kernel supports timing out requests.
  *			 init_out.request_timeout contains the timeout (in secs)
  * FUSE_HAS_IO_URING_BUFPOOL: kernel supports io-uring buffer pools
+ * FUSE_PER_QUEUE_BG: kernel supports per-queue background request accounting
+ *                    for io-uring.
  */
 #define FUSE_ASYNC_READ		(1 << 0)
 #define FUSE_POSIX_LOCKS	(1 << 1)
@@ -512,6 +517,7 @@ struct fuse_file_lock {
 #define FUSE_OVER_IO_URING	(1ULL << 41)
 #define FUSE_REQUEST_TIMEOUT	(1ULL << 42)
 #define FUSE_HAS_IO_URING_BUFPOOL (1ULL << 43)
+#define FUSE_PER_QUEUE_BG	(1ULL << 44)
 
 /**
  * CUSE INIT request/reply flags
@@ -942,7 +948,8 @@ struct fuse_init_out {
 	uint32_t	flags2;
 	uint32_t	max_stack_depth;
 	uint16_t	request_timeout;
-	uint16_t	unused[11];
+	uint16_t	max_bg_per_queue;
+	uint16_t	unused[10];
 };
 
 #define CUSE_INIT_INFO_MAX 4096
Signature · 1 line
2.56.0
maintainer
#2 lore raw
In reply to Aleksander Trofimowicz

Hi Alexsander,

Quoted 15 lines · Aleksander Trofimowicz

fuse: per-queue background request accounting for io-uring

This RFC proposes an opt-in path to replace the connection-wide background request accounting in fuse io-uring with per-queue budgeting.

AFAIR the concept has already floated on the list, but nothing has come to fruition. Nonetheless the problem is obvious: the existing implementation relies on a single connection-wide spinlock (fch->bg_lock) that is taken twice while servicing background requests. That severely hampers the scalability of fuse io-uring for certain types of workload (e.g. direct async I/O). Suffice it to say, with this patch applied I can easily cross the 1M 4k random read IOPS barrier, while the baseline gives a mere 600k IOPS (caeteris paribus).

Quoted 7 lines

I envision this enhancement being negotiated with a daemon, but for your convenience the feature can currently be activated unconditionally via the uring_max_bg_per_queue_force parameter. Mind that the value of uring_max_bg_per_queue must also be increased to obtain any meaningful results.

I am looking forward to your feedback. Thanks in advance.

I wasn't doing this yet, because I see it dependent on the reduced queue feature, which also allows to distribute requests to another queue, when a queue already got too many requests. I.e. if a queue is over its own bg-limit, it should check if other queues are available.

I plan to send out next version of reduced queues over the weekend.

Thanks,
Bernd