2014-11-20 05:19:49

by Al Viro

[permalink] [raw]
Subject: gfs2: gfs2_dir_get_hash_table(): avoiding deferred vfree() is easy here...

vfree() is allowed under spinlock these days, but it's cheaper when
it doesn't step into deferred case and here it's very easy to avoid.

Signed-off-by: Al Viro <[email protected]>
---
fs/gfs2/dir.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c
index c247fed..c5a34f0 100644
--- a/fs/gfs2/dir.c
+++ b/fs/gfs2/dir.c
@@ -370,11 +370,12 @@ static __be64 *gfs2_dir_get_hash_table(struct gfs2_inode *ip)
}

spin_lock(&inode->i_lock);
- if (ip->i_hash_cache)
- kvfree(hc);
- else
+ if (likely(!ip->i_hash_cache)) {
ip->i_hash_cache = hc;
+ hc = NULL;
+ }
spin_unlock(&inode->i_lock);
+ kvfree(hc);

return ip->i_hash_cache;
}
--
1.7.10.4


2014-11-20 13:13:07

by Bob Peterson

[permalink] [raw]
Subject: Re: [Cluster-devel] gfs2: gfs2_dir_get_hash_table(): avoiding deferred vfree() is easy here...

----- Original Message -----
> vfree() is allowed under spinlock these days, but it's cheaper when
> it doesn't step into deferred case and here it's very easy to avoid.
>
> Signed-off-by: Al Viro <[email protected]>
> ---
> fs/gfs2/dir.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c
> index c247fed..c5a34f0 100644
> --- a/fs/gfs2/dir.c
> +++ b/fs/gfs2/dir.c
> @@ -370,11 +370,12 @@ static __be64 *gfs2_dir_get_hash_table(struct
> gfs2_inode *ip)
> }
>
> spin_lock(&inode->i_lock);
> - if (ip->i_hash_cache)
> - kvfree(hc);
> - else
> + if (likely(!ip->i_hash_cache)) {
> ip->i_hash_cache = hc;
> + hc = NULL;
> + }
> spin_unlock(&inode->i_lock);
> + kvfree(hc);
>
> return ip->i_hash_cache;
> }
> --
> 1.7.10.4
>
>

ACK

Bob Peterson
Red Hat File Systems

2014-11-20 17:19:24

by Steven Whitehouse

[permalink] [raw]
Subject: Re: [Cluster-devel] gfs2: gfs2_dir_get_hash_table(): avoiding deferred vfree() is easy here...

Hi,

All five patches now in the GFS2 -nmw tree. Thanks,

Steve.

On 20/11/14 05:19, Al Viro wrote:
> vfree() is allowed under spinlock these days, but it's cheaper when
> it doesn't step into deferred case and here it's very easy to avoid.
>
> Signed-off-by: Al Viro <[email protected]>
> ---
> fs/gfs2/dir.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c
> index c247fed..c5a34f0 100644
> --- a/fs/gfs2/dir.c
> +++ b/fs/gfs2/dir.c
> @@ -370,11 +370,12 @@ static __be64 *gfs2_dir_get_hash_table(struct gfs2_inode *ip)
> }
>
> spin_lock(&inode->i_lock);
> - if (ip->i_hash_cache)
> - kvfree(hc);
> - else
> + if (likely(!ip->i_hash_cache)) {
> ip->i_hash_cache = hc;
> + hc = NULL;
> + }
> spin_unlock(&inode->i_lock);
> + kvfree(hc);
>
> return ip->i_hash_cache;
> }