From: Dave Chinner <dgc@kernel.org>
To: Christoph Hellwig <hch@infradead.org>
Cc: Christian Brauner <brauner@kernel.org>,
Qing Zhang <diasyzhangqing@gmail.com>,
viro@zeniv.linux.org.uk, jack@suse.cz, raven@themaw.net,
djwong@kernel.org, linux-fsdevel@vger.kernel.org,
linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] namei: revalidate the symlink dentry before invoking get_link in RCU-walk
Date: Mon, 23 Nov 2026 08:59:08 +1100 [thread overview]
Message-ID: <awNlrO5A-kdDOYvO@dread> (raw)
In-Reply-To: <awB0RE6WN_v4YBbn@infradead.org>
On Fri, Nov 20, 2026 at 08:24:36AM -0800, Christoph Hellwig wrote:
> On Fri, Nov 20, 2026 at 02:59:42PM +0100, Christian Brauner wrote:
> > This only makes the window smaller.
> >
> > XFS can still reinitialize the inode right after this check and while
> > get() is running. Then ->get_link() operates on an inode that is being
> > reset underneath it. And the !get check only catches the case where the
> > that re-init already finished before we loaded ->get_link.
> >
> > RCU pathwalk relies on inode memory not being reused before a grace
> > period has passed. XFS itself frees inodes via call_rcu() but the
> > recycle path hands the same struct inode out again without waiting for
> > existing RCU walkers.
> >
> > So that should be fixed in XFS, either by not recycling an inode in
> > place while RCU walkers can still see it or by keeping i_op and the link
> > state valid across a recycle.
>
> Not recycling the inode really isn't an option, as that means there
> would cause duplicate inodes in the xfs inode cache. Keeping i_op and
> state in place sounds a bit more feasibly, but could be iffy as well.
>
> The best thing would be to find a way to keep the inode alive at the VFS
> level when XFS marks it reclaimable. That would be a huge an invasive
> change, but it would solve this and many other problems as well.
I don't think that's feasible without a massive rework of the VFS
inode life cycle management and/or the way XFS tracks inode metadata
dirtiness for writeback purposes.
Background:
The xfs_iget_recycle() code exists because dirty XFS_IRECLAIMABLE
inodes are tied into the journal machinery and need writeback before
they can be reclaimed. This is all invisible to the VFS, and it is
done via lockless lookups and atomic state checks without the need
for reference counts within XFS itself.
The issue is that reclaiming such an inode generally requires a log
force to stabilise it in the journal before it can be written back,
and the act of writing it back requires access to the inode state.
Hence the journal requires the XFS inode to live in XFS_IRECLAIMABLE
state until metadata writeback is complete, regardless of any other
inode state changes.
xfs_ireclaim() can expedite the writeback portion of reclaim (by
running an inode flush) but it does not expedite the required
journal flush if the inode is still dirty in memory. On lookup
of an XFS_IRECLAIMABLE inode in RCU mode, we cannot directly reclaim
a dirty XFS_IRECLAIMABLE inode because it requires blocking on both
a log force and metadata writeback. That's why the inode is sitting
in the XFS_IRECLAIMABLE limbo in the first place...
That's where the xfs_iget_recycle() code stepped in - it
reinitialises the VFS portion of the inode without affecting the
internal journal state of the inode. This allows new modifications to
be added to the inode and the attached log item without any
discontinuities in journal state.
The reason it does a full initialisation of the VFS inode is that
the inode can change identity whilst in XFS_IRECLAIMABLE. i.e. it
could be unlinked and then reallocated as a different inode (same
number, different generation), and so the type can change (e.g. REG
-> DIR) and hence a full VFS init is required to recycle it.
And the reason that we've always done this recycle is for
performance reasons - the inode allocation algorithms can prefer to
allocate recently freed inodes (for locality reasons), and hence
recently unlinked inodes in the IRECLAIMABLE state can be
reallocated and need recycling because the final unlink state hasn't
reached stable media before they are recycled.
Doing things like forcing logs, instant reclaim, RCU
synchronisation, etc have all had significant performance impacts
due to the additional latency these operations add to common
workload patterns. Hence the rarity of this recycle issue hasn't
outweighed the cost of the "simple" fixes to everyday operation.
---
> A good reproducer for the issue would help either way.
IIRC, we reproduced this previously using unlinked inodes and
exploiting the inode allocation algorithms to immediately reallocate
said freed inodes whilst they were still in the IRECLAIMABLE state.
I suspect that an acceptible fix here is made up of two parts. The
first is for clean inodes in IRECLAIMABLE state - they can be freed
without needing to wait for IO, so if the inode is clean we simply
reclaim it and return a 'miss' from the fast lookup path. Then the
lookup will hit the slow path, allocate a new inode, instantiate it
from the underlying cached inode cluster buffer (i.e. no IO needed)
and return that newly allocated indoe for the next VFS life cycle.
THis only costs a bit of extra CPU for the reclaim/reallocate case
for clean inodes, and should avoid the issue for all clean inodes.
For dirty inodes, it's a bit more complex - we are going to have to
block in the lookup path to resolve it. The fast path is going to
have to tag the inode as IRECLAIM so that all other lookups will
avoid it, then drop out of the lockless lookup mode. If the inode is
pinned, we need to force the log to enable expedited writeback to
succeed.
Then we can treat it like the clean path - calling
xfs_inode_reclaim() will then expedite the writeback flushing,
remove the inode from the cache and schedule it for freeing via
call_rcu(). Now we can run the cache miss path that will instantiate
a new inode from the underlying cluster buffer, and that gets
returned for the new VFS inode life cycle.
These two mods will give correct behaviour in all situations. It
will still have performance imapcts in the unlink/alloc case,
though, because that's the typical latency sensitive workload (think
working with lots of short term temp files) where the current
xfs_iget_recycle() code works well.
Hence there is a 3rd part to fixing this - avoiding reallocation of
free inodes still in XFS_IRECLAIMABLE state. Right now we have a
separation of on-disk indoe allocation (xfs_dialloc()) and in-memory
inode allocation (xfs_icreate()), with both of these functions being
paired everywhere we allocate an on-disk inode identically.
xfs-dialloc() retuns the inode number of the allocated inode, and
xfs_icreate() instantiates the in-memory inode for that inode
number.
Moving the instantiation of the in-memory inode to the same place we
select and allocate the on-disk inode would allow us to avoid
allocating IRECLAIMABLE inodes on-disk. i.e. we select a candidate
inode for on-disk allocation, check if it is in-memory already, and
if so, select a different inode to allocate. Otherwise, allocate the
in-memory inode and insert it into the cache as XFS_INEW without
doing any of the final setup, the allocate the on-disk inode for
that inode number, and then when that succeeds, do the final setup
of the in-memory inode that enables future lookups to find it in
cache...
At this point, we handle lookups of IRECLAIMABLE inodes correctly,
and we avoid the common situation where lookup-based reclaiming of
dirty IRECLAIMABLE inodes has a major impact on performance...
Cheers,
Dave.
--
Dave Chinner
dgc@kernel.org
prev parent reply other threads:[~2026-11-22 21:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 8:39 Qing Zhang
2026-11-20 13:59 ` Christian Brauner
2026-11-20 16:24 ` Christoph Hellwig
2026-11-22 21:59 ` Dave Chinner [this message]
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=awNlrO5A-kdDOYvO@dread \
--to=dgc@kernel.org \
--cc=brauner@kernel.org \
--cc=diasyzhangqing@gmail.com \
--cc=djwong@kernel.org \
--cc=hch@infradead.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=raven@themaw.net \
--cc=viro@zeniv.linux.org.uk \
/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
all inboxes | Powered by JetHome®