Re: [PATCH] fs: rotate inodes whose page cache could not be dropped
From: Jan Kara
Date: Mon Oct 19 2026 - 07:09:27 EST
On Fri 16-10-26 10:25:15, Nikolaos Karaolidis wrote:
> When inode_lru_isolate() drops the page cache of an unused inode, it
> has to unlock the list, so it returns LRU_RETRY and the walk restarts
> at the head of the list, where the inode still is. If
> invalidate_mapping_pages() could not empty the mapping, the restarted
> walk strips the same inode again, and so on until nr_to_walk runs out.
> Every walk of that list then ends on this inode, and nothing behind it
> is reclaimed for as long as its cache stays.
>
> Before commit 2a0629834cd8 ("vfs: Don't evict inode under the inode lru
> traversing context") the walker pinned the inode with a reference, and
> dropping it in iput_final() set I_REFERENCED, so the restarted walk
> rotated the inode to the tail. Set I_REFERENCED again when the mapping
> is still populated after the invalidation, in the same i_lock section
> that clears I_LRU_ISOLATING. inode_unpin_lru_isolating() now expects
> i_lock to be held, like inode_pin_lru_isolating().
>
> On CONFIG_HIGHMEM kernels this can happen to any unused inode: a folio
> is left behind if it is locked, under writeback, spliced into a pipe,
> or still in another CPU's LRU-add batch after being read. Without
> HIGHMEM it happens to DAX inodes whose only entry is at index 0, which
> mapping_shrinkable() lets onto the LRU and invalidate_mapping_pages()
> never removes.
>
> Fixes: 2a0629834cd8 ("vfs: Don't evict inode under the inode lru traversing context")
> Cc: stable@xxxxxxxxxxxxxxx
> Assisted-by: LLM
> Signed-off-by: Nikolaos Karaolidis <nick@xxxxxxxxxxxxxx>
Looks sensible. Feel free to add:
Reviewed-by: Jan Kara <jack@xxxxxxx>
Honza
> diff --git a/fs/inode.c b/fs/inode.c
> index a9d37be390a1..1614a97ce953 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
> @@ -593,12 +593,11 @@ static void inode_pin_lru_isolating(struct inode *inode)
>
> static void inode_unpin_lru_isolating(struct inode *inode)
> {
> - spin_lock(&inode->i_lock);
> + lockdep_assert_held(&inode->i_lock);
> WARN_ON(!(inode_state_read(inode) & I_LRU_ISOLATING));
> inode_state_clear(inode, I_LRU_ISOLATING);
> /* Called with inode->i_lock which ensures memory ordering. */
> inode_wake_up_bit(inode, __I_LRU_ISOLATING);
> - spin_unlock(&inode->i_lock);
> }
>
> static void inode_wait_for_lru_isolating(struct inode *inode)
> @@ -981,7 +980,13 @@ static enum lru_status inode_lru_isolate(struct list_head *item,
> else
> __count_vm_events(PGINODESTEAL, reap);
> mm_account_reclaimed_pages(reap);
> +
> + spin_lock(&inode->i_lock);
> + /* The walk restarts here: don't retry leftovers right away */
> + if (!mapping_empty(&inode->i_data))
> + inode_state_set(inode, I_REFERENCED);
> inode_unpin_lru_isolating(inode);
> + spin_unlock(&inode->i_lock);
> return LRU_RETRY;
> }
>
>
> base-commit: af32da41b0327b9c6a37856ba82b6760d6c8d10e
> --
> 2.55.0
>
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR