* ovl: sync_file_range() does nothing on overlayfs files
@ 2026-11-18 4:00 Ding Feng
0 siblings, 0 replies; only message in thread
From: Ding Feng @ 2026-11-18 4:00 UTC (permalink / raw)
To: linux-unionfs, linux-fsdevel
Cc: Amir Goldstein, Miklos Szeredi, Christian Brauner,
Pavel Tikhomirov
Hi,
sync_file_range(2) acts on file->f_mapping. For an overlayfs file that
is the overlay inode's mapping, which holds no pages: the data sits in
the real file's page cache. So on an overlayfs file the call writes and
waits on nothing and returns 0.
On a Docker overlayfs root (6.10.14): write 64 MiB to a file, then call
sync_file_range(fd, 0, 0, SYNC_FILE_RANGE_WAIT_BEFORE |
SYNC_FILE_RANGE_WRITE |
SYNC_FILE_RANGE_WAIT_AFTER);
Dirty in /proc/meminfo stays 64 MiB higher until fsync(). The same
program on ext4 sees Dirty drop by 64 MiB after the call. Mainline
fs/sync.c still takes file->f_mapping.
Amir posted a fix in 2018 [1]. Miklos preferred to leave it [2], and
Dave pointed out that the call used WB_SYNC_NONE and so guaranteed
nothing. Since commit c553ea4fdf27 ("fs/sync.c: sync_file_range(2) may
use WB_SYNC_ALL writeback"), the full write-and-wait form does
data-integrity writeback on other filesystems, so on overlayfs it now
silently skips what it does elsewhere.
cachestat() has the same cause, and Pavel's series in June [3] fixes it
by forwarding to the real file, as ovl_fadvise() does. Christian
suggested a helper in fs/backing-file.c for that instead of a new file
operation. Could sync_file_range() use the same helper? I can send a
patch along those lines if that direction is acceptable.
I found this while checking sync_file_range() against its man page
with an AI-assisted verification tool, and reproduced it as above.
[1] https://lore.kernel.org/linux-fsdevel/1535300717-26686-7-git-send-email-amir73il@gmail.com/
[2] https://lore.kernel.org/linux-fsdevel/CAJfpegv50HELSZuwt9gGjgSyB+4aPbiTncc-yBNqUVgTLNHaXw@mail.gmail.com/
[3] https://lore.kernel.org/linux-fsdevel/?q=%22ovl%3A+make+cachestat%28%29+work%22
Thanks,
Ding Feng
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-18 4:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 4:00 ovl: sync_file_range() does nothing on overlayfs files Ding Feng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox