Linux block layer
 help / color / mirror / Atom feed
From: Huang Shijie <huangsj@hygon.cn>
To: Christian Brauner <brauner@kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>, <axboe@kernel.dk>,
	<viro@zeniv.linux.org.uk>, <jack@suse.cz>, <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>, <shijie8@gmail.com>
Subject: Re: [PATCH v2 1/3] vfs: add inode iteration methods
Date: Fri, 20 Nov 2026 19:43:01 +0800	[thread overview]
Message-ID: <awAyRVD3URaBPhw7@hsj-2U-Workstation> (raw)
In-Reply-To: <20261120-mitverantwortlich-drehbaren-kantholz-241300d20168@brauner>

在 Fri, Nov 20, 2026 at 12:14:24PM +0100,Christian Brauner 写道:
> On Mon, Nov 16, 2026 at 02:45:44PM +0800, Huang Shijie wrote:
> > > 	struct inode_iter_contex ctx = INODE_ITER_CTX_INIT;
> > > 
> > > 	while ((inode = sb_inode_iter()))) {
> > > 		/* do stuff */
> > > 	}
> > > 
> > How to manage the sb->s_inode_list_lock in this code?
> > 
> > I have no idea how to hide the sb->s_inode_list_lock in this code.
> 
> I think Christoph is right. The lock shouldn't be held across
> iterations. Let the iterator take it, grab a reference to the next
> inode, drop the lock again and hand the inode out. The reference keeps the
okay. 

If we can accept this method, I can change the code following it in future.

> inode on s_inodes so the next call can continue from there.
> 
> This is how drop_pagecache_sb() does it today. Sm like (UNTESTED and not
> nice-ified):
> 
> struct sb_inode_iter {
> 	struct super_block *sb;
> 	struct inode *inode;
> 	bool done;
> };
> 
> struct inode *sb_inode_iter_next(struct sb_inode_iter *it)
> {
> 	struct super_block *sb = it->sb;
> 	struct inode *prev = it->inode, *inode;
> 
> 	if (it->done)
> 		return NULL;
> 
> 	spin_lock(&sb->s_inode_list_lock);
> 	inode = list_prepare_entry(prev, &sb->s_inodes, i_sb_list);
> 	list_for_each_entry_continue(inode, &sb->s_inodes, i_sb_list) {
> 		spin_lock(&inode->i_lock);
> 		if (inode_state_read(inode) & (I_FREEING | I_WILL_FREE | I_NEW)) {
> 			spin_unlock(&inode->i_lock);
> 			continue;
> 		}
> 		__iget(inode);
> 		spin_unlock(&inode->i_lock);
> 		spin_unlock(&sb->s_inode_list_lock);
> 		it->inode = inode;
> 		iput(prev);
> 		return inode;
> 	}
> 	spin_unlock(&sb->s_inode_list_lock);
> 	it->inode = NULL;
> 	it->done = true;
> 	iput(prev);
> 	return NULL;
> }
> 
> void sb_inode_iter_end(struct sb_inode_iter *it)
> {
> 	iput(it->inode);
> 	it->inode = NULL;
> 	it->done = true;
> }
> 
> and then drop_pagecache_sb() becomes:
> 
> 	struct sb_inode_iter it = { .sb = sb };
> 	struct inode *inode;
> 
> 	while ((inode = sb_inode_iter_next(&it))) {
> 		invalidate_mapping_pages(inode->i_mapping, 0, -1);
> 		cond_resched();
> 	}
> 
> Make it a cleanup class and a caller that breaks out early doesn't have
> to remember sb_inode_iter_end() either.
> 
> This will end because new inodes are added at the head and the cursor
> stays on the list. So these assumptions should get
> VFS_WARN_ON_ONCE()-es.
> 
> Walkers that can't take a reference might need different solution.
> I'm not sure if there are any?
I will think about it.

Thanks
Huang Shijie


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

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13 11:56 [PATCH v2 0/3] vfs: add inode iteration methods Huang Shijie
2026-11-13 11:57 ` [PATCH v2 1/3] " Huang Shijie
2026-11-13 12:23   ` Christoph Hellwig
2026-11-16  6:45     ` Huang Shijie
2026-11-20 11:14       ` Christian Brauner
2026-11-20 11:43         ` Huang Shijie [this message]
2026-11-13 11:57 ` [PATCH v2 2/3] vfs: convert inode iterators to super_iter_inodes_unsafe() Huang Shijie
2026-11-13 11:57 ` [PATCH v2 3/3] vfs: convert sb->s_inodes iteration to super_iter_inodes() Huang Shijie

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=awAyRVD3URaBPhw7@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=hch@infradead.org \
    --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=shijie8@gmail.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