Skip to content

fuse: send the pieces of a synchronous large read or write together (RED-54742) - #285

Closed
cryptosven76 wants to merge 4 commits into
DDNStorage:redfs-ubuntu-hwe-6.17.0-16.16-24.04.1from
cryptosven76:red-54742-parallel-sync-io
Closed

cryptosven76 wants to merge 4 commits into
DDNStorage:redfs-ubuntu-hwe-6.17.0-16.16-24.04.1from
cryptosven76:red-54742-parallel-sync-io

Conversation

@cryptosven76

@cryptosven76 cryptosven76 commented Nov 11, 2026 •

Copy link
Copy Markdown

Fixes the single-stream limit in RED-54742 (Ubuntu 6.17). A synchronous call of more than one max_write/max_read piece (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):

  1. fuse_direct_read_iter() / fuse_direct_write_iter() (96b0ad8, ba00335): with async_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 advances ki_pos, as generic_file_* do for ->direct_IO. Without async_dio nothing changes.
    • Result: as before the series, the bytes before the first failed or short piece, or the error if there are none (sync_result); i_size follows the returned count and an extending write is not truncated back. The cached O_DIRECT path (fuse_direct_IO()) and aio keep their result.
    • Fatal signal: the caller waits killably; on SIGKILL it clears io->done, drops its reference and returns -EINTR at once. The pieces in flight hold references on io and the last completion frees it; the caller's pages stay pinned until then.
  2. fuse_perform_write() (93351a1, 8a5fec9): up to 8 (FUSE_WRITE_PAGES_INFLIGHT) pieces are outstanding. The reply handler does what fuse_send_write_pages() did after the request (uptodate on failure or short write, last-folio unlock, folio put). Replies are accounted in file order.
    • The piece nothing is sent after goes through fuse_simple_request() as before the series, so a one-piece call takes the old foreground path; the other pieces are background requests.
    • Fatal signal: no further piece is sent, and the pieces in flight are still waited for, since they reference the request and the folios (as fuse_simple_request() waits for a request once the server has it).
    • Critical entries: the pieces stay uring_critical, as they hold page cache folios an invalidation can wait for. With the writeback cache and without FUSE_WRITE_CACHE the server takes the DLM lock for the write, which can wait on a revoke, so such a writer (the IOCB_DIRECT fallback, for example) keeps one piece, and one critical entry, in flight, as before. FUSE_WRITE_CACHE writes 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_pos stop 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 local i_size stays 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 at fuse_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 MiB write() 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:

Transfer 1 proc write A → B 8 procs write A → B Read B/A (code unchanged)
2 MiB 744–889 → 754–861 (1.00x) 4332–4912 → 4393–5082 (1.01x) 0.87 / 0.97
4 MiB 814–982 → 915–1512 (1.35x) 4905–6167 → 4788–6152 (1.02x) 0.83 / 0.98
8 MiB 1034–1656 → 1333–2132 (1.28x) 5133–5948 → 9393–9836 (1.76x) 1.09 / 0.95
16 MiB 1641–1650 → 1964–2238 (1.28x) 5409–6220 → 10512–12901 (2.01x) 1.02 / 0.95

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:

Request Before After (this head)
O_DIRECT write 1 / 4 / 16 / 64 MiB 1130 / 1131 / 1487 / 1011 1440 / 2055 / 3323 / 5308
O_DIRECT read 1 / 4 / 16 / 64 MiB 1554 / 1741 / 1748 / 1634 1282 / 1756 / 4187 / 5075
Buffered write 1 / 4 / 16 / 64 MiB 673 / 779 / 754 / 733 667 / 1103 / 1670 / 2026
Buffered read (unchanged path) 16 / 64 MiB 1479 / 1679 1494 / 1607
h5bench 8 ranks, 10 GiB write 0.40 GB/s (25.5 s) 1.02 GB/s (9.8 s)
h5bench 8 ranks, 10 GiB read (unchanged path) 0.82 GB/s 0.80 GB/s

Testing (this head unless noted):

  • Signal: a 2000 MB dd write or read was SIGKILLed while redfsd was SIGSTOPped, then SIGCONT.
    • Direct write: the killed task left __redfs_direct_IO at once; 3 s later it was in do_exit → redfs_flush (the close-time FLUSH, which waits for a stopped daemon in any fuse). It exited 0.01 s after SIGCONT.
    • Buffered write: the task waits in redfs_perform_write for the pieces in flight and exited 0.21 s after SIGCONT.
    • The installed module stays in request_wait_answer of the I/O request itself and exited 0.1–2.1 s after SIGCONT.
    • A 2000 MB direct read finished before the stop could land, so it was not caught in the act; it uses the same __fuse_direct_IO() wait.
  • md5: 1 GiB written buffered (16 MiB), O_DIRECT (64 MiB) and with 5,000,013-byte writes is identical to the source on a second mount without writeback cache and through O_DIRECT reads.
  • Short write: a 32 MiB pwrite whose source buffer is unmapped after 16 MiB returns 16 MiB and leaves a 16 MiB file, buffered and O_DIRECT, before and after.
  • Large-file fsx: -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.
  • Default fsx (-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.
  • h5bench file checked with h5ls -r: 80 datasets.
  • Branch compile check: all fs/fuse objects build against the 6.17.0-42 headers with the branch's uapi fuse.h, no warnings; checkpatch clean.

Not tested:

  • ENOSPC or EDQUOT on a later piece of a multi-piece O_DIRECT write (no quota or full dataset set up on the test cluster). The partial result is covered only through the unmapped-buffer case, where a later piece fails before it is sent.
  • A short WRITE reply from the server.
  • A DLM revoke arriving during a multi-piece write with io-uring and writeback_cache.
  • Other kernels.

@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:

Date (UTC) Head Host Session Internal session Resume
2026-11-11 22:33 93351a1 tyan-h3-u24 2.5 release list ba0a42d5-92a3-5fb9-add0-ec19337acecf cd /mnt/red/.claude/worktrees/bridge-cse_0131UunFqmmGzVMrbF7wkLFu && claude --resume ba0a42d5-92a3-5fb9-add0-ec19337acecf
2026-11-12 03:47 8a5fec9 tyan-h3-u24 2.5 release list ba0a42d5-92a3-5fb9-add0-ec19337acecf cd /mnt/red/.claude/worktrees/bridge-cse_0131UunFqmmGzVMrbF7wkLFu && claude --resume ba0a42d5-92a3-5fb9-add0-ec19337acecf

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 hazhou-ddn left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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()).
  2. 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.
  3. Pieces after a failure have already reached the server, so "as before" is true of the returned count but not of the file.
  4. Up to 8 uring_critical background 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.

Comment thread fs/fuse/file.c Outdated
wr = inflight[head];
head = (head + 1) % FUSE_WRITE_PAGES_INFLIGHT;
nr--;
wait_for_completion(&wr->done);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread fs/fuse/file.c
* __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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both points are changed in ba00335.

  • Wait: a synchronous caller now waits killably. On a fatal signal it clears io->done under io->lock, drops its reference and returns -EINTR at once. The pieces in flight hold their own references on io, and the last completion frees it. fuse_aio_complete() completes io->done only while it is set.
  • Result: with sync_result, a failed piece records its start offset in io->bytes, and fuse_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 and fuse_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.

Comment thread fs/fuse/file.c
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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_size follows 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.

Comment thread fs/fuse/file.c Outdated

do {
/*
* Up to FUSE_WRITE_PAGES_INFLIGHT page writes are sent before the

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"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".

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread fs/fuse/file.c
ia->write.in.write_flags |= FUSE_WRITE_KILL_SUIDGID;

ap->args.uring_critical = true;
ap->args.end = fuse_write_pages_end;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 hbirth left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@hbirth

hbirth commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

added #287 on top of this ... will close it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants