Skip to content

Commit 9ae075f

Browse files
author
Trond Myklebust
committed
NFSv4: Convert open state lookup to use RCU
Further reduce contention on the inode->i_lock. Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
1 parent 0de4397 commit 9ae075f

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

fs/nfs/nfs4_fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ struct nfs4_state {
191191
atomic_t count;
192192

193193
wait_queue_head_t waitq;
194+
struct rcu_head rcu_head;
194195
};
195196

196197

fs/nfs/nfs4state.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ __nfs4_find_state_byowner(struct inode *inode, struct nfs4_state_owner *owner)
684684
struct nfs_inode *nfsi = NFS_I(inode);
685685
struct nfs4_state *state;
686686

687-
list_for_each_entry(state, &nfsi->open_states, inode_states) {
687+
list_for_each_entry_rcu(state, &nfsi->open_states, inode_states) {
688688
if (state->owner != owner)
689689
continue;
690690
if (!nfs4_valid_open_stateid(state))
@@ -698,7 +698,7 @@ __nfs4_find_state_byowner(struct inode *inode, struct nfs4_state_owner *owner)
698698
static void
699699
nfs4_free_open_state(struct nfs4_state *state)
700700
{
701-
kfree(state);
701+
kfree_rcu(state, rcu_head);
702702
}
703703

704704
struct nfs4_state *
@@ -707,9 +707,9 @@ nfs4_get_open_state(struct inode *inode, struct nfs4_state_owner *owner)
707707
struct nfs4_state *state, *new;
708708
struct nfs_inode *nfsi = NFS_I(inode);
709709

710-
spin_lock(&inode->i_lock);
710+
rcu_read_lock();
711711
state = __nfs4_find_state_byowner(inode, owner);
712-
spin_unlock(&inode->i_lock);
712+
rcu_read_unlock();
713713
if (state)
714714
goto out;
715715
new = nfs4_alloc_open_state();
@@ -720,7 +720,7 @@ nfs4_get_open_state(struct inode *inode, struct nfs4_state_owner *owner)
720720
state = new;
721721
state->owner = owner;
722722
atomic_inc(&owner->so_count);
723-
list_add(&state->inode_states, &nfsi->open_states);
723+
list_add_rcu(&state->inode_states, &nfsi->open_states);
724724
ihold(inode);
725725
state->inode = inode;
726726
spin_unlock(&inode->i_lock);
@@ -746,7 +746,7 @@ void nfs4_put_open_state(struct nfs4_state *state)
746746
if (!atomic_dec_and_lock(&state->count, &owner->so_lock))
747747
return;
748748
spin_lock(&inode->i_lock);
749-
list_del(&state->inode_states);
749+
list_del_rcu(&state->inode_states);
750750
list_del(&state->open_states);
751751
spin_unlock(&inode->i_lock);
752752
spin_unlock(&owner->so_lock);

0 commit comments

Comments
 (0)