Skip to content

Linux 6.8: fuse: write dirty folios back before a truncate without the writeback cache - #298

Merged
hbirth merged 1 commit into
DDNStorage:redfs-ubuntu-noble-6.8.0-58.60from
achhenderson:fix-redfs-6.8-wt-truncate-mmap
Nov 19, 2026
Merged

hbirth merged 1 commit into
DDNStorage:redfs-ubuntu-noble-6.8.0-58.60from
achhenderson:fix-redfs-6.8-wt-truncate-mmap

Conversation

@achhenderson

@achhenderson achhenderson commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

6.8 port of #288 (407600f1ceec on 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:

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 */

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. #291 ("fuse: flush dirty folios before a truncate under DLM") writes back before the SETATTR for the writeback cache with DLM; this is the same for the path without the writeback cache.

Adaptation: fuse_do_setattr() is not split into a write-through and a writeback function on this branch, and 6.8 has no staged splice copy whose write-back the 7.0 commit extends. The write-back is a block of its own for a truncate without the writeback cache, placed right after the block #291 adds.

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.8.0-149-generic with redfs.ko built from this branch, RED release/2.5, mounts without the writeback cache:

  • A reproducer that runs 23 variants of the sequence above, 14 of them with dirty mapped folios at the truncate: 12, 14 and 6 wrong results in three runs before the change, none in eight runs after.
  • generic/029 fails before and passes after (2 of 2 runs); generic/030 passes.
  • With the writeback cache nothing changes: no wrong results before (2 runs) or after (3 runs).
  • Together with the lock series for RED-54356 (RED-54356: Linux 6.8: fuse: drop OFD and flock() locks at the last close instead of at RELEASE #299): 92 tests of the CI pass list pass 92 of 92 without the writeback cache (91 of 92 without the two changes; generic/029 fails). With the writeback cache 91 of 92 pass; generic/465 fails the harness's "daemon exists but mount point does not" check, which it also does without these changes.

CI

The x86_64 build check has been failing on this branch outside fuse: drivers/firmware/efi/libstub does not build with the runner's compiler ("false is a keyword with -std=c23 onwards"). It failed that way on both heads of #291, so expect it to be red here as well. The aarch64 check passed there.

… 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 here and this branch has no
  staged splice copy, so the write-back is a block of its own for a
  truncate without the writeback cache]
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