Re: [PATCH v7 0/7] ovl: only sync what was written through the overlay
From: Amir Goldstein
Date: Wed Dec 02 2026 - 17:11:37 EST
On Tue, Dec 1, 2026 at 10:08 PM Josef Bacik <josef@xxxxxxxx> wrote:
>
> > 1. Serialize syncfs calls with ovl s_sync_lock and use dirty list as v12 did
>
> Done in v8, and the wait on s_sync_lock is killable.
>
If the fallback to sync_filesystem(upper) stays, this would cause
a (false positive) lockdep warning.
And unmount and ro remount must not skip the sync on a fatal signal.
> > Holding upper s_umount shared during the walk will remove complexity
> > around freeze of upper and reduces the 3 states to just one dirty/tracked state.
>
> It does get it down to one state. The sb_start_write_trylock() and its
> fallback have to stay though, because freeze_super() sets
> SB_FREEZE_WRITE and drops s_umount before it calls sync_filesystem().
>
It takes s_umount again before sync_filesystem().
If the walk holds upper s_umount shared, could a single
"skip if frozen or ro" check replace the per-inode trylock
and the fallback? That may be simpler and won't have the
lockdep issue above.
> > 2. Replace inode references and shrinker with reclaim list
> >
> > Only an evicted tracked an linked ovl_inode needs to be added to the
> > reclaim list and ihold the upper inode
> > syncfs synced the tracked list (no extra upper ref) and the reclaim
> > list (with extra upper ref)
> > This should get rid of the shrinker hooks
> >
> > This is not simple but maybe a lesser evil than the shrinkers?
> > Not sure.
>
> I tried this and it has a problem. I haven't run v8 yet, so this is
> from reading the code, and I haven't reproduced it.
>
> The reclaim list gets one entry per eviction, not one per upper inode.
> The upper inode isn't ours, so there's nowhere to note that it's already
> on the list, and one upper inode can have many overlay inodes over time.
>
> A user doesn't need memory pressure to force the evictions. We have
> .drop_inode = inode_just_drop, and ovl_instantiate() and
> ovl_remove_upper() both d_drop(), so writing to a file, hard-linking it,
> unlinking the old name and opening the new one evicts a tracked, linked,
> dirty overlay inode every time around.
>
> Each round adds an entry and a
> reference on the same upper inode, and pruning the 4 oldest frees
> nothing because they all name that inode. The memory isn't charged to a
> memcg, killing the task doesn't free it, and only a syncfs, an unmount
> or the loop stopping ends it. The next sync then writes the same inode
> once per entry while it holds s_sync_lock. v7 didn't have this because
> it pinned the overlay inode, so each one had at most one entry.
>
> An entry can also outlive its file. A file that's evicted while dirty,
> looked up again and then unlinked stays pinned by the old entry, so the
> final iput() that does the delete runs in whichever eviction prunes it.
> That can be kswapd, and it can block on a frozen upper. v7 had a work
> item to keep that iput() out of reclaim.
>
> I see four ways to deal with the first one:
>
> 1. Cap the list. Past some number of entries add no more, and have the
> next sync do sync_filesystem() on the upper. A user can then only
> take their own overlay's sync back to what it is today.
> 2. Index the entries by upper inode. That brings back the xarray your
> first suggestion gets rid of.
> 3. Don't evict a tracked, linked overlay inode right away, so the next
> lookup finds it again through iget5_locked(). I haven't checked what
> else relies on overlay inodes going away at once, and it probably
> still needs the cap.
> 4. Go back to v7's pinned overlay inode and the shrinker.
>
> For the second, skipping the prune when the eviction runs in reclaim
> and treating an unlinked upper inode as droppable would keep that
> iput() out of reclaim. Which would you prefer?
Let's go with 4 with mutex and the single list.
One thing to watch: in v7, ovl_untrack() clearing WRITEBACK stopped
ovl_wait_inode() from re-dirtying an inode unlinked during the wait.
With a list, untrack can't see the inode the walker holds, so re-check
the link count before putting it back.
>
> > 3. Try to gate more ovl_track_inode() in existing helpers
>
> Done in v8. There are 13 tracking calls outside sync.c now, against 19
> in v7.
Nice!
But we need a way to tell us if we missed a tracking now or will
miss one in the future.
Please add a check that warns untracked dirty upper inode when its
overlay inode is evicted, at least at unmount after the final sync.
We probably want to use pr_warn_once() rather than WARN_ON,
because there may be false positives, but then we also need
to teach fstests to catch these warnings.
Thanks,
Amir.