From: Huang Shijie <huangsj@hygon.cn>
To: Jan Kara <jack@suse.cz>
Cc: <axboe@kernel.dk>, <viro@zeniv.linux.org.uk>,
<brauner@kernel.org>, <zhongyuan@hygon.cn>,
<fangbaoshun@hygon.cn>, <yingzhiwei@hygon.cn>,
<agruenba@redhat.com>, <mic@digikod.net>, <gnoack@google.com>,
<paul@paul-moore.com>, <jmorris@namei.org>, <serge@hallyn.com>,
<aleksa@amutable.com>, <legion@kernel.org>, <david@kernel.org>,
<sandeen@redhat.com>, <ebiggers@kernel.org>,
<linux-block@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-fsdevel@vger.kernel.org>, <gfs2@lists.linux.dev>,
<linux-security-module@vger.kernel.org>,
<sunjunchao@bytedance.com>
Subject: Re: [PATCH 1/3] vfs: add inode iteration method super_iter_inodes
Date: Tue, 10 Nov 2026 10:38:14 +0800 [thread overview]
Message-ID: <avKDlkJG0Rj872Cd@hsj-2U-Workstation> (raw)
In-Reply-To: <symrqnxn6tkrahynz7rm5b7n3tolkifpbubmwfd3y6q4q2xnt2@vhh7plsok3kh>
在 Mon, Nov 09, 2026 at 11:43:19AM +0100,Jan Kara 写道:
> On Thu 15-10-26 17:38:52, Huang Shijie wrote:
> > +static bool super_iter_iget(struct inode *inode, int flags)
> > +{
> > + bool ret = false;
> > +
>
> Here I'd do a lockless icount_read_once(inode) check if INO_ITER_F_REFERENCED
> is set to avoid unnecessary i_lock round trip.
okay. I will add icount_read_once() in later version.
>
> > + spin_lock(&inode->i_lock);
> > + if (inode_state_read(inode) & (I_NEW | I_FREEING | I_WILL_FREE))
> > + goto out_unlock;
> > +
> > + if ((flags & INO_ITER_F_REFERENCED) && !icount_read(inode))
> > + goto out_unlock;
> > +
> > + __iget(inode);
> > + ret = true;
> > +out_unlock:
> > + spin_unlock(&inode->i_lock);
> > + return ret;
> > +}
> > +
> > +static int generic_iter_inodes(struct super_block *sb, ino_iter_fn iter_fn,
> > + void *private_data, int flags)
> > +{
> > + struct inode *inode, *old_inode = NULL;
> > + int ret = INO_ITER_RET_DONE;
> > +
> > + spin_lock(&sb->s_inode_list_lock);
> > + list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
> > + if (!super_iter_iget(inode, flags))
> > + continue;
> > +
> > + spin_unlock(&sb->s_inode_list_lock);
> > + iput(old_inode);
> > +
> > + ret = iter_fn(inode, private_data);
> > +
> > + old_inode = inode;
> > + if (ret == INO_ITER_RET_ABORT) {
> > + ret = INO_ITER_RET_DONE;
> > + goto out_loop;
> > + }
> > + if (ret < 0)
> > + goto out_loop;
> > +
> > + cond_resched();
> > + spin_lock(&sb->s_inode_list_lock);
> > + }
> > + spin_unlock(&sb->s_inode_list_lock);
> > +out_loop:
> > + iput(old_inode);
> > + return ret;
> > +}
> > +
> > +/*
> > + * Unsafe iteration for internal VFS use only: @iter_fn runs in atomic
> > + * context with only an inode existence guarantee, so it must not block
> > + * and must perform its own inode state checks. Return INO_ITER_RET_ABORT
> > + * to stop the iteration early.
> > + */
> > +static int generic_iter_inodes_unsafe(struct super_block *sb, ino_iter_fn iter_fn,
> > + void *private_data)
> > +{
> > + struct inode *inode;
> > + int ret = INO_ITER_RET_DONE;
> > +
> > + rcu_read_lock();
> > + spin_lock(&sb->s_inode_list_lock);
> > + list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
> > + ret = iter_fn(inode, private_data);
>
> After some thought, I'd probably make this function inline in some VFS
> internal header. That way the compiler can inline everything and avoid the
No problem.
I will try to convert it to inline function later.
> extra costs of indirect function calls, etc. These iterators tend to be
> rather lightweight so it would avoid performance regressions from the
> conversion.
>
> I was considering the same for the generic iterator as well but there I
> don't have so strong opinion as the function is already relatively big and
> the callbacks are usually more heavy. Might still be worth some more
> detailed investigation and performance measurements...
Yes.
This function is already big enough.
Let's keep it as it is.
Thanks
Huang Shijie
next prev parent reply other threads:[~2026-11-10 2:38 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 9:38 [PATCH 0/3] " Huang Shijie
2026-10-15 9:38 ` [PATCH 1/3] " Huang Shijie
2026-10-15 15:23 ` Stephen Smalley
2026-10-16 2:45 ` Huang Shijie
2026-11-09 9:58 ` Jan Kara
2026-11-10 2:32 ` Huang Shijie
2026-11-09 10:43 ` Jan Kara
2026-11-10 2:38 ` Huang Shijie [this message]
2026-10-15 9:38 ` [PATCH 2/3] vfs: convert inode iterators to the unsafe super_iter_inodes() Huang Shijie
2026-11-09 10:08 ` Jan Kara
2026-10-15 9:38 ` [PATCH 3/3] vfs: convert sb->s_inodes iteration to super_iter_inodes() Huang Shijie
2026-11-09 10:31 ` Jan Kara
2026-10-21 10:58 ` [PATCH 0/3] vfs: add inode iteration method super_iter_inodes Christian Brauner
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=avKDlkJG0Rj872Cd@hsj-2U-Workstation \
--to=huangsj@hygon.cn \
--cc=agruenba@redhat.com \
--cc=aleksa@amutable.com \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=david@kernel.org \
--cc=ebiggers@kernel.org \
--cc=fangbaoshun@hygon.cn \
--cc=gfs2@lists.linux.dev \
--cc=gnoack@google.com \
--cc=jack@suse.cz \
--cc=jmorris@namei.org \
--cc=legion@kernel.org \
--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=sunjunchao@bytedance.com \
--cc=viro@zeniv.linux.org.uk \
--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
all inboxes | Powered by JetHome®