lkml.org 
[lkml]   [2012]   [Sep]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/4] fs/inode.c: do not take i_lock in __(insert|remove)_inode_hash
Date
At the beginning of fs/inode.c, the comment suggests both inode_hash_lock and
i_lock protect i_hash. I wonder why two locks are needed.

Grep the source code shows that i_hash is accessed in limited and
well-defined places:

1. In inode_unhashed()
2. In some special cases, as argument to hlist_add_fake()
3. Traverse inode hash list
4. Add/remove inode to/from inode hash list.

Case #1, #2 are not in any locking context. Case #3, #4 will hold
inode_hash_lock. i_hash is not accessed by other ways. This suggests that
inode_hash_lock alone protects i_hash well.

In __(insert|remove)_inode_hash(), our only goal is to manipulate i_hash, do
not take i_lock in these functions.

Signed-off-by: Guo Chao <yan@linux.vnet.ibm.com>
---
fs/inode.c | 4 ----
1 file changed, 4 deletions(-)

diff --git a/fs/inode.c b/fs/inode.c
index d2d15aa..54e4b29 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -463,9 +463,7 @@ void __insert_inode_hash(struct inode *inode, unsigned long hashval)
struct hlist_head *b = inode_hashtable + hash(inode->i_sb, hashval);

spin_lock(&inode_hash_lock);
- spin_lock(&inode->i_lock);
hlist_add_head(&inode->i_hash, b);
- spin_unlock(&inode->i_lock);
spin_unlock(&inode_hash_lock);
}
EXPORT_SYMBOL(__insert_inode_hash);
@@ -479,9 +477,7 @@ EXPORT_SYMBOL(__insert_inode_hash);
void __remove_inode_hash(struct inode *inode)
{
spin_lock(&inode_hash_lock);
- spin_lock(&inode->i_lock);
hlist_del_init(&inode->i_hash);
- spin_unlock(&inode->i_lock);
spin_unlock(&inode_hash_lock);
}
EXPORT_SYMBOL(__remove_inode_hash);
--
1.7.9.5


\
 
 \ /
  Last update: 2012-09-21 12:21    [W:0.093 / U:0.552 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site