Commit 1db97eaa authored by Trond Myklebust's avatar Trond Myklebust

NFS: Convert lookups of the lock context to RCU

Speed up lookups of an existing lock context by avoiding the inode->i_lock,
and using RCU instead.
Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
parent 28ced9a8
...@@ -857,15 +857,14 @@ static void nfs_init_lock_context(struct nfs_lock_context *l_ctx) ...@@ -857,15 +857,14 @@ static void nfs_init_lock_context(struct nfs_lock_context *l_ctx)
static struct nfs_lock_context *__nfs_find_lock_context(struct nfs_open_context *ctx) static struct nfs_lock_context *__nfs_find_lock_context(struct nfs_open_context *ctx)
{ {
struct nfs_lock_context *head = &ctx->lock_context; struct nfs_lock_context *pos;
struct nfs_lock_context *pos = head;
do { list_for_each_entry_rcu(pos, &ctx->lock_context.list, list) {
if (pos->lockowner != current->files) if (pos->lockowner != current->files)
continue; continue;
refcount_inc(&pos->count); if (refcount_inc_not_zero(&pos->count))
return pos; return pos;
} while ((pos = list_entry(pos->list.next, typeof(*pos), list)) != head); }
return NULL; return NULL;
} }
...@@ -874,10 +873,10 @@ struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx) ...@@ -874,10 +873,10 @@ struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx)
struct nfs_lock_context *res, *new = NULL; struct nfs_lock_context *res, *new = NULL;
struct inode *inode = d_inode(ctx->dentry); struct inode *inode = d_inode(ctx->dentry);
spin_lock(&inode->i_lock); rcu_read_lock();
res = __nfs_find_lock_context(ctx); res = __nfs_find_lock_context(ctx);
rcu_read_unlock();
if (res == NULL) { if (res == NULL) {
spin_unlock(&inode->i_lock);
new = kmalloc(sizeof(*new), GFP_KERNEL); new = kmalloc(sizeof(*new), GFP_KERNEL);
if (new == NULL) if (new == NULL)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
...@@ -885,14 +884,14 @@ struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx) ...@@ -885,14 +884,14 @@ struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx)
spin_lock(&inode->i_lock); spin_lock(&inode->i_lock);
res = __nfs_find_lock_context(ctx); res = __nfs_find_lock_context(ctx);
if (res == NULL) { if (res == NULL) {
list_add_tail(&new->list, &ctx->lock_context.list); list_add_tail_rcu(&new->list, &ctx->lock_context.list);
new->open_context = ctx; new->open_context = ctx;
res = new; res = new;
new = NULL; new = NULL;
} }
spin_unlock(&inode->i_lock);
kfree(new);
} }
spin_unlock(&inode->i_lock);
kfree(new);
return res; return res;
} }
EXPORT_SYMBOL_GPL(nfs_get_lock_context); EXPORT_SYMBOL_GPL(nfs_get_lock_context);
...@@ -904,9 +903,9 @@ void nfs_put_lock_context(struct nfs_lock_context *l_ctx) ...@@ -904,9 +903,9 @@ void nfs_put_lock_context(struct nfs_lock_context *l_ctx)
if (!refcount_dec_and_lock(&l_ctx->count, &inode->i_lock)) if (!refcount_dec_and_lock(&l_ctx->count, &inode->i_lock))
return; return;
list_del(&l_ctx->list); list_del_rcu(&l_ctx->list);
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
kfree(l_ctx); kfree_rcu(l_ctx, rcu_head);
} }
EXPORT_SYMBOL_GPL(nfs_put_lock_context); EXPORT_SYMBOL_GPL(nfs_put_lock_context);
......
...@@ -62,6 +62,7 @@ struct nfs_lock_context { ...@@ -62,6 +62,7 @@ struct nfs_lock_context {
struct nfs_open_context *open_context; struct nfs_open_context *open_context;
fl_owner_t lockowner; fl_owner_t lockowner;
atomic_t io_count; atomic_t io_count;
struct rcu_head rcu_head;
}; };
struct nfs4_state; struct nfs4_state;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment