[PATCH 1/3] vfs: introduce shrink_icache_sb() helper

Ye Bin posted 3 patches 1 month, 2 weeks ago
[PATCH 1/3] vfs: introduce shrink_icache_sb() helper
Posted by Ye Bin 1 month, 2 weeks ago
From: Ye Bin <yebin10@huawei.com>

This patch is prepare for support drop_caches for specify file system.
shrink_icache_sb() helper walk the superblock inode LRU for freeable inodes
and attempt to free them.

Signed-off-by: Ye Bin <yebin10@huawei.com>
---
 fs/inode.c    | 17 +++++++++++++++++
 fs/internal.h |  1 +
 2 files changed, 18 insertions(+)

diff --git a/fs/inode.c b/fs/inode.c
index 1939f711d2c9..2129b48571b4 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1045,6 +1045,23 @@ long prune_icache_sb(struct super_block *sb, struct shrink_control *sc)
 	return freed;
 }
 
+/*
+ * Walk the superblock inode LRU for freeable inodes and attempt to free them.
+ * Inodes to be freed are moved to a temporary list and then are freed outside
+ * inode_lock by dispose_list().
+ */
+void shrink_icache_sb(struct super_block *sb)
+{
+	do {
+		LIST_HEAD(dispose);
+
+		list_lru_walk(&sb->s_inode_lru, inode_lru_isolate,
+			      &dispose, 1024);
+		dispose_list(&dispose);
+	} while (list_lru_count(&sb->s_inode_lru) > 0);
+}
+EXPORT_SYMBOL(shrink_icache_sb);
+
 static void __wait_on_freeing_inode(struct inode *inode, bool is_inode_hash_locked);
 /*
  * Called with the inode lock held.
diff --git a/fs/internal.h b/fs/internal.h
index 81c7a085355c..cee79141e308 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -199,6 +199,7 @@ extern int vfs_open(const struct path *, struct file *);
  * inode.c
  */
 extern long prune_icache_sb(struct super_block *sb, struct shrink_control *sc);
+extern void shrink_icache_sb(struct super_block *sb);
 int dentry_needs_remove_privs(struct mnt_idmap *, struct dentry *dentry);
 bool in_group_or_capable(struct mnt_idmap *idmap,
 			 const struct inode *inode, vfsgid_t vfsgid);
-- 
2.31.1
Re: [PATCH 1/3] vfs: introduce shrink_icache_sb() helper
Posted by Jan Kara 1 month, 2 weeks ago
On Thu 10-10-24 19:25:41, Ye Bin wrote:
> From: Ye Bin <yebin10@huawei.com>
> 
> This patch is prepare for support drop_caches for specify file system.
> shrink_icache_sb() helper walk the superblock inode LRU for freeable inodes
> and attempt to free them.
> 
> Signed-off-by: Ye Bin <yebin10@huawei.com>
> ---
>  fs/inode.c    | 17 +++++++++++++++++
>  fs/internal.h |  1 +
>  2 files changed, 18 insertions(+)
> 
> diff --git a/fs/inode.c b/fs/inode.c
> index 1939f711d2c9..2129b48571b4 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
> @@ -1045,6 +1045,23 @@ long prune_icache_sb(struct super_block *sb, struct shrink_control *sc)
>  	return freed;
>  }
>  
> +/*
> + * Walk the superblock inode LRU for freeable inodes and attempt to free them.
> + * Inodes to be freed are moved to a temporary list and then are freed outside
> + * inode_lock by dispose_list().
> + */
> +void shrink_icache_sb(struct super_block *sb)
> +{
> +	do {
> +		LIST_HEAD(dispose);
> +
> +		list_lru_walk(&sb->s_inode_lru, inode_lru_isolate,
> +			      &dispose, 1024);
> +		dispose_list(&dispose);
> +	} while (list_lru_count(&sb->s_inode_lru) > 0);
> +}
> +EXPORT_SYMBOL(shrink_icache_sb);

Hum, but this will livelock if we cannot remove all the inodes? Now I guess
inode_lru_isolate() usually removes busy inodes from the LRU so this should
not happen in practice but such behavior is not guaranteed (we can LRU_SKIP
inodes if i_lock is busy or LRU_RETRY if inode has page cache pages). So I
think we need some safety net here...

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR