From: Huang Shijie <huangsj@hygon.cn>
To: Andreas Gruenbacher <agruenba@redhat.com>
Cc: <viro@zeniv.linux.org.uk>, <brauner@kernel.org>, <jack@suse.cz>,
<hch@infradead.org>, <mic@digikod.net>, <axboe@kernel.dk>,
<gnoack@google.com>, <paul@paul-moore.com>, <jmorris@namei.org>,
<serge@hallyn.com>, <legion@kernel.org>, <aleksa@amutable.com>,
<libaokun@linux.alibaba.com>, <ebiggers@kernel.org>,
<djwong@kernel.org>, <sandeen@redhat.com>, <zhongyuan@hygon.cn>,
<fangbaoshun@hygon.cn>, <yingzhiwei@hygon.cn>,
<wujianyong@hygon.cn>, <shijie8@gmail.com>,
<linux-fsdevel@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-block@vger.kernel.org>, <gfs2@lists.linux.dev>,
<linux-security-module@vger.kernel.org>
Subject: Re: [PATCH v4 00/11] vfs: add inode iteration methods
Date: Thu, 26 Nov 2026 20:15:37 +0800 [thread overview]
Message-ID: <awgi6a0Hayug7RJH@hsj-2U-Workstation> (raw)
In-Reply-To: <CAHc6FU4h-FRvLkO_0ouTey9MbX=n61t3abt4hPNFOthsRGG9mQ@mail.gmail.com>
在 Wed, Nov 25, 2026 at 11:25:12PM +0100,Andreas Gruenbacher 写道:
> Huang,
>
> I have some thoughts ...
>
> On Wed, 25 Nov 2026 at 10:18, Huang Shijie <huangsj@hygon.cn> wrote:
> > This series adds a superblock inode iterator and converts the open-coded
> > sb->s_inodes walks in the VFS to it. The design follows the cursor-based
> > construct proposed by Christian Brauner:
> >
> > https://lore.kernel.org/all/20261120-mitverantwortlich-drehbaren-kantholz-241300d20168@brauner/
> >
> > and is the same direction as Dave Chinner's patch set:
> >
> > "vfs: improving inode cache iteration scalability"
> > https://lore.kernel.org/all/20241002014017.3801899-1-david@fromorbit.com/
> >
> > The caller owns the iterator state and drives the walk itself:
> >
> > CLASS(sb_inode_iter, iter)(sb, eligible, priv, flags);
> > while ((inode = sb_inode_iter_next(&iter)))
> > /* do stuff */;
>
> The pattern should be:
>
> for (CLASS(...); ...; ...) {
> /* ... */
> if (/* end iteration early */)
> break;
> /* ... */
> }
>
> so that the iterator goes out of scope immediately when the loop ends.
> Hide the details of the loop header in a macro and that this becomes:
>
> for_each_inode(inode, sb) {
The fs/jffs2/build.c has used this for_each_inode.
Maybe change to for_each_sb_inode?
> /* inode is referenced and unlocked here */
> }
>
> Use that to convert the simple cases.
>
> And then we've got preconditions that are checked while the inode is
> locked. Those can probably go in an expression:
>
> for_each_inode(inode, sb, expression) {
We still need add flags here.
In evict_inodes() and hook_sb_delete(), only the expression is not enough.
How about add a raw code like this:
for_each_inode_raw(inode, sb, expression, flags) {
}
And add a macro for_each_inode:
#define for_each_inode(inode, sb, expression) for_each_inode_raw(inode, sb, expression, 0)
Most of the cases, we can use the for_each_inode.
But in the evict_inodes() and hook_sb_delete() we can use the for_each_inode_raw.
> /* expression was true */
> /* inode is referenced and unlocked here */
> }
>
> This unfortunately cannot be implemented on top of the
> sb_inode_iter_next() pattern, at least not in a reasonable way, so we
> actually shouldn't use that pattern.
>
> The locked iterator would look like this:
>
> for_each_inode_locked(inode, sb) {
I tried this way today.
The macro for_each_inode_locked is complicated.
When I tried to add more hooks to super_operations to implement the
procfs issue, the for_each_inode_locked becomes more complicated.
BTW: the procfs issue see the link:
https://lore.kernel.org/all/20260920072811.2064247-1-huangsj@hygon.cn/
> /* inode is locked here */
> }
>
> This doesn't cover all existing cases, but that's okay. Don't force
> things into this pattern that are not a match.
>
> We can always extend things further if it makes sense.
>
> > The lock does not span iterations. sb_inode_iter_next() takes
> > sb->s_inode_list_lock, takes a reference on the next inode, drops the lock
> > again and hands the inode out; the reference is what keeps the cursor on
> > sb->s_inodes so that the next call can resume from it. As the iterator
> > is a cleanup class, a caller that breaks out early does not have to call
> > sb_inode_iter_end() explicitly.
> >
> > Two optional channels let a caller keep its own state instead of filling in
> > a shared context:
> >
> > - iter->eligible is called with inode->i_lock held, so that a caller can
> > reject an inode before a reference is paid for.
> >
> > - iter->status carries an error out of the walk. Setting it to a
> > negative value makes sb_inode_iter_next() return NULL.
>
> Nobody needs that. Just break out of the loop.
>
> > Most callers just want a referenced inode and use no flags at all. Three
> > flags cover the walks that need something else:
> >
> > - %INO_ITER_F_REFERENCED restricts the walk to inodes that still have a
> > reference, preserving the "only handle referenced inodes" rule of
> > landlock's sb-delete walk.
> >
> > - %INO_ITER_F_NOREF hands out only inodes whose reference count has
> > already reached zero, and %INO_ITER_F_NOIGET suppresses the reference.
> > Neither keeps the inode alive, so the caller has to make the inode
> > unclaimable itself.
>
> No flags.
If we do not add flags, we cannot convert the evict_inodes() and hook_sb_delete().
We'd better convert evict_inodes/hook_sb_delete this time, and then
we can add more hooks to super_operations{}, such as sb_add_inode/sb_del_inode/sb_iter_inode.
With these hooks in super_operations, we can add more optimization code for different FSs.
For example:
"vfs: improving inode cache iteration scalability"
https://lore.kernel.org/all/20241002014017.3801899-1-david@fromorbit.com/
and
https://lore.kernel.org/all/20260920072811.2064247-1-huangsj@hygon.cn/
Thanks
Huang Shijie
next prev parent reply other threads:[~2026-11-26 12:15 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 9:11 [PATCH v4 00/11] vfs: add inode iteration methods Huang Shijie
2026-11-25 9:11 ` [PATCH v4 01/11] vfs: add sb_inode_iter_next() Huang Shijie
2026-11-25 9:11 ` [PATCH v4 02/11] vfs: add sb_inode_iter_locked() Huang Shijie
2026-11-25 9:11 ` [PATCH v4 03/11] block: convert nr_blockdev_pages() to sb_inode_iter_locked() Huang Shijie
2026-11-25 9:11 ` [PATCH v4 04/11] fs/quota: convert remove_dquot_ref() " Huang Shijie
2026-11-25 9:11 ` [PATCH v4 05/11] fs: convert generic_shutdown_super() poison loop Huang Shijie
2026-11-25 9:11 ` [PATCH v4 06/11] fs/inode: convert evict_inodes() to sb_inode_iter Huang Shijie
2026-11-25 9:11 ` [PATCH v4 07/11] block: convert sync_bdevs() " Huang Shijie
2026-11-25 9:11 ` [PATCH v4 08/11] fs/drop_caches: convert drop_pagecache_sb() " Huang Shijie
2026-11-25 9:11 ` [PATCH v4 09/11] fs/quota: convert add_dquot_ref() " Huang Shijie
2026-11-25 9:11 ` [PATCH v4 10/11] landlock: convert hook_sb_delete() " Huang Shijie
2026-11-25 9:11 ` [PATCH v4 11/11] gfs2: convert gfs2_evict_inodes() " Huang Shijie
2026-11-25 22:25 ` [PATCH v4 00/11] vfs: add inode iteration methods Andreas Gruenbacher
2026-11-26 12:15 ` Huang Shijie [this message]
2026-11-26 14:32 ` Andreas Gruenbacher
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=awgi6a0Hayug7RJH@hsj-2U-Workstation \
--to=huangsj@hygon.cn \
--cc=agruenba@redhat.com \
--cc=aleksa@amutable.com \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=djwong@kernel.org \
--cc=ebiggers@kernel.org \
--cc=fangbaoshun@hygon.cn \
--cc=gfs2@lists.linux.dev \
--cc=gnoack@google.com \
--cc=hch@infradead.org \
--cc=jack@suse.cz \
--cc=jmorris@namei.org \
--cc=legion@kernel.org \
--cc=libaokun@linux.alibaba.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=mic@digikod.net \
--cc=paul@paul-moore.com \
--cc=sandeen@redhat.com \
--cc=serge@hallyn.com \
--cc=shijie8@gmail.com \
--cc=viro@zeniv.linux.org.uk \
--cc=wujianyong@hygon.cn \
--cc=yingzhiwei@hygon.cn \
--cc=zhongyuan@hygon.cn \
/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