Skip to content

fuse: do not write through a write that drains a pipe (stacked on #279) - #280

Merged
hbirth merged 3 commits into
DDNStorage:redfs-ubuntu-hwe-6.17.0-16.16-24.04.1from
cryptosven76:red-54152-splice-write
Nov 6, 2026
Merged

hbirth merged 3 commits into
DDNStorage:redfs-ubuntu-hwe-6.17.0-16.16-24.04.1from
cryptosven76:red-54152-splice-write

Conversation

@cryptosven76

Copy link
Copy Markdown

Stacked on #279. This branch is #279 (Horst's splice read fix and its revert of 9973e48) plus one commit; please review only the last one, 0f56879c27fb "fuse: do not write through a write that drains a pipe". Rebase it onto the base once #279 is merged. Tracking: RED-54152 (RED-54025).

Problem. With #279 the splice read side is fixed, but splice, sendfile and copy_file_range-fallback copies into a writeback-cached file still run at only 55-62 MB/s.

  • iter_file_splice_write() hands ->write_iter one pipe's worth at a time, and do_splice_direct() uses a 64 KiB internal pipe.
  • After four same-size writes, the stream detection from 3338f96 marks the file streamed and writes every 64 KiB chunk through: one DLM write grant and one synchronous WRITE each.

Change. A write that drains a pipe (a bvec in a sync kiocb) neither feeds the rolling mean nor counts as streamed, so it takes the normal cached path and is written back in max_write requests.

  • No locking or DLM code changes.
  • io_uring registered buffers (bvecs in an async kiocb) and plain write(2) keep today's behaviour.

Measured on a 6.17.0-42 client against a one-node cluster. Each copy is 4 GiB within one mount, after a cold remount, and compared with cmp:

Writeback cache #279 #279 + this
Python shutil.copyfile (sendfile) 55 MB/s 258 MB/s
cat a > b 54 MB/s 342 MB/s
cp (kernel copy_file_range fallback) 62 MB/s 354 MB/s
splice through a 1 MiB pipe 320 MB/s 796 MB/s

During shutil the WRITEs are now 4 MiB instead of 64 KiB. Without the writeback cache nothing changes (64-71 MB/s), since every write is synchronous there by design. dd bs=64k with write(2) is unchanged at 57-76 MB/s.

Correctness checks, all passed:

  • dirty splice pages read correctly from a second mount, and remote overwrites invalidate;
  • races against O_DIRECT and buffered writers on another mount: 0 bad pages;
  • fsync durability across a remount;
  • Redfs ubuntu hwe fix splice read #279's read checks, plus socket.sendfile matched by sha256.

Notes:

  • mtime is stamped when the dirty times are flushed, about +0.07 s after the copy. A dd bs=32k control shows the same, so this is existing cached-write behaviour.
  • An ENOSPC or quota error now shows up at fsync or close instead of from sendfile itself, as for any buffered write. This was not exercised.
  • About 66 us of DLM write-grant work per 64 KiB chunk remains.
  • Not done here: raising the 64 KiB stream threshold. On this client, cached writes beat write-through at every record size: 64 KiB 73 vs about 470 MB/s, 1 MiB 474 vs 1343 MB/s. But that changes every streamed write(2) writer, and a single-client test cannot judge the case the threshold was built for. That is your call.
  • Ports to the other branches are yours, as agreed: 6.12 and 7.0 need the same condition, 6.8 and RHEL9 are not affected.

Claude sessions

Date (UTC) Head Host Session name Session Resume
2026-11-06 16:15 0f56879c27 build-u26-1 Data management policies research session_0131UunDKWYf1fyEXfedDXbu, c10f24a4-49fe-51da-96c4-4a22a16358c2 cd /mnt/red/.claude/worktrees/bridge-cse_0131UunDKWYf1fyEXfedDXbu && claude --resume c10f24a4-49fe-51da-96c4-4a22a16358c2

🤖 Generated with Claude Code

hbirth and others added 3 commits November 6, 2026 11:07
…e write grant"

This reverts commit 9973e48.

Signed-off-by: Horst Birthelmer <hbirthelmer@ddn.com>
filemap_splice_read() serves the page cache without calling ->read_iter,
so splice, sendfile and the copy_file_range fallback skip the size
update, the DLM read grant with its invalidation fence and the direct io
dispatch, and fill pages that no grant covers.  Use copy_splice_read().

Fixes: 2cb1e08 ("splice: Use filemap_splice_read() instead of generic_file_splice_read()")
Signed-off-by: Horst Birthelmer <hbirthelmer@ddn.com>
With the writeback cache, a streamed write of FUSE_WRITE_STREAM_MIN or
more is written through: four writes of the same size in a row make the
file streamed, and each such write is sent as one synchronous WRITE.
That suits a writer working through a file in records of its own size.

Splice, sendfile and the copy_file_range fallback are not such writers.
iter_file_splice_write() hands ->write_iter one pipe's worth at a time,
and do_splice_direct() uses a 64 KiB internal pipe, so every copy that
goes this way looks like a stream of 64 KiB records.  Each 64 KiB chunk
then costs a DLM write lock request and a synchronous WRITE.  On a 6.17
client with fuse_splice_read() fixed to go through ->read_iter, a 4 GiB
copy into a writeback-cached file ran at 55 MB/s with shutil.copyfile
(sendfile), 54 MB/s with cat and 62 MB/s with cp, 1324 WRITEs/s of 64
KiB at 0.8 ms each, while dd bs=1M did 258-344 MB/s.

The chunk size is the pipe's, not the writer's record, so a write that
drains a pipe neither feeds the rolling mean nor counts as streamed.  It
is a buffered write like any other: dirty in the page cache under the
same DLM grant and range lock, and written back in max_write requests.
iter_file_splice_write() passes a bvec in a sync kiocb; io_uring
registered buffers are bvecs in an async kiocb and still count as
records.

Same 4 GiB copies, writeback cache, every copy compared with cmp after a
cold remount:

  shutil.copyfile    55 -> 258 MB/s
  cat                54 -> 342 MB/s
  cp                 62 -> 354 MB/s
  splice, 1 MiB pipe 320 -> 796 MB/s

During shutil the WRITEs are now 4 MiB.  Copies with write(2), such as
dd, take the same path as before.  Without the writeback cache
nothing changes: every write is synchronous there by design, and the
copies stay at 64-71 MB/s.

Signed-off-by: Sven Oehme <soehme@ddn.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cryptosven76
cryptosven76 requested a review from hbirth November 6, 2026 15:57
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.

2 participants