Repository navigation
Linux 6.17: fuse: write dirty folios back before a truncate without the writeback cache - #292
Merged
hbirth merged 1 commit intoNov 18, 2026
Conversation
… cache
Without the writeback cache, ftruncate() to a smaller size is lost when
the file has pages that were written through a shared mapping and not yet
written back. The call returns 0, but the file keeps its old size and
contents, including the mapped stores, on every client:
fd = open(f, O_RDWR | O_CREAT | O_TRUNC); pwrite(fd, "X" x 5121, 0);
m = mmap(fd, 5121, MAP_SHARED); memset(m + 2047, 'Z', 3071);
ftruncate(fd, 0); /* returns 0 */
close(fd); /* size is 5121 again */
Truncating down and up again shows the old bytes where zeros belong, which
is how generic/029 fails. With msync() or fsync() before the truncate the
result is correct.
The server's truncate invalidates this client's page cache from inside its
SETATTR handler. fuse_reverse_inval_inode() launders the folios that are
still dirty, with i_size not yet changed, and the server applies those
writes after the truncate. A trace of redfs on 7.0.0-42 shows the two
WRITEs between SETATTR's send and its reply:
SETATTR sent
rfs_inval_0: fuse_reverse_inval_inode -> fuse_launder_folio
WRITE pos 0 len 4096, i_size 5121
WRITE pos 4096 len 1025, i_size 5121
SETATTR done, error 0
"fuse: drop the nowrite freeze from setattr" removed the freeze that used
to hold such writes back until the reply, because the notify waited on
them. "fuse: flush dirty folios before a truncate under DLM" then made the
writeback-cache path write back before the SETATTR, on the assumption that
only that configuration is invalidated on truncate. The path without the
writeback cache got neither, and the notify arrives there as well.
Write back and wait in fuse_wt_do_setattr() before a truncating SETATTR,
together with the staged splice copy that is already written back at this
point. Without the writeback cache only a shared mapping or a staged
splice copy leaves dirty folios, so the call does nothing for a file that
is not mapped. As for the splice case, a writeback error is left in the
mapping for fuse_flush_common() and does not fail the truncate.
open(O_TRUNC) is not changed: the O_TRUNC variants of the reproducer pass
without this.
A store through the mapping that races the truncate from another thread
can still dirty a folio after the write-back and before the reply, and
that folio is laundered as before. Closing that needs page_mkwrite to be
held off across the request, as the DAX case does with the invalidate
lock.
Tested with RED release/2.5 at 497d797afb on Ubuntu 7.0.0-42-generic,
without the writeback cache. trunc_mmap.py runs 23 variants of the
sequence, 14 of which have dirty mapped folios at the truncate: 13, 10 and
14 wrong results in three runs before, none in eight runs after.
generic/029 fails before and passes after; generic/030 passes. With the
writeback cache nothing changes (no wrong results before or after).
Signed-off-by: Allison Henderson <allison.henderson@ddn.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
(cherry picked from commit 407600f)
[ahenderson: fuse_do_setattr() is not split into fuse_wt_do_setattr() and
fuse_wb_do_setattr() here; the condition is added to its write-back of a
staged splice copy without the writeback cache]
hbirth
approved these changes
Nov 17, 2026
hbirth
left a comment
Collaborator
There was a problem hiding this comment.
This is a backport of an approved change
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
6.17 port of #288 (
407600f1ceecon the 7.0 branch).Without the writeback cache, an
ftruncate()to a smaller size is lost when the file has pages that were written through a shared mapping and not yet written back. The call returns 0, but the file keeps its old size and contents on every client:The server's truncate invalidates this client's page cache from inside its SETATTR handler.
fuse_reverse_inval_inode()launders the folios that are still dirty, and the server applies those writes after the truncate. The writeback cache with DLM already writes back before the SETATTR for this reason; the path without the writeback cache did not.Adaptation:
fuse_do_setattr()is not split into a write-through and a writeback function on this branch. The condition is added to its existing write-back of a staged splice copy without the writeback cache, which is the block the 7.0 commit changes infuse_wt_do_setattr().The known gap of the 7.0 commit applies here as well: a store through the mapping that races the truncate from another thread can still dirty a folio between the write-back and the reply.
Testing
Ubuntu 6.17.0-42-generic with
redfs.kobuilt from this branch, RED release/2.5, mounts without the writeback cache: