From: Ding Feng <dingf3ng@gmail.com>
To: linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org
Cc: Amir Goldstein <amir73il@gmail.com>,
Miklos Szeredi <miklos@szeredi.hu>,
Christian Brauner <brauner@kernel.org>,
Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Subject: ovl: sync_file_range() does nothing on overlayfs files
Date: Wed, 18 Nov 2026 12:00:56 +0800 [thread overview]
Message-ID: <20261118040056.6543-1-dingf3ng@gmail.com> (raw)
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
reply other threads:[~2026-11-18 4:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261118040056.6543-1-dingf3ng@gmail.com \
--to=dingf3ng@gmail.com \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=ptikhomirov@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox