Repository navigation
fuse: alternate contested io-uring slots between foreground and bg - #282
Conversation
yongzech
left a comment
There was a problem hiding this comment.
Main concern: the fairness guarantees in the commit message ("within two non-critical completions", "no slot stays free") don't fully hold. See the inline comments.
One finding is on a line outside the diff:
fs/fuse/dev_uring.c:401 fuse_uring_flush_bg() (stop path): it sets queue->stopped and calls only fuse_uring_flush_queue_bg(). On connection stop, max_background becomes UINT_MAX and every bg request floods past max_noncritical, while fg requests waiting on fuse_req_fg_queue stay there until abort. Calling fuse_uring_flush_queue() here would admit both.
|
This is a nice workaround for a workaround, but I don't have a better idea at the moment ;-) |
If upstream designed to support write-back cache for multiple client nodes, then this (fuse io-uring) was a day-1 design issue:-) As Bernd mentioned in the Slack, his initial design contained "such design" as we did in redfs kernel now, but dropped it to simplify it (I guess at that time the upstream didn't support the write-back cache, so no such design would not hit any problem) :) |
769d1f2 to
d6c406a
Compare
@yongzech Done. The stop path now calls |
yongzech
left a comment
There was a problem hiding this comment.
Follow-up review of the new head d6c406a375e8, after the force-push.
Earlier findings:
| # | Finding | Status |
|---|---|---|
| 1 | end_active runs before fuse_request_end returns the bg budget | Partly fixed: released handles a single completion; see inline at 312 |
| 2 | bq_req used flush_queue_bg | Fixed |
| 3 | fuse_request_end doesn't re-flush uring queues | Still present; see below |
| 4 | Stop path didn't admit fg | Fixed as written, but it doesn't drain; see inline at 210 |
| 5 | Turn didn't track uncontested grants | No longer applicable |
| 6 | register holds bg_lock longer | Declined; agreed the cost is small |
| 7 | max_noncritical recomputed per iteration | Declined; see inline at 179 for a way to fold it |
| 8 | Three admission helpers | Fixed |
On #3, which is outside the diff: fs/fuse/dev_uring.c:1979, fg arrival through fuse_uring_flush_queue_fg(). I agree nothing waits forever, because a held bg request implies an active bg request on that queue. But budget freed by fuse_request_end() on another queue (dev.c:496 flushes only the legacy list) does not re-flush this queue. Example: queue B has a free non-critical slot and a bg write held only by the global budget. A bg request on queue A ends. Every fg arrival on B then takes the free slot through flush_queue_fg, with no turn flip, until B's own bg request completes. That delays writeback and fsync on B. Returning the budget at end_active (inline at 123) fixes this too.
The PR description is also out of date after the force-push. It still says "no slot stays free while a request that could use it waits" and "The arrival paths keep admitting only their own kind". Neither holds for the new commit.
With the writeback cache, foreground requests and non-critical background requests share the non-critical entries of a ring queue, max_noncritical of them, 8 at the default depth of 10. When a request ended, fuse_uring_end_active() offered the freed slot first to the kind of request that freed it. Once background requests held every slot, each one that ended was replaced by the next one from the background list, and a foreground request on that queue was admitted only at a moment when the background list happened to be empty. The opposite holds too: a foreground load that keeps its list full holds back async writes the same way. Admit with one helper, fuse_uring_flush_queue(), wherever bg_lock is held: on background arrival, when a slot is freed while background requests wait, when an entry is registered, and when the queue stops. Critical background requests still go first. A free non-critical slot then goes to the only kind that can take it, or, when both kinds can, to the kind that did not get the previous contested slot, tracked by a per-queue noncrit_bg_turn. While a request of either kind can be admitted, it is thus admitted within two non-critical completions on its queue. A background request that the connection-wide max_background budget holds back cannot take a slot and does not contend. Without contention nothing changes: an async-only or a metadata-only load gets every slot as before. A background request that ended used to count in fc->active_background until fuse_request_end() ran, after its slot had been handed on. When the server commits several requests in one io_uring_enter(), fuse_request_end() runs for all of them later from task work, so their budget was still counted while their slots were handed on, and foreground took those slots without contending. When background requests wait on the queue, fuse_uring_end_active() now gives back the budget itself, under bg_lock and before it admits, and marks the request FR_URING_BG_RETURNED so that fuse_request_end() does not give it back again, and admission no longer counts requests that have already ended. Without waiting background requests the budget is still given back in fuse_request_end(), and the completion does not take bg_lock. Foreground arrival still admits only foreground requests, without bg_lock: a background request that waits while a slot is free is held by the background limits, so it could not take the slot. A completion with no background request waiting does the same, so it no longer takes the connection-wide bg_lock on every non-critical completion. Signed-off-by: Hai Zhong Zhou <hazhou@ddn.com>
d6c406a to
3444dea
Compare
|
@yongzech Thanks for the follow-up. Pushed On #3 (cross-queue budget): returning the budget in |
|
@hazhou-ddn can we merge this after the two splice write optimixations, so that we have one commit for splice in redffs ... and then this ... and then later the mtime change? |
Sure, we can do the merge as this order. So this implies the "two splice write optimizations" needs to be in 2.5.1? |
|
@hazhou-ddn I think so, since there is already communication going on about the splice write improvement. So I assumed ;-) |
yongzech
left a comment
There was a problem hiding this comment.
Review of 3444dea. My findings from the review of d6c406a are resolved, and I found no new correctness bug.
- Bg budget:
fuse_uring_end_active()now gives back the budget underbg_lockbefore it hands on the freed slot, andFR_URING_BG_RETURNEDkeepsfuse_request_end()from giving it back twice. In the batched example, each of K commits in oneio_uring_enter()returns its share before it admits, sofc->active_backgroundstays exact. Every caller ofend_active()ends the request withfuse_request_end()afterwards, directly or from task work:__fuse_uring_req_end, the commit-error path, andremove_pending_req(fg only). Teardown, abort and the fast path still give the budget back infuse_request_end()as before. - Stopped queue: dropping the fg override and the commit-message claim is right, and with one copy of the override left there is nothing to drift.
- Cross-queue re-flush (#3): agreed to leave it out. A bg request held back by the budget on queue B means B has a bg request in flight, and its completion re-flushes B.
- Lock order is unchanged (
queue->lock, thenbg_lock). The fast-path test of the bg lists is stable underqueue->lock.
Fine to merge after the splice changes in #281, as agreed with @hbirth.
Reviewed together with Claude Code.
fuse: alternate contested io-uring slots between foreground and bg
With the writeback cache, foreground requests and non-critical background
requests share the non-critical entries of a ring queue, max_noncritical of
them, 8 at the default depth of 10. When a request ended,
fuse_uring_end_active() offered the freed slot first to the kind of request
that freed it. Once background requests held every slot, each one that ended
was replaced by the next one from the background list, and a foreground
request on that queue was admitted only at a moment when the background list
happened to be empty. The opposite holds too: a foreground load that keeps its
list full holds back async writes the same way.
Admit with one helper, fuse_uring_flush_queue(), wherever bg_lock is held: on
background arrival, when a slot is freed while background requests wait, when
an entry is registered, and when the queue stops. Critical background requests
still go first. A free non-critical slot then goes to the only kind that can
take it, or, when both kinds can, to the kind that did not get the previous
contested slot, tracked by a per-queue noncrit_bg_turn. While a request of
either kind can be admitted, it is thus admitted within two non-critical
completions on its queue. A background request that the connection-wide
max_background budget holds back cannot take a slot and does not contend.
Without contention nothing changes: an async-only or a metadata-only load gets
every slot as before.
A background request that ended used to count in fc->active_background until
fuse_request_end() ran, after its slot had been handed on. When the server
commits several requests in one io_uring_enter(), fuse_request_end() runs for
all of them later from task work, so their budget was still counted while
their slots were handed on, and foreground took those slots without
contending. When background requests wait on the queue,
fuse_uring_end_active() now gives back the budget itself, under bg_lock and
before it admits, and marks the request FR_URING_BG_RETURNED so that
fuse_request_end() does not give it back again, and admission no longer counts
requests that have already ended. Without waiting background requests the
budget is still given back in fuse_request_end(), and the completion does not
take bg_lock.
Foreground arrival still admits only foreground requests, without bg_lock: a
background request that waits while a slot is free is held by the background
limits, so it could not take the slot. A completion with no background request
waiting does the same, so it no longer takes the connection-wide bg_lock on
every non-critical completion.