Repository navigation
fuse: send the pieces of a synchronous large read or write together (RED-54742) - #285
cryptosven76 wants to merge 4 commits into
Conversation
A synchronous read or write on a FOPEN_DIRECT_IO open went through fuse_direct_io() with FUSE_IO_PRIV_SYNC, which sends one max_read or max_write piece and waits for its reply before it sends the next. With the 4 MiB pieces redfs uses, that caps one stream at the latency of one piece: 16 MiB O_DIRECT writes ran at 1.4 GB/s and 32 MiB reads at 2.0 GB/s on a 6.17 client, while the same requests through libaio, which sends all pieces before waiting, ran at 3.3 and 5.7 GB/s. With async_dio, synchronous calls now take __fuse_direct_IO() as well. It already handles a blocking kiocb: it sends every piece as a background request and waits on io->done. The caller advances ki_pos, as generic_file_direct_write() and generic_file_read_iter() do for ->direct_IO. Without async_dio nothing changes. The completion is the aio one, so a short write reply now fails the call with -EIO, as it already did for aio, instead of returning the short count.
…4742) fuse_perform_write() filled up to max_write bytes of folios, sent them with fuse_simple_request() and waited for the reply before it filled the next piece. A single buffered writer was capped at the round trip of one piece: 16 MiB writes ran at 0.85 GB/s with a 4 MiB max_write, while the daemon and servers could take several pieces at once. One MPI-IO aggregator writing an HDF5 file through glibc's POSIX aio issues exactly such synchronous pwrites. Each piece is now sent as a background request, and up to FUSE_WRITE_PAGES_INFLIGHT (8) are outstanding before the oldest is waited for. The reply handler does what fuse_send_write_pages() did after the request: it clears uptodate on a failed or short write, unlocks the last folio if it was left locked and drops the folio references. Replies are accounted in file order, so the result and ki_pos cover only the bytes before the first failed or short piece, as before. The pieces cover disjoint ranges and keep uring_critical, so under the writeback cache a background one does not wait for the background budget either.
hazhou-ddn
left a comment
There was a problem hiding this comment.
I read fs/fuse/file.c, dev.c and dev_uring.c at 93351a197a, but did not build or run anything. The speed-up is real and the in-order accounting is careful. Two behaviour changes are missing from the description, though, and one of them can leave a process that can't be killed. I'd fix those before merging. Details are inline:
- Should fix: both new paths wait without responding to signals, so a stuck call can no longer be killed (
fuse_perform_write(), and synchronous direct I/O through__fuse_direct_IO()). - Should fix: a synchronous O_DIRECT call that fails part-way now returns the error instead of the bytes done, and an extending write is truncated back.
- Pieces after a failure have already reached the server, so "as before" is true of the returned count but not of the file.
- Up to 8
uring_criticalbackground writes per writer can fill the critical io-uring entries.
Checked and fine: the ring buffer drains on every error path, and each wr is freed only after complete(). Only one locked non-uptodate folio is in flight at a time. ki_pos and i_size stay correct in the direct-I/O path, because a positive ret means every piece completed.
Testing gaps: a signal sent to a large synchronous call while the server is stalled; ENOSPC or EDQUOT on a later piece of a multi-piece O_DIRECT write; and io-uring with writeback_cache and DLM, with a revoke arriving during a multi-piece write.
| wr = inflight[head]; | ||
| head = (head + 1) % FUSE_WRITE_PAGES_INFLIGHT; | ||
| nr--; | ||
| wait_for_completion(&wr->done); |
There was a problem hiding this comment.
This wait doesn't respond to signals. Before, each piece went through fuse_simple_request(), and request_wait_answer() waits with wait_event_interruptible and then wait_event_killable: a signal sent FUSE_INTERRUPT, and kill -9 always got the caller out. Now a buffered write longer than one piece sits in D state if redfsd hangs or is stuck on a DLM revoke. It can't be killed, and it trips hung-task warnings.
Could this use wait_for_completion_killable()? On a fatal signal, stop sending new pieces, then wait (uninterruptibly) only for the pieces already in flight, since they reference our folios and wr.
There was a problem hiding this comment.
Changed in 8a5fec9. The wait is now wait_for_completion_killable(). On a fatal signal no further piece is sent, and the pieces already in flight are waited for uninterruptibly, since they reference wr and the folios. That matches fuse_simple_request(), which also waits for a request once the server has it. If no byte was accounted, the call returns -EINTR.
Test: a 2000 MB buffered write SIGKILLed while redfsd was SIGSTOPped stayed in redfs_perform_write for those pieces only, then exited 0.21 s after SIGCONT.
| * __fuse_direct_IO(), which sends all max_read pieces before waiting | ||
| * for any of them. | ||
| */ | ||
| if (!is_sync_kiocb(iocb) || ff->fm->fc->async_dio) { |
There was a problem hiding this comment.
Same issue for synchronous reads. __fuse_direct_IO() ends in wait_for_completion(&wait), which doesn't respond to signals, whereas the __fuse_direct_read() path below waited killably for each piece. Large O_DIRECT reads on an async_dio mount become unkillable while the server is stalled.
The result also changes. If a later piece fails, fuse_get_res_by_io() returns io->err and drops the bytes the earlier pieces read. Before, the call returned the bytes read up to the failure.
There was a problem hiding this comment.
Both points are changed in ba00335.
- Wait: a synchronous caller now waits killably. On a fatal signal it clears
io->doneunderio->lock, drops its reference and returns -EINTR at once. The pieces in flight hold their own references onio, and the last completion frees it.fuse_aio_complete()completesio->doneonly while it is set. - Result: with
sync_result, a failed piece records its start offset inio->bytes, andfuse_get_res_by_io()returns the bytes before the first failed or short piece, or the error if there are none. That is what the per-piece path returned. aio andfuse_direct_IO()keep their result.
Test: SIGKILL of a 2000 MB synchronous O_DIRECT call with redfsd stopped left __redfs_direct_IO at once (3 s later the task was in do_exit → redfs_flush). It exited 0.01 s after SIGCONT. The 2000 MB read finished before the stop could land, so only the write was caught in the act; both use the same wait.
| task_io_account_write(res); | ||
| if (!is_sync_kiocb(iocb)) { | ||
| /* As for reads: async_dio sends the pieces of a sync write together */ | ||
| if (!is_sync_kiocb(iocb) || ff->fm->fc->async_dio) { |
There was a problem hiding this comment.
This changes what a synchronous write returns when it fails part-way, beyond the short-reply case in the description. fuse_direct_io() used to return res > 0 ? res : err, so a 64 MiB write that hit ENOSPC or EDQUOT on its third piece returned 8 MiB. Now fuse_get_res_by_io() returns io->err. For an extending write under the exclusive lock, __fuse_direct_IO() then also calls fuse_do_truncate(), which drops the pieces the server did write.
Tools that depend on the short count (dd, cp, MPI-IO) will see a different result. Could synchronous calls keep the old result, the bytes up to the first failed piece? If not, please document the change. The same unkillable wait as in fuse_perform_write() applies here too.
There was a problem hiding this comment.
Changed in ba00335, so synchronous calls keep the old result. A 64 MiB write that fails on its third piece returns 8 MiB again.
i_sizefollows the returned count (offset + ret), not the end of the last piece sent.- With
sync_result, nothing is truncated, as on the per-piece path. - The truncate on failure stays only for the paths that had it (aio and
fuse_direct_IO()). - The wait is killable, as in the read thread.
Test: a 32 MiB O_DIRECT pwrite whose buffer is unmapped after 16 MiB still returns 16 MiB and leaves a 16 MiB file. I could not provoke ENOSPC or EDQUOT on a later piece on the test cluster, so a server-side error on a later piece is untested; the PR description says so.
|
|
||
| do { | ||
| /* | ||
| * Up to FUSE_WRITE_PAGES_INFLIGHT page writes are sent before the |
There was a problem hiding this comment.
"The result covers only the bytes before the first failed or short write" is true of the returned count and ki_pos. But up to 7 later pieces have already been sent and applied by the server, so the server's file can hold new data, and a larger size, past what the call reported. With writeback_cache the local i_size stays at the reported end while the server has more, and under DLM another node can see those extra bytes. That may be acceptable, but please say so here and in the PR description instead of "as before".
There was a problem hiding this comment.
Agreed, and now documented instead of "as before". The comments at fuse_perform_write() (8a5fec9) and __fuse_direct_IO() (ba00335), and a paragraph in the PR description, say that the pieces sent after the failed one were applied by the server. The server's file can then hold data and a size past the returned count; with writeback_cache the local i_size stays at the returned end, and under DLM another node can see the extra bytes.
I did not limit it. Stopping that would mean waiting for each piece before sending the next, which is the cost the series removes. The count and ki_pos stay exact, as for any write that fails part-way through more than one request.
| ia->write.in.write_flags |= FUSE_WRITE_KILL_SUIDGID; | ||
|
|
||
| ap->args.uring_critical = true; | ||
| ap->args.end = fuse_write_pages_end; |
There was a problem hiding this comment.
The critical entries (a quarter of each queue, at least 2, see dev_uring.c near fuse_uring_nr_critical()) exist so that requests which can block in userspace on a DLM revoke never take every entry. With io-uring, max_background is UINT_MAX, and fuse_simple_background() doesn't make critical requests wait for the background budget. So all 8 of these critical background pieces are admitted at once and can fill the critical entries of the writer's queue.
With FUSE_WRITE_CACHE the server doesn't take the lock for the write, so those pieces can't block. Without the flag, the server does take the lock and the piece can wait on a revoke. That covers the IOCB_DIRECT fallback in fuse_cache_write_iter(), which passes 0, and the last else if it can be reached with writeback_cache on. Before, one writer held at most one critical entry. Now one writer can hold them all while blocked, and a readfolio/readahead request that the revoke is waiting for can't get an entry.
Could the pieces be marked critical only when write_flags & FUSE_WRITE_CACHE, or could the number of critical pieces in flight be capped?
There was a problem hiding this comment.
Changed in 8a5fec9, along the lines of your first suggestion. With the writeback cache and without FUSE_WRITE_CACHE, fuse_perform_write() keeps one piece in flight, so such a writer again holds at most one critical entry. That covers the IOCB_DIRECT fallback and the last else. FUSE_WRITE_CACHE writes keep 8, since the server does not take the lock for them and they cannot block on a revoke. Mounts without the writeback cache also keep 8, because fuse_uring_req_critical() makes no entry critical there.
I kept the pieces uring_critical rather than dropping the flag for the non-FUSE_WRITE_CACHE case, because they hold page cache folios, the last one possibly locked, that an invalidation can wait for. That is the reason the old synchronous send was critical.
Not tested: a revoke during a multi-piece write with io-uring and writeback_cache.
…nd the wait (RED-54742) Synchronous direct I/O through __fuse_direct_IO() changed two things the one-piece-at-a-time path did. A call that failed part-way returned the error instead of the bytes before the failed piece, so a 64 MiB write that hit ENOSPC on its third piece returned -ENOSPC instead of 8 MiB, and an extending write under the exclusive lock was then truncated back. And the caller waited in wait_for_completion(), so a stalled server left it unkillable. With sync_result, set for synchronous calls from fuse_direct_read_iter() and fuse_direct_write_iter(), a failed piece records its start as the end of the result, fuse_get_res_by_io() returns the bytes before the first failed or short piece, or the error if there are none, i_size follows the returned count and nothing is truncated. The pieces after the failed one were applied by the server all the same, as noted at __fuse_direct_IO(). The cached O_DIRECT path, fuse_direct_IO(), and aio keep their result. The caller now waits killably. On a fatal signal it clears io->done under io->lock, drops its reference and returns -EINTR; the pieces in flight hold references on io and the last completion frees it.
…-54742) A buffered write of a single max_write piece became 16-26 % slower with pieces sent in the background: ior-easy with 4 MiB transfers on a writeback_cache mount went from 1.13 to 0.84 GB/s with one process. A background request goes to the queue of the next CPU, and that queue's ring task copies the payload, 482 us per 4 MiB piece, while a foreground request is copied by the caller; the call waits for the hand-off as well. The piece nothing is sent after is now sent with fuse_simple_request(), as before the series, so a one-piece call takes the old path and the last piece of a longer one overlaps with the pieces in flight. The wait for a piece is killable. On a fatal signal no further piece is sent and the pieces in flight are still waited for, since they reference the request and the folios; fuse_simple_request() also waits for a request once the server has it. With the writeback cache and without FUSE_WRITE_CACHE the server takes the DLM lock for a write, which can wait on a revoke. Such pieces are uring_critical and would hold up to eight critical entries of the queue. A writer like that, such as the IOCB_DIRECT fallback, keeps a single piece in flight, as before the series. FUSE_WRITE_CACHE writes, and mounts without the writeback cache, where no entry is critical, keep eight. The comment now says that the pieces after a failed one have been applied by the server, so its file can hold data and a size past the returned count.
hbirth
left a comment
There was a problem hiding this comment.
Looks good overall.
There are some small problems in comments and no Signed-Off tags (this is cosmetic).
I will create a new PR with the same commits, since I'm not allowed to commit to this branch.
|
added #287 on top of this ... will close it |
Fixes the single-stream limit in RED-54742 (Ubuntu 6.17). A synchronous call of more than one
max_write/max_readpiece (4 MiB on redfs) was sent one piece at a time, each waiting for the reply of the one before. redfsd and the servers take several pieces at once: through libaio, which already sends all pieces together, a 16 MiB O_DIRECT write ran at 3.3 GB/s against 1.4 GB/s synchronously. Found with h5bench, where one Open MPI aggregator issues every pwrite of an 8-rank job.Changes (four commits; the last two answer the review by hazhou-ddn and fix a 4 MiB regression):
fuse_direct_read_iter()/fuse_direct_write_iter()(96b0ad8, ba00335): withasync_dio, a synchronous call on a FOPEN_DIRECT_IO open also goes through__fuse_direct_IO(), which sends every piece as a background request. The caller advanceski_pos, asgeneric_file_*do for->direct_IO. Withoutasync_dionothing changes.sync_result);i_sizefollows the returned count and an extending write is not truncated back. The cached O_DIRECT path (fuse_direct_IO()) and aio keep their result.io->done, drops its reference and returns -EINTR at once. The pieces in flight hold references onioand the last completion frees it; the caller's pages stay pinned until then.fuse_perform_write()(93351a1, 8a5fec9): up to 8 (FUSE_WRITE_PAGES_INFLIGHT) pieces are outstanding. The reply handler does whatfuse_send_write_pages()did after the request (uptodate on failure or short write, last-folio unlock, folio put). Replies are accounted in file order.fuse_simple_request()as before the series, so a one-piece call takes the old foreground path; the other pieces are background requests.fuse_simple_request()waits for a request once the server has it).uring_critical, as they hold page cache folios an invalidation can wait for. With the writeback cache and withoutFUSE_WRITE_CACHEthe server takes the DLM lock for the write, which can wait on a revoke, so such a writer (theIOCB_DIRECTfallback, for example) keeps one piece, and one critical entry, in flight, as before.FUSE_WRITE_CACHEwrites cannot block on a revoke, and without the writeback cache no entry is critical, so those keep 8.Behaviour after a failed piece: the returned count and
ki_posstop at the first failed or short piece, but the pieces sent after it (up to 7 buffered, or all pieces of a direct call) were applied by the server all the same. The server's file can then hold data, and a size, past the returned count; with writeback_cache the locali_sizestays at the returned end, and under DLM another node can see the extra bytes. This is the same as after any write that fails part-way through more than one request, and is documented atfuse_perform_write()and__fuse_direct_IO().Regression found and fixed (8a5fec9): with every piece in the background, a single-piece buffered write got slower. ior-easy with 4 MiB transfers fell from 1.13 to 0.84 GB/s with one process. Traced on u24: a background request goes to the next CPU's queue (
fuse_uring_select_queue(..., true)), and that queue's ring task copies the payload (482 µs per 4 MiB), while a foreground request is copied by the caller. ior's 4 MiBwrite()took 4.8 ms instead of 2.25 ms. With the last piece in the foreground the trace shows the caller copying again.Measured on tyan-h3-u24 (6.17.0-42) against 2.5.2 servers (tyan-h3-u25). The test module is the 2.5.3~alpha.1 DKMS source with this series applied (same functions as this branch); the baseline is the installed module from the same source.
ior-easy, file per process, writeback_cache, 20 s stonewall, 3 interleaved reps A (before) / B (this head), MiB/s:
Buffered reads do not run the changed code; their one-process ranges overlap between A and B (for 4 MiB, A 1586–2115, B 1415–1877).
fio psync, 1 job, 10 s each, MB/s:
Testing (this head unless noted):
ddwrite or read was SIGKILLed while redfsd was SIGSTOPped, then SIGCONT.__redfs_direct_IOat once; 3 s later it was indo_exit→redfs_flush(the close-time FLUSH, which waits for a stopped daemon in any fuse). It exited 0.01 s after SIGCONT.redfs_perform_writefor the pieces in flight and exited 0.21 s after SIGCONT.request_wait_answerof the I/O request itself and exited 0.1–2.1 s after SIGCONT.__fuse_direct_IO()wait.-e 1 -l 134217728 -N 2000, ops up to 32 MiB (3 seeds) and up to 6 MiB (1 seed), buffered and O_DIRECT (-Z -R -W -r 4096 -w 4096 -t 4096), each with and without writeback_cache. 16 runs, all "All 2000 operations completed A-OK" (also on 93351a1). The first run of each set was traced: 972–1069 full 4 MiB WRITE requests per run, so the multi-piece paths ran.-e 1 -N 100000): 5 runs with writeback_cache and 3 without, all pass. These use fsx defaults (file up to 256 KiB, ops up to 64 KiB), so they never sent more than one piece; the large-file runs above cover the changes.h5ls -r: 80 datasets.fs/fuseobjects build against the 6.17.0-42 headers with the branch's uapifuse.h, no warnings; checkpatch clean.Not tested:
@hbirth could you take this forward from here: review, port to the other
redfs-*branches (7.0, 6.12/RHEL 10, 6.8, RHEL 9) and decide on the in-flight count? Raw data: u24:/var/tmp/soehme/red54742/res/.Agent changes:
cd /mnt/red/.claude/worktrees/bridge-cse_0131UunFqmmGzVMrbF7wkLFu && claude --resume ba0a42d5-92a3-5fb9-add0-ec19337acecfcd /mnt/red/.claude/worktrees/bridge-cse_0131UunFqmmGzVMrbF7wkLFu && claude --resume ba0a42d5-92a3-5fb9-add0-ec19337acecf