Re: [PATCH] fs: Kill DCACHE_DONTCACHE dentry even if DCACHE_REFERENCED is set

From: Ira Weiny
Date: Fri Aug 21 2020 - 13:40:50 EST


On Fri, Aug 21, 2020 at 09:59:53AM +0800, Hao Li wrote:
> Currently, DCACHE_REFERENCED prevents the dentry with DCACHE_DONTCACHE
> set from being killed, so the corresponding inode can't be evicted. If
> the DAX policy of an inode is changed, we can't make policy changing
> take effects unless dropping caches manually.
>
> This patch fixes this problem and flushes the inode to disk to prepare
> for evicting it.

This looks intriguing and I really hope this helps but I don't think this will
guarantee that the state changes immediately will it?

Do you have a test case which fails before and passes after? Perhaps one of
the new xfstests submitted by Xiao?

Ira

>
> Signed-off-by: Hao Li <lihao2018.fnst@xxxxxxxxxxxxxx>
> ---
> fs/dcache.c | 3 ++-
> fs/inode.c | 2 +-
> 2 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/fs/dcache.c b/fs/dcache.c
> index ea0485861d93..486c7409dc82 100644
> --- a/fs/dcache.c
> +++ b/fs/dcache.c
> @@ -796,7 +796,8 @@ static inline bool fast_dput(struct dentry *dentry)
> */
> smp_rmb();
> d_flags = READ_ONCE(dentry->d_flags);
> - d_flags &= DCACHE_REFERENCED | DCACHE_LRU_LIST | DCACHE_DISCONNECTED;
> + d_flags &= DCACHE_REFERENCED | DCACHE_LRU_LIST | DCACHE_DISCONNECTED
> + | DCACHE_DONTCACHE;
>
> /* Nothing to do? Dropping the reference was all we needed? */
> if (d_flags == (DCACHE_REFERENCED | DCACHE_LRU_LIST) && !d_unhashed(dentry))
> diff --git a/fs/inode.c b/fs/inode.c
> index 72c4c347afb7..5218a8aebd7f 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
> @@ -1632,7 +1632,7 @@ static void iput_final(struct inode *inode)
> }
>
> state = inode->i_state;
> - if (!drop) {
> + if (!drop || (drop && (inode->i_state & I_DONTCACHE))) {
> WRITE_ONCE(inode->i_state, state | I_WILL_FREE);
> spin_unlock(&inode->i_lock);
>
> --
> 2.28.0
>
>
>