From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexander Aring Date: Mon, 2 May 2022 11:14:09 -0400 Subject: [Cluster-devel] [PATCH dlm/next 2/3] fs: dlm: use kref_put_lock in put_rsb In-Reply-To: <20220502151410.4049410-1-aahringo@redhat.com> References: <20220502151410.4049410-1-aahringo@redhat.com> Message-ID: <20220502151410.4049410-2-aahringo@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit This patch will optimize put_rsb() by using kref_put_lock(). The function kref_put_lock() will only held the lock if the reference is going to be zero, if not the lock will never be hold. Signed-off-by: Alexander Aring --- fs/dlm/lock.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c index 97ca728dc194..a331210434b2 100644 --- a/fs/dlm/lock.c +++ b/fs/dlm/lock.c @@ -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) -- 2.31.1