Re: [PATCH v6 2/2] fuse: add new function to invalidate cache for all inodes

From: Miklos Szeredi
Date: Tue Feb 18 2025 - 04:18:51 EST


On Mon, 17 Feb 2025 at 14:32, Luis Henriques <luis@xxxxxxxxxx> wrote:
>
> Currently userspace is able to notify the kernel to invalidate the cache
> for an inode. This means that, if all the inodes in a filesystem need to
> be invalidated, then userspace needs to iterate through all of them and do
> this kernel notification separately.
>
> This patch adds a new option that allows userspace to invalidate all the
> inodes with a single notification operation. In addition to invalidate
> all the inodes, it also shrinks the sb dcache.

What is your use case for dropping all inodes?

There's a reason for doing cache shrinking that I know of, and that's
about resources held by the fuse server (e.g. open files) for each
cached inode. In that case what's really needed is something that
tells the fuse client (the kernel or in case of virtiofs, the guest
kernel) to get rid of the N least recently used inodes.


> Signed-off-by: Luis Henriques <luis@xxxxxxxxxx>
> ---
> fs/fuse/inode.c | 34 ++++++++++++++++++++++++++++++++++
> include/uapi/linux/fuse.h | 3 +++
> 2 files changed, 37 insertions(+)
>
> diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
> index e9db2cb8c150..64fa0806e97d 100644
> --- a/fs/fuse/inode.c
> +++ b/fs/fuse/inode.c
> @@ -547,6 +547,37 @@ struct inode *fuse_ilookup(struct fuse_conn *fc, u64 nodeid,
> return NULL;
> }
>
> +static int fuse_reverse_inval_all(struct fuse_conn *fc)
> +{
> + struct fuse_mount *fm;
> + struct inode *inode;
> +
> + inode = fuse_ilookup(fc, FUSE_ROOT_ID, &fm);
> + if (!inode || !fm)
> + return -ENOENT;
> + iput(inode);
> +
> + /* Remove all possible active references to cached inodes */
> + shrink_dcache_sb(fm->sb);
> +
> + /* Remove all unreferenced inodes from cache */
> + invalidate_inodes(fm->sb);

After a dcache shrink, this is unnecessary. See " .drop_inode =
generic_delete_inode," in fs/fuse/inode.c

Thanks,
Miklos