dlm: use kref_put_lock in put_rsb
authorAlexander Aring <aahringo@redhat.com>
Mon, 2 May 2022 15:14:09 +0000 (11:14 -0400)
committerDavid Teigland <teigland@redhat.com>
Mon, 2 May 2022 16:22:56 +0000 (11:22 -0500)
This patch will optimize put_rsb() by using kref_put_lock(). The
function kref_put_lock() will only take the lock if the reference is
going to be zero, if not the lock will never be held.

Signed-off-by: Alexander Aring <aahringo@redhat.com>
Signed-off-by: David Teigland <teigland@redhat.com>
fs/dlm/lock.c

index 97ca728dc1941a3ba8581c963ec47c25b88cf53b..a331210434b2b48b812024991ff13008f2ded666 100644 (file)
@@ -350,10 +350,12 @@ static void put_rsb(struct dlm_rsb *r)
 {
        struct dlm_ls *ls = r->res_ls;
        uint32_t bucket = r->res_bucket;
+       int rv;
 
-       spin_lock(&ls->ls_rsbtbl[bucket].lock);
-       kref_put(&r->res_ref, toss_rsb);
-       spin_unlock(&ls->ls_rsbtbl[bucket].lock);
+       rv = kref_put_lock(&r->res_ref, toss_rsb,
+                          &ls->ls_rsbtbl[bucket].lock);
+       if (rv)
+               spin_unlock(&ls->ls_rsbtbl[bucket].lock);
 }
 
 void dlm_put_rsb(struct dlm_rsb *r)