Skip to contentSkip to conversation

fuse: optimize over-io-uring request expiration check

PATCH Superseded Joanne Koong 2 participants 7 messages Jan 23, 2025 – Jan 24, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Joanne Koong

author maintainer
#0 lore raw

PATCH 1/1 fuse: optimize over-io-uring request expiration check

Currently, when checking whether a request has timed out, we check fpq processing, but fuse-over-io-uring has one fpq per core and 256 entries in the processing table. For systems where there are a large number of cores, this may be too much overhead.

Instead of checking the fpq processing list, check ent_w_req_queue, ent_in_userspace, and ent_commit_queue.

---
 fs/fuse/dev.c        |  2 +-
 fs/fuse/dev_uring.c  | 23 ++++++++++++++++++++---
 fs/fuse/fuse_dev_i.h |  1 -
 3 files changed, 21 insertions(+), 5 deletions(-)
fs/fuse/dev.c +1 -1
index 3c03aac480a4..80a11ef4b69a 100644
@@ -45,7 +45,7 @@ bool fuse_request_expired(struct fuse_conn *fc, struct list_head *list)
 	return time_is_before_jiffies(req->create_time + fc->timeout.req_timeout);
 }
 
-bool fuse_fpq_processing_expired(struct fuse_conn *fc, struct list_head *processing)
+static bool fuse_fpq_processing_expired(struct fuse_conn *fc, struct list_head *processing)
 {
 	int i;
 
fs/fuse/dev_uring.c +20 -3
index 5c9b5a5fb7f7..dfa6c5337bbf 100644
@@ -90,6 +90,7 @@ static void fuse_uring_req_end(struct fuse_ring_ent *ent, int error)
 		fuse_uring_flush_bg(queue);
 		spin_unlock(&fc->bg_lock);
 	}
+	ent->fuse_req = NULL;
 
 	spin_unlock(&queue->lock);
 
@@ -97,8 +98,7 @@ static void fuse_uring_req_end(struct fuse_ring_ent *ent, int error)
 		req->out.h.error = error;
 
 	clear_bit(FR_SENT, &req->flags);
-	fuse_request_end(ent->fuse_req);
-	ent->fuse_req = NULL;
+	fuse_request_end(req);
 }
 
 /* Abort all list queued request on the given ring queue */
@@ -140,6 +140,21 @@ void fuse_uring_abort_end_requests(struct fuse_ring *ring)
 	}
 }
 
+static bool ent_list_request_expired(struct fuse_conn *fc, struct list_head *list)
+{
+	struct fuse_ring_ent *ent;
+	struct fuse_req *req;
+
+	list_for_each_entry(ent, list, list) {
+		req = ent->fuse_req;
+		if (req)
+			return time_is_before_jiffies(req->create_time +
+						      fc->timeout.req_timeout);
+	}
+
+	return false;
+}
+
 bool fuse_uring_request_expired(struct fuse_conn *fc)
 {
 	struct fuse_ring *ring = fc->ring;
@@ -157,7 +172,9 @@ bool fuse_uring_request_expired(struct fuse_conn *fc)
 		spin_lock(&queue->lock);
 		if (fuse_request_expired(fc, &queue->fuse_req_queue) ||
 		    fuse_request_expired(fc, &queue->fuse_req_bg_queue) ||
-		    fuse_fpq_processing_expired(fc, queue->fpq.processing)) {
+		    ent_list_request_expired(fc, &queue->ent_w_req_queue) ||
+		    ent_list_request_expired(fc, &queue->ent_in_userspace) ||
+		    ent_list_request_expired(fc, &queue->ent_commit_queue)) {
 			spin_unlock(&queue->lock);
 			return true;
 		}
fs/fuse/fuse_dev_i.h +0 -1
index 3c4ae4d52b6f..19c29c6000a7 100644
@@ -63,7 +63,6 @@ void fuse_dev_queue_forget(struct fuse_iqueue *fiq,
 void fuse_dev_queue_interrupt(struct fuse_iqueue *fiq, struct fuse_req *req);
 
 bool fuse_request_expired(struct fuse_conn *fc, struct list_head *list);
-bool fuse_fpq_processing_expired(struct fuse_conn *fc, struct list_head *processing);
 
 #endif
 
Signature · 1 line
2.43.5
#1 lore raw
Quoted 41 lines · Joanne Koong

Currently, when checking whether a request has timed out, we check fpq processing, but fuse-over-io-uring has one fpq per core and 256 entries in the processing table. For systems where there are a large number of cores, this may be too much overhead.

Instead of checking the fpq processing list, check ent_w_req_queue, ent_in_userspace, and ent_commit_queue.

---
 fs/fuse/dev.c        |  2 +-
 fs/fuse/dev_uring.c  | 23 ++++++++++++++++++++---
 fs/fuse/fuse_dev_i.h |  1 -
 3 files changed, 21 insertions(+), 5 deletions(-)
fs/fuse/dev.c +1 -1
index 3c03aac480a4..80a11ef4b69a 100644
@@ -45,7 +45,7 @@ bool fuse_request_expired(struct fuse_conn *fc, struct list_head *list)
 	return time_is_before_jiffies(req->create_time + fc->timeout.req_timeout);
 }
 
-bool fuse_fpq_processing_expired(struct fuse_conn *fc, struct list_head *processing)
+static bool fuse_fpq_processing_expired(struct fuse_conn *fc, struct list_head *processing)
 {
 	int i;
 
fs/fuse/dev_uring.c +1 -0
index 5c9b5a5fb7f7..dfa6c5337bbf 100644
@@ -90,6 +90,7 @@ static void fuse_uring_req_end(struct fuse_ring_ent *ent, int error)
 		fuse_uring_flush_bg(queue);
 		spin_unlock(&fc->bg_lock);
 	}
+	ent->fuse_req = NULL;
 
 	spin_unlock(&queue->lock);
 

fs/fuse/dev_uring.c static void fuse_uring_req_end(struct fuse_ring_ent *ent, int error) · line 103

Quoted 8 lines
fs/fuse/dev_uring.c +1 -2
@@ -97,8 +98,7 @@ static void fuse_uring_req_end(struct fuse_ring_ent *ent, int error)
 		req->out.h.error = error;
 
 	clear_bit(FR_SENT, &req->flags);
-	fuse_request_end(ent->fuse_req);
-	ent->fuse_req = NULL;
+	fuse_request_end(req);
 }
 

Oh, this is actually a fix, it should be always set with the lock being held.

Quoted 9 lines
fs/fuse/dev_uring.c +4 -0
 /* Abort all list queued request on the given ring queue */
@@ -140,6 +140,21 @@ void fuse_uring_abort_end_requests(struct fuse_ring *ring)
 	}
 }
 
+static bool ent_list_request_expired(struct fuse_conn *fc, struct list_head *list)
+{
+	struct fuse_ring_ent *ent;
+	struct fuse_req *req;

fs/fuse/dev_uring.c void fuse_uring_abort_end_requests(struct fuse_ring *ring) · line 156

Quoted 10 lines
fs/fuse/dev_uring.c +10 -0
+
+	list_for_each_entry(ent, list, list) {
+		req = ent->fuse_req;
+		if (req)
+			return time_is_before_jiffies(req->create_time +
+						      fc->timeout.req_timeout);
+	}
+
+	return false;
+}

Hmm, would only need to check head? Oh I see it, we need to use list_move_tail().

Quoted 27 lines
fs/fuse/dev_uring.c +4 -1
+
 bool fuse_uring_request_expired(struct fuse_conn *fc)
 {
 	struct fuse_ring *ring = fc->ring;
@@ -157,7 +172,9 @@ bool fuse_uring_request_expired(struct fuse_conn *fc)
 		spin_lock(&queue->lock);
 		if (fuse_request_expired(fc, &queue->fuse_req_queue) ||
 		    fuse_request_expired(fc, &queue->fuse_req_bg_queue) ||
-		    fuse_fpq_processing_expired(fc, queue->fpq.processing)) {
+		    ent_list_request_expired(fc, &queue->ent_w_req_queue) ||
+		    ent_list_request_expired(fc, &queue->ent_in_userspace) ||
+		    ent_list_request_expired(fc, &queue->ent_commit_queue)) {
 			spin_unlock(&queue->lock);
 			return true;
 		}
fs/fuse/fuse_dev_i.h +0 -1
index 3c4ae4d52b6f..19c29c6000a7 100644
@@ -63,7 +63,6 @@ void fuse_dev_queue_forget(struct fuse_iqueue *fiq,
 void fuse_dev_queue_interrupt(struct fuse_iqueue *fiq, struct fuse_req *req);
 
 bool fuse_request_expired(struct fuse_conn *fc, struct list_head *list);
-bool fuse_fpq_processing_expired(struct fuse_conn *fc, struct list_head *processing);
 
 #endif
 
#2 lore raw

Hi Joanne,

Quoted 2 lines · Bernd Schubert

Hmm, would only need to check head? Oh I see it, we need to use list_move_tail().

how about the attached updated patch, which uses list_first_entry_or_null()? It also changes from list_move() to list_move_tail() so that oldest entry is always on top. I didn't give it any testing, though.

This is on top of the other fuse-uring updates I had sent out about an hour ago.

Here is the corresponding branch
https://github.com/bsbernd/linux/tree/optimize-fuse-uring-req-timeouts

Thanks,
Bernd

fuse: optimize over-io-uring request expiration check

From: Joanne Koong <[email protected]>

Currently, when checking whether a request has timed out, we check fpq processing, but fuse-over-io-uring has one fpq per core and 256 entries in the processing table. For systems where there are a large number of cores, this may be too much overhead.

Instead of checking the fpq processing list, check ent_w_req_queue, ent_in_userspace, and ent_commit_queue.

---
 fs/fuse/dev.c        |    2 +-
 fs/fuse/dev_uring.c  |   31 +++++++++++++++++++++++++------
 fs/fuse/fuse_dev_i.h |    1 -
 3 files changed, 26 insertions(+), 8 deletions(-)
fs/fuse/dev.c +1 -1
index 3c03aac480a4..80a11ef4b69a 100644
@@ -45,7 +45,7 @@ bool fuse_request_expired(struct fuse_conn *fc, struct list_head *list)
 	return time_is_before_jiffies(req->create_time + fc->timeout.req_timeout);
 }
 
-bool fuse_fpq_processing_expired(struct fuse_conn *fc, struct list_head *processing)
+static bool fuse_fpq_processing_expired(struct fuse_conn *fc, struct list_head *processing)
 {
 	int i;
 
fs/fuse/dev_uring.c +25 -6
index c4453352a0c1..ecaeffbc2698 100644
@@ -140,6 +140,23 @@ void fuse_uring_abort_end_requests(struct fuse_ring *ring)
 	}
 }
 
+static bool ent_list_request_expired(struct fuse_conn *fc, struct list_head *list)
+{
+	struct fuse_ring_ent *ent;
+	struct fuse_req *req;
+
+	ent = list_first_entry_or_null(list, struct fuse_ring_ent, list);
+	if (!ent)
+		return false;
+
+	req = ent->fuse_req;
+	if (WARN_ON_ONCE(!req))
+		return false;
+
+	return time_is_before_jiffies(req->create_time +
+				      fc->timeout.req_timeout);
+}
+
 bool fuse_uring_request_expired(struct fuse_conn *fc)
 {
 	struct fuse_ring *ring = fc->ring;
@@ -157,7 +174,9 @@ bool fuse_uring_request_expired(struct fuse_conn *fc)
 		spin_lock(&queue->lock);
 		if (fuse_request_expired(fc, &queue->fuse_req_queue) ||
 		    fuse_request_expired(fc, &queue->fuse_req_bg_queue) ||
-		    fuse_fpq_processing_expired(fc, queue->fpq.processing)) {
+		    ent_list_request_expired(fc, &queue->ent_w_req_queue) ||
+		    ent_list_request_expired(fc, &queue->ent_in_userspace) ||
+		    ent_list_request_expired(fc, &queue->ent_commit_queue)) {
 			spin_unlock(&queue->lock);
 			return true;
 		}
@@ -496,7 +515,7 @@ static void fuse_uring_cancel(struct io_uring_cmd *cmd,
 	spin_lock(&queue->lock);
 	if (ent->state == FRRS_AVAILABLE) {
 		ent->state = FRRS_USERSPACE;
-		list_move(&ent->list, &queue->ent_in_userspace);
+		list_move_tail(&ent->list, &queue->ent_in_userspace);
 		need_cmd_done = true;
 		ent->cmd = NULL;
 	}
@@ -716,7 +735,7 @@ static int fuse_uring_send_next_to_ring(struct fuse_ring_ent *ent,
 	cmd = ent->cmd;
 	ent->cmd = NULL;
 	ent->state = FRRS_USERSPACE;
-	list_move(&ent->list, &queue->ent_in_userspace);
+	list_move_tail(&ent->list, &queue->ent_in_userspace);
 	spin_unlock(&queue->lock);
 
 	io_uring_cmd_done(cmd, 0, 0, issue_flags);
@@ -770,7 +789,7 @@ static void fuse_uring_add_req_to_ring_ent(struct fuse_ring_ent *ent,
 	spin_unlock(&fiq->lock);
 	ent->fuse_req = req;
 	ent->state = FRRS_FUSE_REQ;
-	list_move(&ent->list, &queue->ent_w_req_queue);
+	list_move_tail(&ent->list, &queue->ent_w_req_queue);
 	fuse_uring_add_to_pq(ent, req);
 }
 
@@ -855,7 +874,7 @@ static int fuse_ring_ent_set_commit(struct fuse_ring_ent *ent)
 		return -EIO;
 
 	ent->state = FRRS_COMMIT;
-	list_move(&ent->list, &queue->ent_commit_queue);
+	list_move_tail(&ent->list, &queue->ent_commit_queue);
 
 	return 0;
 }
@@ -1186,7 +1205,7 @@ static void fuse_uring_send(struct fuse_ring_ent *ent, struct io_uring_cmd *cmd,
 
 	spin_lock(&queue->lock);
 	ent->state = FRRS_USERSPACE;
-	list_move(&ent->list, &queue->ent_in_userspace);
+	list_move_tail(&ent->list, &queue->ent_in_userspace);
 	ent->cmd = NULL;
 	spin_unlock(&queue->lock);
 
fs/fuse/fuse_dev_i.h +0 -1
index 3c4ae4d52b6f..19c29c6000a7 100644
@@ -63,7 +63,6 @@ void fuse_dev_queue_forget(struct fuse_iqueue *fiq,
 void fuse_dev_queue_interrupt(struct fuse_iqueue *fiq, struct fuse_req *req);
 
 bool fuse_request_expired(struct fuse_conn *fc, struct list_head *list);
-bool fuse_fpq_processing_expired(struct fuse_conn *fc, struct list_head *processing);
 
 #endif
 
author maintainer
#3 lore raw
Quoted 4 lines · Bernd Schubert

Hi Joanne,

On 1/24/25 12:30, Bernd Schubert wrote:

Quoted 8 lines
Quoted 2 lines

Hmm, would only need to check head? Oh I see it, we need to use list_move_tail().

how about the attached updated patch, which uses list_first_entry_or_null()? It also changes from list_move() to list_move_tail() so that oldest entry is always on top. I didn't give it any testing, though.

Woah that's cool, I didn't know you could send attachments over the mailing list.
Ah I didn't realize list_move doesn't already by default add to the tail of the list - thanks for catching that, yes those should be list_move_tail() then.

In t he attached patch, I think we still need the original ent_list_request_expired() logic:

static bool ent_list_request_expired(struct fuse_conn *fc, struct list_head *list)

{
    struct fuse_ring_ent *ent;
    struct fuse_req *req;

    list_for_each_entry(ent, list, list) {
    req = ent->fuse_req;
    if (req)
        return time_is_before_jiffies(req->create_time +
                    fc->timeout.req_timeout);
    }

    return false;
}

and we can't assume req is non-NULL. For entries that have been committed, their ->req is set to NULL but they are still on the ent_commit_queue.

Thanks,
Joanne

Quoted 11 lines

This is on top of the other fuse-uring updates I had sent out about an hour ago.

Here is the corresponding branch
https://github.com/bsbernd/linux/tree/optimize-fuse-uring-req-timeouts

Thanks,
Bernd

#4 lore raw
Quoted 26 lines · Joanne Koong
Quoted 4 lines · Bernd Schubert

Hi Joanne,

On 1/24/25 12:30, Bernd Schubert wrote:

Quoted 8 lines
Quoted 2 lines

Hmm, would only need to check head? Oh I see it, we need to use list_move_tail().

how about the attached updated patch, which uses list_first_entry_or_null()? It also changes from list_move() to list_move_tail() so that oldest entry is always on top. I didn't give it any testing, though.

Woah that's cool, I didn't know you could send attachments over the mailing list.
Ah I didn't realize list_move doesn't already by default add to the tail of the list - thanks for catching that, yes those should be list_move_tail() then.

In t he attached patch, I think we still need the original ent_list_request_expired() logic:

static bool ent_list_request_expired(struct fuse_conn *fc, struct list_head *list)

Quoted 13 lines
{
    struct fuse_ring_ent *ent;
    struct fuse_req *req;

    list_for_each_entry(ent, list, list) {
    req = ent->fuse_req;
    if (req)
        return time_is_before_jiffies(req->create_time +
                    fc->timeout.req_timeout);
    }

    return false;
}

Could you explain why? That would be super expensive if lists have many entries? Due to fg and bg queues it might not be perfectly ordered, but that it actually also true for fuse_req_queue and also without io-uring. Server might process requests in different order, so ent_commit_queue might also not be perfectly sorted. But then I'm not even sure if we need to process that queue, as it has entries that are already processed - at best that would catch fuse client/kernel bugs.
Though, if there is some kind if req processing issue, either everything times out, or the head will eventually get the older requests. So I don't understand why would need to go over all entries.

Quoted 4 lines

and we can't assume req is non-NULL. For entries that have been committed, their ->req is set to NULL but they are still on the ent_commit_queue.

Yeah sorry, right, though I wonder if we can just avoid checking that queue.

Thanks,
Bernd

author maintainer
#5 lore raw
Quoted 44 lines · Bernd Schubert
Quoted 26 lines · Joanne Koong
Quoted 4 lines · Bernd Schubert

Hi Joanne,

On 1/24/25 12:30, Bernd Schubert wrote:

Quoted 8 lines
Quoted 2 lines

Hmm, would only need to check head? Oh I see it, we need to use list_move_tail().

how about the attached updated patch, which uses list_first_entry_or_null()? It also changes from list_move() to list_move_tail() so that oldest entry is always on top. I didn't give it any testing, though.

Woah that's cool, I didn't know you could send attachments over the mailing list.
Ah I didn't realize list_move doesn't already by default add to the tail of the list - thanks for catching that, yes those should be list_move_tail() then.

In t he attached patch, I think we still need the original ent_list_request_expired() logic:

static bool ent_list_request_expired(struct fuse_conn *fc, struct list_head *list)

Quoted 13 lines
{
    struct fuse_ring_ent *ent;
    struct fuse_req *req;

    list_for_each_entry(ent, list, list) {
    req = ent->fuse_req;
    if (req)
        return time_is_before_jiffies(req->create_time +
                    fc->timeout.req_timeout);
    }

    return false;
}
Quoted 12 lines

Could you explain why? That would be super expensive if lists have many entries? Due to fg and bg queues it might not be perfectly ordered, but that it actually also true for fuse_req_queue and also without io-uring. Server might process requests in different order, so ent_commit_queue might also not be perfectly sorted. But then I'm not even sure if we need to process that queue, as it has entries that are already processed - at best that would catch fuse client/kernel bugs.
Though, if there is some kind if req processing issue, either everything times out, or the head will eventually get the older requests. So I don't understand why would need to go over all entries.

I don't think this in most cases goes over all entries. For ent_w_req_queue and ent_in_userspace queues, I think this is equivalent to just checking the head of the list since every entry on it will have a non-NULL request attached. But I think we need this "list_for_each_entry() { ... if (req) ... }" logic in order to properly handle the ent_commit_queue cases where an entry is on that queue but has a NULL request (eg the condition where fuse_uring_commit() has finished being called on the entry but a new request hasn't yet been attached to that entry).

I think another option is if we move the fuse_uring_ent_avail() call from fuse_uring_next_fuse_req() to be in fuse_uring_req_end() within the scope of the queue->lock instead, then that ensures all entries on the committed queue have valid requests.

Quoted 2 lines
Quoted 2 lines

and we can't assume req is non-NULL. For entries that have been

sorry, this should have been "because we can't assume req is non-NULL", not "and".

Quoted 6 lines
Quoted 2 lines

committed, their ->req is set to NULL but they are still on the ent_commit_queue.

Yeah sorry, right, though I wonder if we can just avoid checking that queue.

I like the idea of skipping the ent_commit_queue! We pretty much know the request is being responded to right now if it's being committed, so even if it has technically timed out, we can skip aborting it. Timeouts are kind of fuzzy right now anyways given the FUSE_TIMEOUT_TIMER_FREQ periodic check, so I don't see why this would be a problem.

Thanks,
Joanne

Quoted 3 lines

Thanks,
Bernd

author maintainer
#6 lore raw
Quoted 13 lines · Joanne Koong
Quoted 10 lines · Bernd Schubert
Quoted 6 lines · Joanne Koong
Quoted 4 lines · Bernd Schubert

Hi Joanne,

On 1/24/25 12:30, Bernd Schubert wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

Hmm, would only need to check head? Oh I see it, we need to use list_move_tail().

how about the attached updated patch, which uses list_first_entry_or_null()? It also changes from list_move() to list_move_tail() so that oldest entry is always on top. I didn't give it any testing, though.

I think this attached patch looks good, except with the "ent_list_request_expired(fc, &queue->ent_commit_queue))" line in it removed.

Thanks,
Joanne

Quoted 81 lines
Quoted 26 lines
Quoted 12 lines

Woah that's cool, I didn't know you could send attachments over the mailing list.
Ah I didn't realize list_move doesn't already by default add to the tail of the list - thanks for catching that, yes those should be list_move_tail() then.

In t he attached patch, I think we still need the original ent_list_request_expired() logic:

static bool ent_list_request_expired(struct fuse_conn *fc, struct list_head *list)

Quoted 13 lines
{
    struct fuse_ring_ent *ent;
    struct fuse_req *req;

    list_for_each_entry(ent, list, list) {
    req = ent->fuse_req;
    if (req)
        return time_is_before_jiffies(req->create_time +
                    fc->timeout.req_timeout);
    }

    return false;
}
Quoted 12 lines

Could you explain why? That would be super expensive if lists have many entries? Due to fg and bg queues it might not be perfectly ordered, but that it actually also true for fuse_req_queue and also without io-uring. Server might process requests in different order, so ent_commit_queue might also not be perfectly sorted. But then I'm not even sure if we need to process that queue, as it has entries that are already processed - at best that would catch fuse client/kernel bugs.
Though, if there is some kind if req processing issue, either everything times out, or the head will eventually get the older requests. So I don't understand why would need to go over all entries.

I don't think this in most cases goes over all entries. For ent_w_req_queue and ent_in_userspace queues, I think this is equivalent to just checking the head of the list since every entry on it will have a non-NULL request attached. But I think we need this "list_for_each_entry() { ... if (req) ... }" logic in order to properly handle the ent_commit_queue cases where an entry is on that queue but has a NULL request (eg the condition where fuse_uring_commit() has finished being called on the entry but a new request hasn't yet been attached to that entry).

I think another option is if we move the fuse_uring_ent_avail() call from fuse_uring_next_fuse_req() to be in fuse_uring_req_end() within the scope of the queue->lock instead, then that ensures all entries on the committed queue have valid requests.

Quoted 2 lines
Quoted 2 lines

and we can't assume req is non-NULL. For entries that have been

sorry, this should have been "because we can't assume req is non-NULL", not "and".

Quoted 6 lines
Quoted 2 lines

committed, their ->req is set to NULL but they are still on the ent_commit_queue.

Yeah sorry, right, though I wonder if we can just avoid checking that queue.

I like the idea of skipping the ent_commit_queue! We pretty much know the request is being responded to right now if it's being committed, so even if it has technically timed out, we can skip aborting it. Timeouts are kind of fuzzy right now anyways given the FUSE_TIMEOUT_TIMER_FREQ periodic check, so I don't see why this would be a problem.

Thanks,
Joanne

Quoted 3 lines

Thanks,
Bernd