[patch 24/35] fs: icache use RCU to avoid locking in hash lookups

From: npiggin
Date: Tue Oct 19 2010 - 00:01:34 EST


Signed-off-by: Nick Piggin <npiggin@xxxxxxxxx>

---
fs/inode.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)

Index: linux-2.6/fs/inode.c
===================================================================
--- linux-2.6.orig/fs/inode.c 2010-10-19 14:18:59.000000000 +1100
+++ linux-2.6/fs/inode.c 2010-10-19 14:19:22.000000000 +1100
@@ -646,27 +646,27 @@
struct inode *inode = NULL;

repeat:
- spin_lock_bucket(b);
- hlist_bl_for_each_entry(inode, node, &b->head, i_hash) {
+ rcu_read_lock();
+ hlist_bl_for_each_entry_rcu(inode, node, &b->head, i_hash) {
if (inode->i_sb != sb)
continue;
- if (!spin_trylock(&inode->i_lock)) {
- spin_unlock_bucket(b);
- cpu_relax();
- goto repeat;
+ spin_lock(&inode->i_lock);
+ if (hlist_bl_unhashed(&inode->i_hash)) {
+ spin_unlock(&inode->i_lock);
+ continue;
}
if (!test(inode, data)) {
spin_unlock(&inode->i_lock);
continue;
}
if (inode->i_state & (I_FREEING|I_WILL_FREE)) {
- spin_unlock_bucket(b);
+ rcu_read_unlock();
__wait_on_freeing_inode(inode);
goto repeat;
}
break;
}
- spin_unlock_bucket(b);
+ rcu_read_unlock();
return node ? inode : NULL;
}

@@ -682,25 +682,25 @@
struct inode *inode = NULL;

repeat:
- spin_lock_bucket(b);
- hlist_bl_for_each_entry(inode, node, &b->head, i_hash) {
+ rcu_read_lock();
+ hlist_bl_for_each_entry_rcu(inode, node, &b->head, i_hash) {
if (inode->i_ino != ino)
continue;
if (inode->i_sb != sb)
continue;
- if (!spin_trylock(&inode->i_lock)) {
- spin_unlock_bucket(b);
- cpu_relax();
- goto repeat;
+ spin_lock(&inode->i_lock);
+ if (hlist_bl_unhashed(&inode->i_hash)) {
+ spin_unlock(&inode->i_lock);
+ continue;
}
if (inode->i_state & (I_FREEING|I_WILL_FREE)) {
- spin_unlock_bucket(b);
+ rcu_read_unlock();
__wait_on_freeing_inode(inode);
goto repeat;
}
break;
}
- spin_unlock_bucket(b);
+ rcu_read_unlock();
return node ? inode : NULL;
}



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/