Linux XFS filesystem development
 help / color / mirror / Atom feed
From: Dave Chinner <dgc@kernel.org>
To: Jan Kara <jack@suse.cz>
Cc: Christoph Hellwig <hch@infradead.org>,
	Christian Brauner <brauner@kernel.org>,
	Qing Zhang <diasyzhangqing@gmail.com>,
	viro@zeniv.linux.org.uk, 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: Tue, 24 Nov 2026 07:49:21 +1100	[thread overview]
Message-ID: <awSm0WX5bb5p9hnW@dread> (raw)
In-Reply-To: <d2w6jvflihqiyfbht3qv3mgjg3muuuvmhnss5j5dp4zh6axhn2@nsegavvnkpie>

On Mon, Nov 23, 2026 at 09:50:21AM +0100, Jan Kara wrote:
> On Mon 23-11-26 08:59:08, Dave Chinner wrote:
> > 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.
> 
> I'd just mention one possible solution which you didn't mention below (I
> don't know how complex it would get for XFS but we effectively do this in
> ext4) - make the VFS part of the inode and the journalled portion of the
> inode separate entities in memory (independently allocated & freed).

Yes, that's another avenue - we already have the abstraction of hte
log items being tracked and used by the journal, and the inode
simply contains a pointer to the log item for.

*however*

> Then
> you can free the VFS portion of the inode while still keeping the
> journalled portion allocated.

The separation is between the XFS/VFS inode structure and the xfs
log item structure. The problem is that the XFS/VFS inode is a
single comingled structure (i.e. struct xfs_inode { ... struct inode
vfs_inode; } and xfs_iget_recycle() is reinitialising just the VFS
portion of the structure.

The reality is that the XFS inode is still needed by journal
writeback to format the current state of the inode into the backing
buffer at writeback time, because the delta written to the journal
is not tracked by the log item itself past the journal commit.

We used to have separate XFS and VFS inode structures - a couple of
decades ago. That went away a long time ago, and I don't think we
really want to go back in that direction because we'd have to undo
all the inode field deduplication we've done in the last 15 years...

> If the inode location on disk gets
> reallocated, you allocate fresh VFS part and recycle the journalled part.
> In ext4 we have this natural separation between the buffer carrying the
> inode structure on disk which is part of the journalling process and the
> inode itself so this separation is easy there. For XFS I presume this is
> complex or you wouldn't bother with all the separate inode lifetime logic
> but I just wanted to toss this idea out.

XFS uses individual structure-based inode logging, not buffer based
logging. Hence writeback of the inode log item still needs to format
the inode structure into the backing buffer. Hence the inode
structure must be available at writeback time, and because we do
transactions on inodes after evict (e.g. unlinked inode freeing),
the inode structure -must- persistent beyond the VFS inode life
cycle.

When describing the above solutions, I did consider "can we keep the
log item and reallocate the struct xfs_inode and point it back at
the log item?" to do somethign similar to what you suggest. We could
potentially do that, but the changes we need to do first to enable
it are .... quite extensive.

Unfortunately, the log items are not reference counted by the
journal when being tracked for writeback, and the inode is not
reference counted by the log item's back pointer to the inode
itself. Hence disconnecting and reparenting the inode log item
whilst it is still active in the journal machinery is ... excitingly
complex.

(FYI - log item writeback reference counting and dynamic inode log
item design docs:

https://lore.kernel.org/all/aqI6v-_dc2DDSbgB@dread/

tl;dr: very complex!)

Then there's the fact that the inode cluster buffer tracks dirty
inode log items, too. Hence there's situations where buffer IO
completion can reach through the attached inode log item to the XFS
inode to change state, and it does this without holding a direct
reference to the inode, too. The state that allows this to be done
safely is held in the XFS inode itself (the flush 'lock' and
XFS_IFLUSHING) and processing is dependent on inode state (e.g.
XFS_ISTALE), and hence any 'replacement' of the xfs inode cannot be
done whilst the inode itself is under writeback....

So, yeah, I did consider the 'leave the log item in the journal,
recreate just the XFS/VFS inode' path, but handling the changeover
in a sane manner seems far more complex than the 'flush, reclaim,
reallocate' approach.

Cheers,

Dave.
-- 
Dave Chinner
dgc@kernel.org

      reply	other threads:[~2026-11-23 20:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  8:39 [RFC PATCH] namei: revalidate the symlink dentry before invoking get_link in RCU-walk Qing Zhang
2026-11-20 13:59 ` Christian Brauner
2026-11-20 16:24   ` Christoph Hellwig
2026-11-22 21:59     ` Dave Chinner
2026-11-23  8:50       ` Jan Kara
2026-11-23 20:49         ` 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=awSm0WX5bb5p9hnW@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