Linux-Fsdevel Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v2] fs: Kill DCACHE_DONTCACHE dentry even if DCACHE_REFERENCED is set
@ 2020-09-24 5:59 Hao Li
2020-09-24 14:58 ` Jan Kara
2020-09-24 15:27 ` Ira Weiny
0 siblings, 2 replies; 5+ messages in thread
From: Hao Li @ 2020-09-24 5:59 UTC (permalink / raw)
To: linux-kernel, linux-fsdevel
Cc: david, ira.weiny, linux-xfs, viro, y-goto, lihao2018.fnst
If DCACHE_REFERENCED is set, fast_dput() will return true, and then
retain_dentry() have no chance to check DCACHE_DONTCACHE. As a result,
the dentry won't be killed and the corresponding inode can't be evicted.
In the following example, the DAX policy can't take effects unless we
do a drop_caches manually.
# DCACHE_LRU_LIST will be set
echo abcdefg > test.txt
# DCACHE_REFERENCED will be set and DCACHE_DONTCACHE can't do anything
xfs_io -c 'chattr +x' test.txt
# Drop caches to make DAX changing take effects
echo 2 > /proc/sys/vm/drop_caches
What this patch does is preventing fast_dput() from returning true if
DCACHE_DONTCACHE is set. Then retain_dentry() will detect the
DCACHE_DONTCACHE and will return false. As a result, the dentry will be
killed and the inode will be evicted. In this way, if we change per-file
DAX policy, it will take effects automatically after this file is closed
by all processes.
I also add some comments to make the code more clear.
Signed-off-by: Hao Li <lihao2018.fnst@cn.fujitsu.com>
---
v1 is split into two standalone patch as discussed in [1], and the first
patch has been reviewed in [2]. This is the second patch.
[1]: https://lore.kernel.org/linux-fsdevel/20200831003407.GE12096@dread.disaster.area/
[2]: https://lore.kernel.org/linux-fsdevel/20200906214002.GI12131@dread.disaster.area/
fs/dcache.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/fs/dcache.c b/fs/dcache.c
index ea0485861d93..97e81a844a96 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -793,10 +793,17 @@ static inline bool fast_dput(struct dentry *dentry)
* a reference to the dentry and change that, but
* our work is done - we can leave the dentry
* around with a zero refcount.
+ *
+ * Nevertheless, there are two cases that we should kill
+ * the dentry anyway.
+ * 1. free disconnected dentries as soon as their refcount
+ * reached zero.
+ * 2. free dentries if they should not be cached.
*/
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))
--
2.28.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] fs: Kill DCACHE_DONTCACHE dentry even if DCACHE_REFERENCED is set
2020-09-24 5:59 [PATCH v2] fs: Kill DCACHE_DONTCACHE dentry even if DCACHE_REFERENCED is set Hao Li
@ 2020-09-24 14:58 ` Jan Kara
2020-10-21 13:51 ` Jan Kara
2020-09-24 15:27 ` Ira Weiny
1 sibling, 1 reply; 5+ messages in thread
From: Jan Kara @ 2020-09-24 14:58 UTC (permalink / raw)
To: Hao Li
Cc: linux-kernel, linux-fsdevel, david, ira.weiny, linux-xfs, viro, y-goto
On Thu 24-09-20 13:59:58, Hao Li wrote:
> If DCACHE_REFERENCED is set, fast_dput() will return true, and then
> retain_dentry() have no chance to check DCACHE_DONTCACHE. As a result,
> the dentry won't be killed and the corresponding inode can't be evicted.
> In the following example, the DAX policy can't take effects unless we
> do a drop_caches manually.
>
> # DCACHE_LRU_LIST will be set
> echo abcdefg > test.txt
>
> # DCACHE_REFERENCED will be set and DCACHE_DONTCACHE can't do anything
> xfs_io -c 'chattr +x' test.txt
>
> # Drop caches to make DAX changing take effects
> echo 2 > /proc/sys/vm/drop_caches
>
> What this patch does is preventing fast_dput() from returning true if
> DCACHE_DONTCACHE is set. Then retain_dentry() will detect the
> DCACHE_DONTCACHE and will return false. As a result, the dentry will be
> killed and the inode will be evicted. In this way, if we change per-file
> DAX policy, it will take effects automatically after this file is closed
> by all processes.
>
> I also add some comments to make the code more clear.
>
> Signed-off-by: Hao Li <lihao2018.fnst@cn.fujitsu.com>
The patch looks good to me. You can add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> v1 is split into two standalone patch as discussed in [1], and the first
> patch has been reviewed in [2]. This is the second patch.
>
> [1]: https://lore.kernel.org/linux-fsdevel/20200831003407.GE12096@dread.disaster.area/
> [2]: https://lore.kernel.org/linux-fsdevel/20200906214002.GI12131@dread.disaster.area/
>
> fs/dcache.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/fs/dcache.c b/fs/dcache.c
> index ea0485861d93..97e81a844a96 100644
> --- a/fs/dcache.c
> +++ b/fs/dcache.c
> @@ -793,10 +793,17 @@ static inline bool fast_dput(struct dentry *dentry)
> * a reference to the dentry and change that, but
> * our work is done - we can leave the dentry
> * around with a zero refcount.
> + *
> + * Nevertheless, there are two cases that we should kill
> + * the dentry anyway.
> + * 1. free disconnected dentries as soon as their refcount
> + * reached zero.
> + * 2. free dentries if they should not be cached.
> */
> 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))
> --
> 2.28.0
>
>
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] fs: Kill DCACHE_DONTCACHE dentry even if DCACHE_REFERENCED is set
2020-09-24 5:59 [PATCH v2] fs: Kill DCACHE_DONTCACHE dentry even if DCACHE_REFERENCED is set Hao Li
2020-09-24 14:58 ` Jan Kara
@ 2020-09-24 15:27 ` Ira Weiny
1 sibling, 0 replies; 5+ messages in thread
From: Ira Weiny @ 2020-09-24 15:27 UTC (permalink / raw)
To: Hao Li; +Cc: linux-kernel, linux-fsdevel, david, linux-xfs, viro, y-goto
On Thu, Sep 24, 2020 at 01:59:58PM +0800, Hao Li wrote:
> If DCACHE_REFERENCED is set, fast_dput() will return true, and then
> retain_dentry() have no chance to check DCACHE_DONTCACHE. As a result,
> the dentry won't be killed and the corresponding inode can't be evicted.
> In the following example, the DAX policy can't take effects unless we
> do a drop_caches manually.
>
> # DCACHE_LRU_LIST will be set
> echo abcdefg > test.txt
>
> # DCACHE_REFERENCED will be set and DCACHE_DONTCACHE can't do anything
> xfs_io -c 'chattr +x' test.txt
>
> # Drop caches to make DAX changing take effects
> echo 2 > /proc/sys/vm/drop_caches
>
> What this patch does is preventing fast_dput() from returning true if
> DCACHE_DONTCACHE is set. Then retain_dentry() will detect the
> DCACHE_DONTCACHE and will return false. As a result, the dentry will be
> killed and the inode will be evicted. In this way, if we change per-file
> DAX policy, it will take effects automatically after this file is closed
> by all processes.
>
> I also add some comments to make the code more clear.
>
> Signed-off-by: Hao Li <lihao2018.fnst@cn.fujitsu.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
> ---
> v1 is split into two standalone patch as discussed in [1], and the first
> patch has been reviewed in [2]. This is the second patch.
>
> [1]: https://lore.kernel.org/linux-fsdevel/20200831003407.GE12096@dread.disaster.area/
> [2]: https://lore.kernel.org/linux-fsdevel/20200906214002.GI12131@dread.disaster.area/
>
> fs/dcache.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/fs/dcache.c b/fs/dcache.c
> index ea0485861d93..97e81a844a96 100644
> --- a/fs/dcache.c
> +++ b/fs/dcache.c
> @@ -793,10 +793,17 @@ static inline bool fast_dput(struct dentry *dentry)
> * a reference to the dentry and change that, but
> * our work is done - we can leave the dentry
> * around with a zero refcount.
> + *
> + * Nevertheless, there are two cases that we should kill
> + * the dentry anyway.
> + * 1. free disconnected dentries as soon as their refcount
> + * reached zero.
> + * 2. free dentries if they should not be cached.
> */
> 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))
> --
> 2.28.0
>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] fs: Kill DCACHE_DONTCACHE dentry even if DCACHE_REFERENCED is set
2020-09-24 14:58 ` Jan Kara
@ 2020-10-21 13:51 ` Jan Kara
2020-11-05 10:54 ` Li, Hao
0 siblings, 1 reply; 5+ messages in thread
From: Jan Kara @ 2020-10-21 13:51 UTC (permalink / raw)
To: Al Viro
Cc: linux-kernel, linux-fsdevel, david, ira.weiny, linux-xfs, viro,
y-goto, Hao Li
Hum, Al, did this patch get lost?
Honza
On Thu 24-09-20 16:58:56, Jan Kara wrote:
> On Thu 24-09-20 13:59:58, Hao Li wrote:
> > If DCACHE_REFERENCED is set, fast_dput() will return true, and then
> > retain_dentry() have no chance to check DCACHE_DONTCACHE. As a result,
> > the dentry won't be killed and the corresponding inode can't be evicted.
> > In the following example, the DAX policy can't take effects unless we
> > do a drop_caches manually.
> >
> > # DCACHE_LRU_LIST will be set
> > echo abcdefg > test.txt
> >
> > # DCACHE_REFERENCED will be set and DCACHE_DONTCACHE can't do anything
> > xfs_io -c 'chattr +x' test.txt
> >
> > # Drop caches to make DAX changing take effects
> > echo 2 > /proc/sys/vm/drop_caches
> >
> > What this patch does is preventing fast_dput() from returning true if
> > DCACHE_DONTCACHE is set. Then retain_dentry() will detect the
> > DCACHE_DONTCACHE and will return false. As a result, the dentry will be
> > killed and the inode will be evicted. In this way, if we change per-file
> > DAX policy, it will take effects automatically after this file is closed
> > by all processes.
> >
> > I also add some comments to make the code more clear.
> >
> > Signed-off-by: Hao Li <lihao2018.fnst@cn.fujitsu.com>
>
> The patch looks good to me. You can add:
>
> Reviewed-by: Jan Kara <jack@suse.cz>
>
> Honza
>
> > ---
> > v1 is split into two standalone patch as discussed in [1], and the first
> > patch has been reviewed in [2]. This is the second patch.
> >
> > [1]: https://lore.kernel.org/linux-fsdevel/20200831003407.GE12096@dread.disaster.area/
> > [2]: https://lore.kernel.org/linux-fsdevel/20200906214002.GI12131@dread.disaster.area/
> >
> > fs/dcache.c | 9 ++++++++-
> > 1 file changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/fs/dcache.c b/fs/dcache.c
> > index ea0485861d93..97e81a844a96 100644
> > --- a/fs/dcache.c
> > +++ b/fs/dcache.c
> > @@ -793,10 +793,17 @@ static inline bool fast_dput(struct dentry *dentry)
> > * a reference to the dentry and change that, but
> > * our work is done - we can leave the dentry
> > * around with a zero refcount.
> > + *
> > + * Nevertheless, there are two cases that we should kill
> > + * the dentry anyway.
> > + * 1. free disconnected dentries as soon as their refcount
> > + * reached zero.
> > + * 2. free dentries if they should not be cached.
> > */
> > 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))
> > --
> > 2.28.0
> >
> >
> >
> --
> Jan Kara <jack@suse.com>
> SUSE Labs, CR
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] fs: Kill DCACHE_DONTCACHE dentry even if DCACHE_REFERENCED is set
2020-10-21 13:51 ` Jan Kara
@ 2020-11-05 10:54 ` Li, Hao
0 siblings, 0 replies; 5+ messages in thread
From: Li, Hao @ 2020-11-05 10:54 UTC (permalink / raw)
To: Jan Kara, Al Viro
Cc: linux-kernel, linux-fsdevel, david, ira.weiny, linux-xfs, y-goto
Ping :)
On 2020/10/21 21:51, Jan Kara wrote:
> Hum, Al, did this patch get lost?
>
> Honza
>
> On Thu 24-09-20 16:58:56, Jan Kara wrote:
>> On Thu 24-09-20 13:59:58, Hao Li wrote:
>>> If DCACHE_REFERENCED is set, fast_dput() will return true, and then
>>> retain_dentry() have no chance to check DCACHE_DONTCACHE. As a result,
>>> the dentry won't be killed and the corresponding inode can't be evicted.
>>> In the following example, the DAX policy can't take effects unless we
>>> do a drop_caches manually.
>>>
>>> # DCACHE_LRU_LIST will be set
>>> echo abcdefg > test.txt
>>>
>>> # DCACHE_REFERENCED will be set and DCACHE_DONTCACHE can't do anything
>>> xfs_io -c 'chattr +x' test.txt
>>>
>>> # Drop caches to make DAX changing take effects
>>> echo 2 > /proc/sys/vm/drop_caches
>>>
>>> What this patch does is preventing fast_dput() from returning true if
>>> DCACHE_DONTCACHE is set. Then retain_dentry() will detect the
>>> DCACHE_DONTCACHE and will return false. As a result, the dentry will be
>>> killed and the inode will be evicted. In this way, if we change per-file
>>> DAX policy, it will take effects automatically after this file is closed
>>> by all processes.
>>>
>>> I also add some comments to make the code more clear.
>>>
>>> Signed-off-by: Hao Li <lihao2018.fnst@cn.fujitsu.com>
>> The patch looks good to me. You can add:
>>
>> Reviewed-by: Jan Kara <jack@suse.cz>
>>
>> Honza
>>
>>> ---
>>> v1 is split into two standalone patch as discussed in [1], and the first
>>> patch has been reviewed in [2]. This is the second patch.
>>>
>>> [1]: https://lore.kernel.org/linux-fsdevel/20200831003407.GE12096@dread.disaster.area/
>>> [2]: https://lore.kernel.org/linux-fsdevel/20200906214002.GI12131@dread.disaster.area/
>>>
>>> fs/dcache.c | 9 ++++++++-
>>> 1 file changed, 8 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/fs/dcache.c b/fs/dcache.c
>>> index ea0485861d93..97e81a844a96 100644
>>> --- a/fs/dcache.c
>>> +++ b/fs/dcache.c
>>> @@ -793,10 +793,17 @@ static inline bool fast_dput(struct dentry *dentry)
>>> * a reference to the dentry and change that, but
>>> * our work is done - we can leave the dentry
>>> * around with a zero refcount.
>>> + *
>>> + * Nevertheless, there are two cases that we should kill
>>> + * the dentry anyway.
>>> + * 1. free disconnected dentries as soon as their refcount
>>> + * reached zero.
>>> + * 2. free dentries if they should not be cached.
>>> */
>>> 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))
>>> --
>>> 2.28.0
>>>
>>>
>>>
>> --
>> Jan Kara <jack@suse.com>
>> SUSE Labs, CR
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-11-05 10:55 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-24 5:59 [PATCH v2] fs: Kill DCACHE_DONTCACHE dentry even if DCACHE_REFERENCED is set Hao Li
2020-09-24 14:58 ` Jan Kara
2020-10-21 13:51 ` Jan Kara
2020-11-05 10:54 ` Li, Hao
2020-09-24 15:27 ` Ira Weiny
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).