Re: [PATCH v3 2/8] ovl: setup overlayfs' private bdi
From: Amir Goldstein
Date: Thu Nov 05 2026 - 06:23:27 EST
On Wed, Nov 4, 2026 at 9:45 PM Josef Bacik <josef@xxxxxxxxxxxxxx> wrote:
>
> From: Chengguang Xu <charliecgxu@xxxxxxxxxxx>
>
> Setup overlayfs' private bdi so that we can collect
> overlayfs' own dirty inodes.
>
> Signed-off-by: Chengguang Xu <charliecgxu@xxxxxxxxxxx>
> [josef: only for an overlay that tracks dirty inodes, add
> ovl_tracks_dirty()]
> Signed-off-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
> ---
> fs/overlayfs/overlayfs.h | 18 ++++++++++++++++++
> fs/overlayfs/super.c | 10 ++++++++++
> 2 files changed, 28 insertions(+)
>
> diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
> index 444e28c09145..0ef81c7a9701 100644
> --- a/fs/overlayfs/overlayfs.h
> +++ b/fs/overlayfs/overlayfs.h
> @@ -7,6 +7,7 @@
> #include <linux/kernel.h>
> #include <linux/uuid.h>
> #include <linux/fs.h>
> +#include <linux/backing-dev.h>
> #include <linux/fsverity.h>
> #include <linux/namei.h>
> #include <linux/posix_acl.h>
> @@ -683,6 +684,23 @@ static inline bool ovl_should_sync_upper_fs(struct ovl_fs *ofs)
> ofs->config.fsync_mode == OVL_FSYNC_STRICT;
> }
>
> +/*
> + * Does this overlay track the upper inodes that are modified through it, so
> + * that syncfs() and unmount only have to sync those?
> + *
> + * Only with fsync=relaxed. In the other modes the overlay never syncs, or it
> + * syncs the entire upper filesystem. fsync=auto does not count until it has
> + * been resolved. sync_filesystem() does not write any inodes of a filesystem
> + * that has no writeback, like tmpfs, and nothing ever clears their dirty flags.
> + */
> +static inline bool ovl_tracks_dirty(struct ovl_fs *ofs)
> +{
> + if (!ovl_upper_mnt(ofs) || ofs->config.fsync_mode != OVL_FSYNC_RELAXED)
> + return false;
> +
> + return ovl_upper_mnt(ofs)->mnt_sb->s_bdi != &noop_backing_dev_info;
> +}
> +
I had concerns that this is not the exact opposite of ovl_should_sync_upper_fs()
and testing noop_backing_dev_info here is not optimal.
It is better to set the fsync mode correctly for noop_backing_dev_info
at mount time (non-upper ovl cannot have non default fsync mode already).
So I sent you v2 of my patch with my own version of ovl_tracks_dirty().
Other than that the series looks good to me but I am lacking familiarity with
writeback to be able to properly assess the vfs correctness.
I ran fstests on overlayfs nothing popped out, but it doesn't say much
on the implementation.
FYI overalyfs fstests supports {,_require}_scratch_shutdown{,_and_syncfs}
and there are 2 tests that make use of those overlay/078 overlay/087
maybe that's a start for some test that could exercise this code.
Thanks,
Amir.