[PATCH v5 08/10] fs/drop_caches: convert drop_pagecache_sb() to for_each_inode()
From: Huang Shijie
Date: Tue Dec 01 2026 - 01:48:15 EST
Convert drop_pagecache_sb() to for_each_inode().
No functional change.
Signed-off-by: Huang Shijie <huangsj@xxxxxxxx>
---
fs/drop_caches.c | 31 +++++++------------------------
1 file changed, 7 insertions(+), 24 deletions(-)
diff --git a/fs/drop_caches.c b/fs/drop_caches.c
index 28c5fb9c7357..6967813a42ed 100644
--- a/fs/drop_caches.c
+++ b/fs/drop_caches.c
@@ -16,43 +16,26 @@
/* A global variable is a bit ugly, but it keeps the code simple */
static int sysctl_drop_caches;
static void drop_pagecache_sb(struct super_block *sb, void *unused)
{
- struct inode *inode, *toput_inode = NULL;
+ struct inode *inode;
if (sb->s_bdi == &noop_backing_dev_info)
return;
- spin_lock(&sb->s_inode_list_lock);
- list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
- spin_lock(&inode->i_lock);
- /*
- * We must skip inodes in unusual state. We may also skip
- * inodes without pages but we deliberately won't in case
- * we need to reschedule to avoid softlockups.
- */
- if ((inode_state_read(inode) & (I_FREEING | I_WILL_FREE | I_NEW)) ||
- (mapping_empty(inode->i_mapping) && !need_resched())) {
- spin_unlock(&inode->i_lock);
- continue;
- }
- __iget(inode);
- spin_unlock(&inode->i_lock);
- spin_unlock(&sb->s_inode_list_lock);
-
+ /*
+ * We may skip inodes without pages but we deliberately won't in
+ * case we need to reschedule to avoid softlockups.
+ */
+ for_each_inode(inode, sb,
+ !mapping_empty(inode->i_mapping) || need_resched()) {
invalidate_mapping_pages(inode->i_mapping, 0, -1);
- iput(toput_inode);
- toput_inode = inode;
-
cond_resched();
- spin_lock(&sb->s_inode_list_lock);
}
- spin_unlock(&sb->s_inode_list_lock);
- iput(toput_inode);
}
static int drop_caches_sysctl_handler(const struct ctl_table *table, int write,
void *buffer, size_t *length, loff_t *ppos)
{
int ret;
--
2.34.1