Skip to content

Linux 6.17: batch streamed writes and sendfile copies into 4 MiB aligned WRITEs through writeback - #283

Closed
cryptosven76 wants to merge 13 commits into
DDNStorage:redfs-ubuntu-hwe-6.17.0-16.16-24.04.1from
cryptosven76:red-writeback-batch
Closed

cryptosven76 wants to merge 13 commits into
DDNStorage:redfs-ubuntu-hwe-6.17.0-16.16-24.04.1from
cryptosven76:red-writeback-batch

Conversation

@cryptosven76

@cryptosven76 cryptosven76 commented Nov 8, 2026 •

Copy link
Copy Markdown

Stacked on #281. This branch is #281's seven commits plus six new ones. Review only the last six (rebased onto #281's review fixes): 5fe36adc7443 write-behind, 9633bfd01584 splice batching, 938b7252e08c bulk write-back before a notify invalidate, 5455754a8491 the option (a) invalidate bound, 5f0342e9e653 the earlier-chunk error check and 7ab2a6f61511 clearing the staged bit. I'll rebase it onto the base once #281 merges. Tracking: RED-54304 (RED-54224).

This is the rework of the splice batching and write-behind that were withdrawn from #281, built on the normal writeback path as @yongzech suggested. Both are module parameters that default to 0. At 0 the module sends exactly #281's requests: the same WRITE, READ and DLM counts in all 12 traced cases.

Problem. Streamed write(2) and sendfile copies into redfs send one synchronous 64 KiB FUSE_WRITE per call:

  • with the writeback cache, through the stream write-through from 3338f96;
  • without it, through do_splice_direct()'s 64 KiB pipe.

The server codes each WRITE as new erasure-coded extents, so a 64 KiB WRITE becomes a narrow stripe: 64 extents per 4 MiB instead of 2.

Commits:

  1. 161f39648452 fuse: write a streamed write behind the writer instead of through it. Behind stream_write_behind=N.
    • The stream's folios are dirtied through the normal buffered path.
    • Each completed 4 MiB chunk is kicked to writeback from a chunk boundary, so WRITEs are 4 MiB-aligned without align_page_order.
    • The writer waits only on the chunk N behind, which keeps 3338f96's goal: streamed folios are clean again within N chunks.
  2. 9f3c06689cec fuse: batch sendfile and copy_file_range fallback writes through writeback without the writeback cache. Behind splice_write_batch=N.
    • Spliced rounds dirty folios. They are written back and waited for at the round without SPLICE_F_MORE, at a failed or short round, and in ->splice_eof().
    • While data is staged, the inode keeps its cached size and times.

Both commits:

  • have no private staging buffer, no task_work and no new send path;
  • report errors only through the mapping's errseq, with a per-fd cursor, so fsync and close each report once;
  • never batch O_SYNC, O_DSYNC, O_DIRECT, O_APPEND or kernel threads.

Measured on a 6.17.0-42 client against a one-node cluster over RoCE, 4 GiB files, 3 reps. Every run was verified after a cold remount (128 of 128). MB/s:

Case both 0 (= #281) this PR withdrawn prototype
write(2) 64 KiB, wbc, stream_write_behind=8, dlm_grant_ahead=1 114 1479 1460
write(2) 1 MiB, same 610 1830 1800
dd copy bs=64k, same 108 873 798
dd copy bs=1M, same 505 1041 956
Python 3.12 shutil, no_writeback_cache, splice_write_batch=8 103 850 676
  • WRITEs are 1,024 × 4 MiB, all 4 MiB-aligned, instead of 65,536 × 64 KiB.
  • Share of the gain that needs dlm_grant_ahead: 72% for write(2) 64 KiB, 46% for dd 64 KiB, about 8% at 1 MiB, none for the no_writeback_cache copy.

Correctness, 55 of 55 checks passed:

  • unaligned destination offset 100;
  • an error surfaced once (a connection abort mid-copy: ECONNABORTED once per fd at fsync, then ENOTCONN);
  • two writers on one inode;
  • short writes;
  • O_DIRECT, PUNCH_HOLE and copy_file_range interleaved with a staged copy;
  • 8 × kill -9 mid-copy and mid-stream;
  • cc2 22/22 with and without the writeback cache.

Two-client contention (two DLM clients on one file, writeback cache, stream_write_behind=8):

  • dlm_grant_ahead at 1 or 4 made both clients 2-3x faster than at 0, in adjacent, interleaved and parallel patterns.
  • A client that only re-reads the region another client overwrites lost fewer cached pages with grant-ahead: 699k at 0, 559k at 1, 438k at 4.
  • The one cost: when two clients' regions meet at an unaligned boundary (1 GiB + 1 MiB), the grant reaches past it and the neighbour drops its whole cached range. That happened at N=1 and N=4 alike.
  • N=1 is the recommended value when enabled. Details are on Linux 6.17: optional DLM write grant ahead of copies and streamed writes; fix aligned writeback requests #281.

Overwrite without the writeback cache (2d3ee45ece80):

  • redfsd sends FUSE_NOTIFY_INVAL_INODE during an overwrite. Its own PR -> CW sattr lock conversion invalidates the cached value, and without the writeback cache that arms a page-cache invalidate.
  • fuse_reverse_inval_inode() now writes back and waits for staged splice data before the invalidate, as it already did for writeback-cache inodes with the DLM.
  • Result: a 1 GiB aligned overwrite goes out as 255 × 4 MiB WRITEs instead of 26,848 × 4 KiB launders.
  • Unaligned overwrite (offset 100), fixed: for an inode with a staged copy, the notify invalidate now ends at the last folio present when the notify is handled. The 1 GiB overwrite at offset 100 sends 259 WRITEs instead of about 40,000 4 KiB launders, and the invalidate takes about 1 ms instead of 12 s. A two-mount staleness check passes 8/8.
  • Data stays correct in both cases.

Not run: quota ENOSPC, multi-node IOR.

Ports: 7.0 and 6.12 need the same changes. Ports are yours, as for #281.

Agent changes:

Date (UTC) Head Host Session Internal session Resume
2026-11-08 13:20 9f3c06689c build-u26-1 Data management policies research c10f24a4-49fe-51da-96c4-4a22a16358c2 cd /mnt/linux-redfs-sendfile && claude --resume c10f24a4-49fe-51da-96c4-4a22a16358c2
2026-11-08 13:55 2d3ee45ece build-u26-1 Data management policies research c10f24a4-49fe-51da-96c4-4a22a16358c2 cd /mnt/linux-redfs-sendfile && claude --resume c10f24a4-49fe-51da-96c4-4a22a16358c2
2026-11-08 17:52 7ab2a6f615 build-u26-1 Data management policies research c10f24a4-49fe-51da-96c4-4a22a16358c2 cd /mnt/linux-redfs-sendfile && claude --resume c10f24a4-49fe-51da-96c4-4a22a16358c2

cryptosven76 and others added 4 commits November 8, 2026 06:22
sendfile(2) and the copy_file_range() fallback go through
do_splice_direct(), whose internal pipe holds 16 pages, so a copy into a
fuse file arrives as one 64 KiB ->write_iter per pipe round.  Under DLM
with the writeback cache, fuse_cache_write_iter() asks the server for a
write grant covering exactly the bytes of that write, and the server
grants exactly that range.  The next round starts where the grant ends,
so every 64 KiB waits for a FUSE_DLM_WB_LOCK round trip of its own.

Since "fuse: do not write through a write that drains a pipe" these
copies are cached and written back in max_write requests, and the grant
is what is left.  During a 4 GiB shutil.copyfile (Python 3.12, sendfile)
on a 6.17 client over TCP, the client sent 4000-6000 DLM_WB_LOCK a
second at 66 us each, one per 64 KiB, against 42 WRITEs of 4 MiB.  Over
RoCE the same copy runs at 519-667 MB/s, while a splice loop through a
1 MiB pipe, which pays one grant per MiB, reaches 1014 MB/s.

do_splice_direct() sets SPLICE_F_MORE on every round but the last.
When it is set, request the grant ahead of the write, for as far as the
run of sequential splice writes through this file has already come, at
most 4 MiB, and never past the next 4 MiB boundary after the write.  A
copy then costs one grant round trip per 4 MiB instead of one per
64 KiB: 1030 instead of 65536 for 4 GiB.  Growing the request with the
run and stopping at the boundary keep a copy into one region of a file
that other nodes write from taking a grant over their regions, as long
as the regions are aligned to 4 MiB.

The request is only a hint.  It takes a range lock over the whole range,
as every grant request does, so an invalidate cannot run between the
reply and the recording of the grant.  The write itself still requests
its own range under its own range lock; when the grant ahead is there it
finds it held and goes on without a round trip, and when a revoke took
it in between, it asks again as before.  Errors are left to the write.

Unchanged: splice(2) without SPLICE_F_MORE, writes without the
writeback cache or DLM, O_DIRECT, FOPEN_DIRECT_IO and passthrough files,
files with suid or sgid set, and sendfile to a socket or a pipe, which
does not reach ->splice_write of a fuse file.

Signed-off-by: Sven Oehme <soehme@ddn.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the server sets FUSE_ALIGN_PG_ORDER, fuse_writepage_need_send()
ends a writeback request at an alignment boundary if the chunk that
starts there no longer fits.  It counted the folio at the boundary,
which is the first page of that chunk, once in the request and once in
the chunk, so the chunk never fit when the alignment is a power of two
below max_pages: with a 2 MiB alignment and 4 MiB requests every
request held a single 2 MiB chunk.

Count only the pages queued before the boundary folio.  Requests then
carry max_pages again, start and end on alignment boundaries after the
first one of a run, and only the head of a run that starts unaligned is
short.  An alignment equal to max_pages, the only setting that worked
before, behaves as it did.

RED codes each 2 MiB bucket as one erasure-coded extent, so a server
that announces its bucket size gets bucket-aligned writeback requests
at the full request size.

Signed-off-by: Sven Oehme <soehme@ddn.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Under DLM with the writeback cache, a cached write asks the server for
a write grant covering exactly its own bytes, and the server grants
exactly that range: redfsd extends read grants over what the node
already holds, not write grants.  The next write starts where the grant
ends, so every write(2) of a stream waits for a FUSE_DLM_WB_LOCK round
trip of 80-90 us before it is written through.  A stream of 64 KiB
records on a RoCE client spends about 590 us in each write(2), one
grant and one synchronous FUSE_WRITE of 64 KiB, and pays the grant
65536 times for 4 GiB.

The client already records any granted range that covers the request,
and the server grants a wider write range when asked for one.  So the
round trip can go without a server change, the way it went for splice
copies: a streamed write is one of a run of writes of the same size,
so request the grant ahead of it, with the same ramp and 4 MiB boundary
that splice uses.  A sequential stream then pays one grant round trip
per 4 MiB instead of one per write.

Generalise fuse_splice_write_grant_ahead() to fuse_write_grant_ahead(),
which takes whether more follows instead of the splice flags, and call
it for a write that is written through as a stream, before the inode
lock is taken, as splice does.  An append is left out: it lands at
EOF, not at ki_pos.

A wider write grant makes another node that writes in the same 4 MiB
revoke it sooner, which is why the run has to have come as far as the
grant reaches.  A writer whose records do not follow each other
restarts the run at every write and never asks ahead.  The write
itself is unchanged: it is still written through and still requests
its own range, which it now finds granted.

Signed-off-by: Sven Oehme <soehme@ddn.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The grant-ahead requests a wider DLM write grant than the write needs.
That saves this client a round trip per write, but the node holding the
wider grant is favoured: every other node that writes or caches in that
range has to give its grant back and drop its cached pages there, a
trade-off that was found counterproductive for shared files before.
Whether it pays depends on how the cluster's clients share files, so
leave it to the administrator and keep the default behaviour as it was
before grant-ahead: a write requests exactly its own range.

dlm_grant_ahead (0644, default 0) sets the window in units of the
server's write alignment (fc->alignment_pages, which redfsd sets with
align_page_order), so that a grant ends where a server extent ends.  A
server that announces no alignment gets units of fc->max_write, the size
of a writeback request.  The window is at most 64 units and 256 MiB, so
that one client never takes an unbounded range from the others; larger
values are rejected.  The ramp and the boundary rule stay: a grant never
reaches further ahead than the run has come, nor past the next multiple
of the window.

At 0 neither caller tracks a run nor sends a request.  1 with a 4 MiB
unit, which a RED server without align_page_order gives today, is the
behaviour of the previous two commits; with a 2 MiB alignment that is 2.

Signed-off-by: Sven Oehme <soehme@ddn.com>
@cryptosven76

Copy link
Copy Markdown
Author

Pushed 2d3ee45ece80 for the staged-overwrite launders. fuse_reverse_inval_inode() now also writes back and waits before the invalidate when the inode holds staged splice data. It reuses the write-back block of the writeback-cache + DLM case, and the errors stay in errseq.

  • A 1 GiB aligned sendfile overwrite on a no_writeback_cache mount with splice_write_batch=8 now sends 255 × 4 MiB WRITEs, plus 2 split chunks and 16 × 4 KiB, instead of 26,848 × 4 KiB launders.
  • Unchanged: fresh-file copies, the parameters at 0, the B1/B2/B4/B7 checks, a kill mid-overwrite, and cc2 on no_writeback_cache (22/22).
  • Still open: an unaligned overwrite (offset 100) still launders about 40k folios. Its single whole-file invalidate runs for the whole copy, right behind it, so it needs a separate change. Throughput is not affected.
  • The notify itself comes from redfsd: its PR -> CW sattr lock conversion invalidates the cached value.

yongzech
yongzech previously approved these changes Nov 8, 2026

@yongzech yongzech 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.

Reviewed the last three commits (161f396, 9f3c066, 2d3ee45). Both features stay on the normal writeback path and default to 0, so I'm fine landing them.

What I checked:

  • Write-behind kicks from a chunk boundary, waits only on folios tagged for writeback and killably, and leaves AS_EIO for fuse_flush(). The per-fd cursor leaves f_wb_err to fsync().
  • The kick is WB_SYNC_NONE, so fuse_writepages() skips it once num_background reaches congestion_threshold, which would break the N-in-flight bound. redfsd sets the threshold to UINT16_MAX / 2, so that doesn't happen on RED.
  • Writeback WRITEs carry no caller credentials, but the RED server charges quota to the inode owner, so the principal doesn't change.
  • Staging is limited to do_splice_direct() rounds (pipe == current->splice_pipe), one task per inode, and excludes O_SYNC/O_DSYNC/O_DIRECT/DIRECT_IO/DAX/suid. Every way a copy can end flushes: the last round, a short or failed round, ->splice_eof(), and FOPEN_NOFLUSH close.
  • The attr, short-read and setattr handling mirrors the writeback cache.
  • 2d3ee45 reuses the existing write-back-before-invalidate block and adds no new server dependency compared with the launder it replaces.

Two inline comments, and two questions:

  • Quota ENOSPC wasn't run. With either parameter on, EDQUOT/ENOSPC moves from write(2)/sendfile(2) to a later write, fsync() or close(). Please run that case before anyone enables these on a quota-enabled dataset.
  • Is there a ticket for the unaligned-overwrite launders (bounding the notify invalidate), so it doesn't get lost after this merges?

Comment thread fs/fuse/file.c Outdated
WRITE_ONCE(fi->splice_stager, NULL);
if (ret > 0)
fuse_write_behind(out, pos, ret, chunks);
err = fuse_write_check_wb_err(out);

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.

This check runs after the round has already been copied into the page cache and i_size moved. When an earlier chunk failed, the round returns the error, so do_splice_direct() reports only the earlier rounds' bytes. But the code falls through to fuse_splice_stage_flush(), so this round's data still reaches the server, and the file ends up holding more than sendfile(2) reported. Commit 1 checks before the write instead (fuse_cache_write_iter()). Doing the same here, before fuse_splice_stage_begin(), would keep the count accurate. The check after the final flush is still needed.

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.

Fixed in 5f0342e (was 1359f5668ffc before the rebase onto #281's fixes). A round now checks for an earlier chunk's error before it is copied, and is skipped on an error; the check after the final flush stays. With test-only fault injection that fails the Nth writeback WRITE, the server held exactly one 64 KiB round more than sendfile(2) returned before the fix (3/3), and exactly the returned count after it (3/3).

Comment thread fs/fuse/fuse_i.h
* writeback cache (fuse_splice_write()). Never cleared: it only
* means something while the mapping is dirty or under writeback.
*/
FUSE_I_SPLICE_STAGED,

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.

Because this bit is never cleared, after one batched copy the inode keeps the staged attr rules (cached size/mtime win over the server's) for its whole life whenever its mapping is dirty. Without the writeback cache, that includes shared-mmap dirty pages, which before this PR took the server's size and mtime. Could the bit be cleared when a copy's final flush leaves the mapping clean? If the mmap case is intended, please say so in the comment.

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.

Fixed in 7ab2a6f. The bit is cleared when a copy's final flush, or the write-back at close, leaves the mapping clean. The check runs under the stager claim, so a new copy cannot stage between the check and the clear. A shared-mapping dirty page after a batched copy no longer gets the staged attribute rules: a trace shows the rule fired on the GETATTR before the fix and not after. So it takes the server's size and mtime, as before this PR.

@hbirth

hbirth commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

@cryptosven76 do you want to address @yongzech comments (they are minor), or should we merge this?

@cryptosven76

Copy link
Copy Markdown
Author

@hbirth We'll address both of @yongzech's comments today, together with a fix for the remaining unaligned-overwrite case. I'll ping you here when they're pushed, and then please merge.

The grant-ahead reserved its window, up to 256 MiB, with the blocking
fuse_range_lock_acquire_init(), and fuse_get_dlm_lock() then moved it
to LOCKED with the blocking fuse_range_lock_mark_locked().  The writer
so waited for any local read or write anywhere in the window, and for
any invalidate draining anywhere in it, not only over its own bytes:
the stuck-invalidation case of RED-52104, for a request that is only a
hint.

Take the range lock with fuse_range_lock_try_acquire_init() and move it
to LOCKED with fuse_range_lock_try_mark_locked() before the request,
and skip the grant-ahead when either finds the window busy.  The write
then requests its own range, as it does with grant-ahead off.  Once the
range is LOCKED, nothing can take an overlapping READY or LOCKED range,
so the mark_locked() in fuse_get_dlm_lock() returns at once, and the
range goes back to INIT for the round trip as before.

Local IO that arrives in the window while the request is in flight
still waits for that request, as it would behind a write over the
window; that happens at most once per window.

Signed-off-by: Sven Oehme <soehme@ddn.com>
The run of sequential writes that a grant-ahead reaches from advanced
before the write, by the length the caller asked for.  For sendfile(2)
and the copy_file_range() fallback that is the length written: the
internal pipe holds exactly what is spliced.  splice(2) callers commonly
ask for far more than the pipe holds, 1 MiB for 64 KiB for example, and
a short write(2) writes less than it asked for.  The next write then
starts short of where the run was said to continue, every call starts a
new run, and no grant is ever requested ahead: splice(2) with
SPLICE_F_MORE, which the first grant-ahead commit covers, never got one.
The same overstated length made the request reach only once the run
had come further than the asked length, and past the window boundary
after the bytes really written.

Advance the run after the write, from the position it reached:
*ppos after iter_file_splice_write() and ki_pos after a streamed write.
Before a splice, estimate the length from what the pipe holds when it
starts, which is what iter_file_splice_write() writes unless it has to
wait for more, so a splice(2) asks for the grant a sendfile(2) of the
same data asks for.  A splice without SPLICE_F_MORE still advances the
run, as before.

With dlm_grant_ahead at 0 nothing changes: neither the pipe is read nor
the run is tracked.

Signed-off-by: Sven Oehme <soehme@ddn.com>
FUSE_GRANT_AHEAD_MAX_UNITS and FUSE_GRANT_AHEAD_MAX_BYTES are used only
in file.c, next to dlm_grant_ahead, so define them there.

Only the 64-unit limit rejects a value; the 256 MiB limit caps the
window for a large unit, since the unit is per connection and not known
when the parameter is set.  Say so in the parameter description.

Signed-off-by: Sven Oehme <soehme@ddn.com>
With the writeback cache, a run of same-size buffered writes of
FUSE_WRITE_STREAM_MIN or more is written through from write(2)
(3338f96), so that the folios a stream never reads back turn clean
at once and reclaim can take them without a writeback pass.  The cost is
one request in flight per stream, each the size of the record, and each
record waiting for its own FUSE_WRITE.  On a RoCE client, real-data
streams of 64 KiB records write 115-120 MB/s and 1 MiB records 665-675
MB/s, while the same records written back reach several times that, and
a 64 KiB WRITE is coded on the server as a narrow 64 KiB extent.

Add the module parameter stream_write_behind.  When it is set to N, such
a write is cached like any other, and each time the stream completes a
chunk of the largest power of two a FUSE_WRITE carries (4 MiB on RED),
that chunk is put under writeback at once.  The writer then waits only
for the chunk N chunks behind it.  The folios still turn clean right
behind the writer, a stream has at most N chunks under writeback and
less than one dirty, so the bound on what it pins stays small and fixed,
which is what the write-through is there for on memory-limited clients.
The kick starts on a chunk boundary, so the requests are whole aligned
chunks without align_page_order.  Everything else is the existing
writeback path: the requests carry no caller credentials, and
truncation, DLM revokes and fsync() see the chunks as any other cached
data.

The kick and the wait run after the range lock and the inode lock are
dropped, as the flusher would.  The wait looks only at folios tagged for
writeback and is killable; filemap_fdatawait_range() would clear the
AS_EIO that fuse_flush() reports, and could not be interrupted while
the server holds the requests.

Errors become those of writeback, reported through the mapping's
errseq: fsync() and close() report them once each, as for any cached
write.  In addition, the next streamed write through the file fails with
an error that no write through it has reported yet, so a writer stops
within the window rather than at close.  That check keeps a cursor of
its own in the fuse_file and advances it, so a write sees each error at
most once and leaves f_wb_err to fsync().  O_SYNC and O_DSYNC records
stay written through, and O_DIRECT never streams.

Default 0, which keeps the write-through: with the parameter set, a
record that fails on the server is no longer reported by the write(2)
that wrote it.

Signed-off-by: Sven Oehme <soehme@ddn.com>
…eback without the writeback cache

Without the writeback cache, sendfile(2) and the copy_file_range()
fallback hand a file over 64 KiB at a time, the size of the internal
pipe of do_splice_direct(), and each round is one synchronous 64 KiB
WRITE.  A Python shutil copy of 4 GiB runs at 114 MB/s on a RoCE client,
and the server codes every 64 KiB as an extent of its own.

Add the module parameter splice_write_batch.  When it is set to N, a
round of do_splice_direct() is copied into the page cache through the
same iomap path the writeback cache uses and left dirty.  Each chunk the
copy completes (the largest power of two a FUSE_WRITE carries, 4 MiB on
RED) is put under writeback at once with fuse_write_behind(), the helper
streamed writes use, so the requests are whole aligned chunks with at
most N in flight.  Whatever is staged is written back and waited for
before the system call returns, at the points where the copy ends:

 - the round without SPLICE_F_MORE, which ends a copy of a given length;
 - ->splice_eof(), which do_splice_direct() calls when the source ran out
   before the length, the case of shutil, whose last round still carries
   SPLICE_F_MORE;
 - a round that fails or comes up short, which ends the copy as well.

There is no staging buffer, task_work or per-file hint: the data is
ordinary dirty page cache, sent by fuse_writepages() without caller
credentials, each folio once, and seen by every path that already
flushes or invalidates the cache, among them O_DIRECT, FOPEN_DIRECT_IO,
fallocate(), copy_file_range() on the server, fsync(), close() and the
NOTIFY_INVAL_INODE write back.  write_iter learns that a round is staged
from fi->splice_stager, which fuse_splice_write() claims with cmpxchg()
for the duration of the round and only for its own task; a second
copy into the same inode writes through as before, and the end of every
copy writes back whatever the inode holds.

Without the writeback cache the server's size and stamps win over the
cached ones, which would drop staged data the server has not seen: a
smaller size from GETATTR or a SETATTR reply truncates the page cache, a
short read shrinks i_size, and a newer mtime with auto_inval_data
launders the cache a folio at a time.  While FUSE_I_SPLICE_STAGED is set
and the mapping is dirty or under writeback, keep the cached size when
the server reports less, keep the cached stamps, treat a short read as
a hole, and write the staged data back before a SETATTR, as the
writeback cache does.  An FOPEN_NOFLUSH close still writes staged data
back, for a copy that ended on a failed source read and so had no flush
point left.

Errors go through the mapping's errseq.  The round that writes back a
copy's last data reports a failure through the cursor added for
streamed writes, so sendfile(2) fails, or returns the count of the
earlier rounds as do_splice_direct() does for any failing round, and
fsync() and close() still report it once each.  A failure of a chunk
under writeback ends the copy at the next round.  ->splice_eof() cannot
fail the call; its error is left for the next write, fsync() and
close().

Default 0, which writes each round through: with the parameter set, a
failed chunk is reported by a later round of the copy or, at the end of
a copy that ran to the end of its source, after sendfile(2) returned.

Signed-off-by: Sven Oehme <soehme@ddn.com>
A FUSE_NOTIFY_INVAL_INODE that arrives while splice_write_batch has a
copy staged in the page cache, without the writeback cache, drops the
range with invalidate_inode_pages2_range(), which launders every dirty
folio with a synchronous WRITE of its own.  The bulk write-back before
the invalidate ran only for writeback cache inodes with the DLM.  A
1 GiB sendfile(2) overwrite of an existing file on RED, which sends 11
such notifies during the copy, went out as 26,627 4 KiB WRITEs and
about 256 near 4 MiB ones, and as 42,273 4 KiB WRITEs at offset 100.

Write the range back and wait for it before the invalidate also when
the inode holds staged splice data, through the same path.  The wait
keeps the error in the mapping's errseq, so the copy, fsync() and
close() still report it once each.  The notify reader already waits for
the server in the launder that this replaces, which sends its WRITE
through the same writeback path, so the server answering requests while
a notify is pending is not a new requirement.  The aligned
overwrite now goes out as 255 4 MiB WRITEs.

Without the writeback cache there is no range lock to keep the copy
from dirtying the range again, so a folio dirtied after the write-back
is still laundered.  An unaligned overwrite (offset 100) still launders
about 40,000 folios: its one whole-file invalidate runs for the whole
copy, right behind it, and needs a separate change.

Signed-off-by: Sven Oehme <soehme@ddn.com>
A FUSE_NOTIFY_INVAL_INODE for an inode that holds a staged splice copy
without the writeback cache runs invalidate_inode_pages2_range() over
the notified range while the copy keeps adding folios to it.  When each
round of the copy has to read its partial head folio, which an
unaligned destination offset makes it do, the invalidate waits on that
folio, launders it with a WRITE of its own, and never gets ahead of the
copy.  A 1 GiB sendfile(2) overwrite at offset 100 on RED, whose one
whole-file notify arrives at the start of the copy, went out as about
40,000 4 KiB WRITEs from an invalidate that ran for the whole 12 s.

For such an inode, end the invalidate at the last folio present when
the notify is handled.  A folio added after that point cannot hold data
the notify supersedes: the server sent the notify after its view of the
file changed, a READ that fills a new folio is sent after the folio is
in the mapping, and a write puts its own data in.  Folios present at
that point, including one locked for a READ still in flight, stay in
the range and are dropped as before.  Every other inode keeps the
invalidate as it was.

The overwrite at offset 100 now launders one folio and its invalidate
takes about 3 ms.

Signed-off-by: Sven Oehme <soehme@ddn.com>
fuse_splice_write() checked for the error of an earlier chunk only
after the round had been copied into the page cache and i_size moved.
The round then returned the error, so do_splice_direct() reported the
bytes of the earlier rounds only, while the flush at the end of the
copy still wrote this round's data to the server: the file ended up
with more than sendfile(2) or copy_file_range(2) had reported.

Check before the round is copied, as a written-behind write(2) does.
An error that comes in while the round is copied is reported by the
next round, or by the check after the final flush.

Signed-off-by: Sven Oehme <soehme@ddn.com>
FUSE_I_SPLICE_STAGED was never cleared, so after one batched copy an
inode without the writeback cache kept the staged attribute rules for
as long as it lived: whenever its mapping was dirty, its cached mtime
and a larger cached size won over the server's.  A shared mapping
dirties folios without any copy, and before splice_write_batch such an
inode took the server's size and mtime.

Clear the bit when the final flush of a copy, or the write-back at
close, leaves the mapping clean.  The check runs under the stager
claim, which a copy takes before it sets the bit and holds while it
stages, so a new copy cannot stage between the check and the clear.

Signed-off-by: Sven Oehme <soehme@ddn.com>
@cryptosven76

Copy link
Copy Markdown
Author

Rebased onto #281's review fixes and pushed (7ab2a6f). Three new commits:

  • Unaligned staged overwrite (option a): for an inode with a staged splice copy, the notify invalidate ends at the last folio present when the notify is handled. A later folio is filled by a READ queued after the notify, or by the copy's own bytes, so it cannot hold data the notify supersedes. The 1 GiB overwrite at offset 100 now sends 259 WRITEs instead of about 40,000 4 KiB launders, and the invalidate takes about 1 ms instead of 12 s. A two-mount staleness check passes 8/8.
  • @yongzech's two comments are answered inline (5f0342e, 7ab2a6f).

u24 after the rebase (srcversion 2F3E6334): 1467/1829/835/1031/859 MB/s on the headline cells (write(2) 64k/1M, dd 64k/1M, shutil no_wbc). The overwrite probe sends 257/259 WRITEs at offsets 0/100. With all parameters at 0 the request counts equal #281's at N=0. cc2 passes with and without the writeback cache.

@hbirth Both PRs are ready from my side. Please merge #281 first, then this one.

@cryptosven76

Copy link
Copy Markdown
Author

@yongzech Your approval was dismissed by the force push that rebased this onto #281's review fixes (7ab2a6f). Since then the only changes are your two comments, both fixed and answered inline, and the bound on the staged invalidate (5455754). Could you take another look?

@hbirth

hbirth commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

since it was rebased on PR 281 I ahve merged it by hand

@hbirth hbirth closed this Nov 9, 2026
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