nfsd: optimize destroy_lockowner cl_lock thrashing

Reduce the cl_lock trashing in destroy_lockowner. Unhash all of the
lockstateids on the lockowner's list. Put the reference under the lock
and see if it was the last one. If so, then add it to a private list
to be destroyed after we drop the lock.

Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
This commit is contained in:
Jeff Layton 2014-07-29 21:34:39 -04:00 committed by J. Bruce Fields
parent a819ecc1bb
commit 3c1c995cc2
1 changed files with 37 additions and 20 deletions

View File

@ -983,14 +983,23 @@ static void nfs4_free_lock_stateid(struct nfs4_stid *stid)
nfs4_free_ol_stateid(stid); nfs4_free_ol_stateid(stid);
} }
static void unhash_lock_stateid(struct nfs4_ol_stateid *stp)
{
struct nfs4_openowner *oo = openowner(stp->st_openstp->st_stateowner);
lockdep_assert_held(&oo->oo_owner.so_client->cl_lock);
list_del_init(&stp->st_locks);
unhash_generic_stateid(stp);
unhash_stid(&stp->st_stid);
}
static void release_lock_stateid(struct nfs4_ol_stateid *stp) static void release_lock_stateid(struct nfs4_ol_stateid *stp)
{ {
struct nfs4_openowner *oo = openowner(stp->st_openstp->st_stateowner); struct nfs4_openowner *oo = openowner(stp->st_openstp->st_stateowner);
spin_lock(&oo->oo_owner.so_client->cl_lock); spin_lock(&oo->oo_owner.so_client->cl_lock);
list_del(&stp->st_locks); unhash_lock_stateid(stp);
unhash_generic_stateid(stp);
unhash_stid(&stp->st_stid);
spin_unlock(&oo->oo_owner.so_client->cl_lock); spin_unlock(&oo->oo_owner.so_client->cl_lock);
nfs4_put_stid(&stp->st_stid); nfs4_put_stid(&stp->st_stid);
} }
@ -1004,30 +1013,38 @@ static void unhash_lockowner_locked(struct nfs4_lockowner *lo)
list_del_init(&lo->lo_owner.so_strhash); list_del_init(&lo->lo_owner.so_strhash);
} }
static void release_lockowner_stateids(struct nfs4_lockowner *lo)
{
struct nfs4_client *clp = lo->lo_owner.so_client;
struct nfs4_ol_stateid *stp;
lockdep_assert_held(&clp->cl_lock);
while (!list_empty(&lo->lo_owner.so_stateids)) {
stp = list_first_entry(&lo->lo_owner.so_stateids,
struct nfs4_ol_stateid, st_perstateowner);
spin_unlock(&clp->cl_lock);
release_lock_stateid(stp);
spin_lock(&clp->cl_lock);
}
}
static void release_lockowner(struct nfs4_lockowner *lo) static void release_lockowner(struct nfs4_lockowner *lo)
{ {
struct nfs4_client *clp = lo->lo_owner.so_client; struct nfs4_client *clp = lo->lo_owner.so_client;
struct nfs4_ol_stateid *stp;
struct list_head reaplist;
INIT_LIST_HEAD(&reaplist);
spin_lock(&clp->cl_lock); spin_lock(&clp->cl_lock);
unhash_lockowner_locked(lo); unhash_lockowner_locked(lo);
release_lockowner_stateids(lo); while (!list_empty(&lo->lo_owner.so_stateids)) {
stp = list_first_entry(&lo->lo_owner.so_stateids,
struct nfs4_ol_stateid, st_perstateowner);
unhash_lock_stateid(stp);
/*
* We now know that no new references can be added to the
* stateid. If ours is the last one, finish the unhashing
* and put it on the list to be reaped.
*/
if (atomic_dec_and_test(&stp->st_stid.sc_count)) {
idr_remove(&clp->cl_stateids,
stp->st_stid.sc_stateid.si_opaque.so_id);
list_add(&stp->st_locks, &reaplist);
}
}
spin_unlock(&clp->cl_lock); spin_unlock(&clp->cl_lock);
while (!list_empty(&reaplist)) {
stp = list_first_entry(&reaplist, struct nfs4_ol_stateid,
st_locks);
list_del(&stp->st_locks);
stp->st_stid.sc_free(&stp->st_stid);
}
nfs4_put_stateowner(&lo->lo_owner); nfs4_put_stateowner(&lo->lo_owner);
} }