Skip to contentSkip to conversation

gfs2: gfs2_dir_get_hash_table(): avoiding deferred vfree() is easy here...

PATCH Al Viro 3 participants 3 messages Nov 20, 2014 GFS2 file system

lore
Share & tools
lore

Al Viro

author
#0 lore raw

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.

---
 fs/gfs2/dir.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fs/gfs2/dir.c +4 -3
index c247fed..c5a34f0 100644
@@ -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;
 }
Signature · 1 line
1.7.10.4
#1 lore raw

----- Original Message -----

Quoted 28 lines

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.

---
 fs/gfs2/dir.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fs/gfs2/dir.c +4 -3
index c247fed..c5a34f0 100644
@@ -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;
Quoted 5 lines

}
--
1.7.10.4

ACK

Bob Peterson
Red Hat File Systems

#2 lore raw
In reply to Al Viro

Hi,

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

Steve.

Quoted 28 lines · Al Viro

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.

---
  fs/gfs2/dir.c |    7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
fs/gfs2/dir.c +4 -3
index c247fed..c5a34f0 100644
@@ -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;
  }