From patchwork Thu Jul 12 08:45:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 10521339 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3EBBB601C2 for ; Thu, 12 Jul 2018 08:45:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20B9629427 for ; Thu, 12 Jul 2018 08:45:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 148C3294E3; Thu, 12 Jul 2018 08:45:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3F6E29427 for ; Thu, 12 Jul 2018 08:45:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732497AbeGLIyd (ORCPT ); Thu, 12 Jul 2018 04:54:33 -0400 Received: from mout.gmx.net ([212.227.17.21]:59287 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727447AbeGLIyd (ORCPT ); Thu, 12 Jul 2018 04:54:33 -0400 Received: from x201.localdomain ([117.136.31.239]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0MYtId-1fYOhY2Xzv-00VkNh; Thu, 12 Jul 2018 10:45:52 +0200 From: Chengguang Xu To: ceph-devel@vger.kernel.org Cc: zyan@redhat.com, idryomov@gmail.com, Chengguang Xu Subject: [Resend PATCH 1/2] ceph: introudce a variable to avoid calling refcount_read() twice Date: Thu, 12 Jul 2018 16:45:07 +0800 Message-Id: <20180712084508.24131-1-cgxu519@gmx.com> X-Mailer: git-send-email 2.17.1 X-Provags-ID: V03:K1:BwD3DRjOBK+mxcBl2NK35tJLdSzWbE9W8a0Bl+5OPZtN9vNeM9e pR0PXNsd396/rHkYfZD5RrrmaWjSWpKj93JXiwnGv4KZy29bYNlYiHIJfT9V9+mYbbSMzsH r6oJeU/p6r03O8P3cJe7dx25s7KKiX0K1Dz02ati6A2SBMfdEacjCG1u98kilUXEwxaAV2A 3pBG2t+zv6gJ1HwuR9mmA== X-UI-Out-Filterresults: notjunk:1; V01:K0:ZjTsnl3K3PE=:+ApO0Hc+3zhM6x0983tslj aL5RSdiEjSbUgythdO6TlqO172+iy1Mpw/QtPJyf+5InWjYKXuG7zEjeJ1ebCU2B8TaFL17rU SOQNNdmzsHd8p1FE2M66cmd0fidR9KFrJRjxLMuIwDmD6KC2KhR0hHH6X2yxuldbeI8HW4tTE foydrEhQJt/UIbc6WFV7pgQLeDvvkJ45pxCLMOU/xKGxnP8geyMix2pP7c0QeJiAnnH1kT1Jj U9nMUKFov6BlxPlwbD2jOPVkiyWRiXKpM8QGBdg/z1UUC3yu13px1ZWEQldytNmEKkz99lW7G SZlUI/Z3cuAfqd/NH7dgoaORx5Zgl9i5hb92JkbyYrqiAwmfnscGhbjeYFsXO1zKCgPLDBXPP 6ik8ldmnGEMxu21iZbGH/kbzSuaGwDi/f1usHDuasyJ5p7JV9IZq+JIVtUHRSlTXt+70/DctT XGEh7ygc1B+U9PTJ4DQHQQnD5yyUUK/AHAIwRK6+yC19cV5B8uHvm+xQQK9y/Ws5CWCGo3/ra dWlTcazWKtnZY4v6Ozr0PS1oMJE2TOzLdWkD6JCuXAEP5Q6PzeIqTJkcrYD5lXq2UzGPJLaGH dGMuptsh52pCGW7Ew7CVlHqc/a19+nFw3gzi+RfJVvn06peaa7baJlTGbAJNRHOeqaL/CkMiw YwuANl1mYVMYRiA1/AwgifWsGCG5WDB96fJ2tb73eTMeIMY/XwzT+zYDcUOPH+sGN4Lia8RRj CwjXhxPqa9iyGfJsiQMKq/WQ9tZM3O/ngKFI2hGy90rXe7LAYGnTtXbN2Ms= Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Calling refcount_read() twice may return different value each time, so introduce a variable to avoid it. Signed-off-by: Chengguang Xu --- Sorry, I just wrote wrong email address in previous sending, so resend it. If you have received previous email please ignore it, thanks. fs/ceph/mds_client.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index df0a3bb0f6a5..2a8d4cc69eb6 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c @@ -399,9 +399,10 @@ const char *ceph_session_state_name(int s) static struct ceph_mds_session *get_session(struct ceph_mds_session *s) { + unsigned int refcnt = refcount_read(&s->s_ref); + if (refcount_inc_not_zero(&s->s_ref)) { - dout("mdsc get_session %p %d -> %d\n", s, - refcount_read(&s->s_ref)-1, refcount_read(&s->s_ref)); + dout("mdsc get_session %p %d -> %d\n", s, refcnt - 1, refcnt); return s; } else { dout("mdsc get_session %p 0 -- FAIL\n", s); @@ -411,8 +412,9 @@ static struct ceph_mds_session *get_session(struct ceph_mds_session *s) void ceph_put_mds_session(struct ceph_mds_session *s) { - dout("mdsc put_session %p %d -> %d\n", s, - refcount_read(&s->s_ref), refcount_read(&s->s_ref)-1); + unsigned int refcnt = refcount_read(&s->s_ref); + + dout("mdsc put_session %p %d -> %d\n", s, refcnt, refcnt - 1); if (refcount_dec_and_test(&s->s_ref)) { if (s->s_auth.authorizer) ceph_auth_destroy_authorizer(s->s_auth.authorizer);