2020-08-31 10:14:18

by Hao Li

[permalink] [raw]
Subject: [PATCH] fs: Handle I_DONTCACHE in iput_final() instead of generic_drop_inode()

If generic_drop_inode() returns true, it means iput_final() can evict
this inode regardless of whether it is dirty or not. If we check
I_DONTCACHE in generic_drop_inode(), any inode with this bit set will be
evicted unconditionally. This is not the desired behavior because
I_DONTCACHE only means the inode shouldn't be cached on the LRU list.
As for whether we need to evict this inode, this is what
generic_drop_inode() should do. This patch corrects the usage of
I_DONTCACHE.

This patch was proposed in [1].

[1]: https://lore.kernel.org/linux-fsdevel/[email protected]/

Signed-off-by: Hao Li <[email protected]>
---
fs/inode.c | 3 ++-
include/linux/fs.h | 3 +--
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/inode.c b/fs/inode.c
index 72c4c347afb7..4e45d5ea3d0f 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1625,7 +1625,8 @@ static void iput_final(struct inode *inode)
else
drop = generic_drop_inode(inode);

- if (!drop && (sb->s_flags & SB_ACTIVE)) {
+ if (!drop && !(inode->i_state & I_DONTCACHE) &&
+ (sb->s_flags & SB_ACTIVE)) {
inode_add_lru(inode);
spin_unlock(&inode->i_lock);
return;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index e019ea2f1347..93caee80ce47 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2922,8 +2922,7 @@ extern int inode_needs_sync(struct inode *inode);
extern int generic_delete_inode(struct inode *inode);
static inline int generic_drop_inode(struct inode *inode)
{
- return !inode->i_nlink || inode_unhashed(inode) ||
- (inode->i_state & I_DONTCACHE);
+ return !inode->i_nlink || inode_unhashed(inode);
}
extern void d_mark_dontcache(struct inode *inode);

--
2.28.0




2020-08-31 17:16:55

by Ira Weiny

[permalink] [raw]
Subject: Re: [PATCH] fs: Handle I_DONTCACHE in iput_final() instead of generic_drop_inode()

On Mon, Aug 31, 2020 at 06:13:13PM +0800, Hao Li wrote:
> If generic_drop_inode() returns true, it means iput_final() can evict
> this inode regardless of whether it is dirty or not. If we check
> I_DONTCACHE in generic_drop_inode(), any inode with this bit set will be
> evicted unconditionally. This is not the desired behavior because
> I_DONTCACHE only means the inode shouldn't be cached on the LRU list.
> As for whether we need to evict this inode, this is what
> generic_drop_inode() should do. This patch corrects the usage of
> I_DONTCACHE.
>
> This patch was proposed in [1].
>
> [1]: https://lore.kernel.org/linux-fsdevel/[email protected]/
>
> Signed-off-by: Hao Li <[email protected]>

Thanks! I think this looks good, but shouldn't we add? It seems like this is
a bug right?

Fixes: dae2f8ed7992 ("fs: Lift XFS_IDONTCACHE to the VFS layer")

Reviewed-by: Ira Weiny <[email protected]>

> ---
> fs/inode.c | 3 ++-
> include/linux/fs.h | 3 +--
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/fs/inode.c b/fs/inode.c
> index 72c4c347afb7..4e45d5ea3d0f 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
> @@ -1625,7 +1625,8 @@ static void iput_final(struct inode *inode)
> else
> drop = generic_drop_inode(inode);
>
> - if (!drop && (sb->s_flags & SB_ACTIVE)) {
> + if (!drop && !(inode->i_state & I_DONTCACHE) &&
> + (sb->s_flags & SB_ACTIVE)) {
> inode_add_lru(inode);
> spin_unlock(&inode->i_lock);
> return;
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index e019ea2f1347..93caee80ce47 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -2922,8 +2922,7 @@ extern int inode_needs_sync(struct inode *inode);
> extern int generic_delete_inode(struct inode *inode);
> static inline int generic_drop_inode(struct inode *inode)
> {
> - return !inode->i_nlink || inode_unhashed(inode) ||
> - (inode->i_state & I_DONTCACHE);
> + return !inode->i_nlink || inode_unhashed(inode);
> }
> extern void d_mark_dontcache(struct inode *inode);
>
> --
> 2.28.0
>
>
>

2020-09-01 03:49:46

by Hao Li

[permalink] [raw]
Subject: Re: [PATCH] fs: Handle I_DONTCACHE in iput_final() instead of generic_drop_inode()

On 2020/9/1 1:12, Ira Weiny wrote:
> On Mon, Aug 31, 2020 at 06:13:13PM +0800, Hao Li wrote:
>> If generic_drop_inode() returns true, it means iput_final() can evict
>> this inode regardless of whether it is dirty or not. If we check
>> I_DONTCACHE in generic_drop_inode(), any inode with this bit set will be
>> evicted unconditionally. This is not the desired behavior because
>> I_DONTCACHE only means the inode shouldn't be cached on the LRU list.
>> As for whether we need to evict this inode, this is what
>> generic_drop_inode() should do. This patch corrects the usage of
>> I_DONTCACHE.
>>
>> This patch was proposed in [1].
>>
>> [1]: https://lore.kernel.org/linux-fsdevel/[email protected]/
>>
>> Signed-off-by: Hao Li <[email protected]>
>
> Thanks!  I think this looks good, but shouldn't we add?  It seems like this is
> a bug right?
>
> Fixes: dae2f8ed7992 ("fs: Lift XFS_IDONTCACHE to the VFS layer")

Yeah, this is more meaningful.

I'm not sure if I need to submit a v2 patch, or this tag will be added
by the maintainer when applying this patch. I have no experience with
this before. Thanks!

Regards,
Hao Li

>
>
> Reviewed-by: Ira Weiny <[email protected]>
>
>> ---
>>  fs/inode.c         | 3 ++-
>>  include/linux/fs.h | 3 +--
>>  2 files changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/fs/inode.c b/fs/inode.c
>> index 72c4c347afb7..4e45d5ea3d0f 100644
>> --- a/fs/inode.c
>> +++ b/fs/inode.c
>> @@ -1625,7 +1625,8 @@ static void iput_final(struct inode *inode)
>>      else
>>          drop = generic_drop_inode(inode);
>>  
>> -    if (!drop && (sb->s_flags & SB_ACTIVE)) {
>> +    if (!drop && !(inode->i_state & I_DONTCACHE) &&
>> +            (sb->s_flags & SB_ACTIVE)) {
>>          inode_add_lru(inode);
>>          spin_unlock(&inode->i_lock);
>>          return;
>> diff --git a/include/linux/fs.h b/include/linux/fs.h
>> index e019ea2f1347..93caee80ce47 100644
>> --- a/include/linux/fs.h
>> +++ b/include/linux/fs.h
>> @@ -2922,8 +2922,7 @@ extern int inode_needs_sync(struct inode *inode);
>>  extern int generic_delete_inode(struct inode *inode);
>>  static inline int generic_drop_inode(struct inode *inode)
>>  {
>> -    return !inode->i_nlink || inode_unhashed(inode) ||
>> -        (inode->i_state & I_DONTCACHE);
>> +    return !inode->i_nlink || inode_unhashed(inode);
>>  }
>>  extern void d_mark_dontcache(struct inode *inode);
>>  
>> --
>> 2.28.0
>>
>>
>>
>
>



2020-09-03 22:01:41

by Dave Chinner

[permalink] [raw]
Subject: Re: [PATCH] fs: Handle I_DONTCACHE in iput_final() instead of generic_drop_inode()

On Mon, Aug 31, 2020 at 06:13:13PM +0800, Hao Li wrote:
> If generic_drop_inode() returns true, it means iput_final() can evict
> this inode regardless of whether it is dirty or not. If we check
> I_DONTCACHE in generic_drop_inode(), any inode with this bit set will be
> evicted unconditionally. This is not the desired behavior because
> I_DONTCACHE only means the inode shouldn't be cached on the LRU list.
> As for whether we need to evict this inode, this is what
> generic_drop_inode() should do. This patch corrects the usage of
> I_DONTCACHE.
>
> This patch was proposed in [1].
>
> [1]: https://lore.kernel.org/linux-fsdevel/[email protected]/
>
> Signed-off-by: Hao Li <[email protected]>
> ---
> fs/inode.c | 3 ++-
> include/linux/fs.h | 3 +--
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/fs/inode.c b/fs/inode.c
> index 72c4c347afb7..4e45d5ea3d0f 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
> @@ -1625,7 +1625,8 @@ static void iput_final(struct inode *inode)
> else
> drop = generic_drop_inode(inode);
>
> - if (!drop && (sb->s_flags & SB_ACTIVE)) {
> + if (!drop && !(inode->i_state & I_DONTCACHE) &&
> + (sb->s_flags & SB_ACTIVE)) {

FWIW, the format used in fs/inode.c is to align the logic
statements, not tab indent the additional lines in the statement.
i.e.

if (!drop &&
!(inode->i_state & I_DONTCACHE) &&
(sb->s_flags & SB_ACTIVE)) {

Which gives a clear indication that there are all at the same
precedence and separate logic statements...

Otherwise the change looks good.

Probably best to resend with the fixes tag :)

Cheers,

Dave.
--
Dave Chinner
[email protected]

2020-09-04 07:19:37

by Hao Li

[permalink] [raw]
Subject: Re: [PATCH] fs: Handle I_DONTCACHE in iput_final() instead of generic_drop_inode()

On 2020/9/4 5:58, Dave Chinner wrote:
> On Mon, Aug 31, 2020 at 06:13:13PM +0800, Hao Li wrote:
>> If generic_drop_inode() returns true, it means iput_final() can evict
>> this inode regardless of whether it is dirty or not. If we check
>> I_DONTCACHE in generic_drop_inode(), any inode with this bit set will be
>> evicted unconditionally. This is not the desired behavior because
>> I_DONTCACHE only means the inode shouldn't be cached on the LRU list.
>> As for whether we need to evict this inode, this is what
>> generic_drop_inode() should do. This patch corrects the usage of
>> I_DONTCACHE.
>>
>> This patch was proposed in [1].
>>
>> [1]: https://lore.kernel.org/linux-fsdevel/[email protected]/
>>
>> Signed-off-by: Hao Li <[email protected]>
>> ---
>>  fs/inode.c         | 3 ++-
>>  include/linux/fs.h | 3 +--
>>  2 files changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/fs/inode.c b/fs/inode.c
>> index 72c4c347afb7..4e45d5ea3d0f 100644
>> --- a/fs/inode.c
>> +++ b/fs/inode.c
>> @@ -1625,7 +1625,8 @@ static void iput_final(struct inode *inode)
>>      else
>>          drop = generic_drop_inode(inode);
>>  
>> -    if (!drop && (sb->s_flags & SB_ACTIVE)) {
>> +    if (!drop && !(inode->i_state & I_DONTCACHE) &&
>> +            (sb->s_flags & SB_ACTIVE)) {
>
> FWIW, the format used in fs/inode.c is to align the logic
> statements, not tab indent the additional lines in the statement.
> i.e.
>
>     if (!drop &&
>         !(inode->i_state & I_DONTCACHE) &&
>         (sb->s_flags & SB_ACTIVE)) {
>
> Which gives a clear indication that there are all at the same
> precedence and separate logic statements...
>
> Otherwise the change looks good.
>
> Probably best to resend with the fixes tag :)

Got it! Thanks.

>
>
> Cheers,
>
> Dave.