From patchwork Thu Aug 2 13:32:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 10553641 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A6CB713BB for ; Thu, 2 Aug 2018 13:32:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 986AD20182 for ; Thu, 2 Aug 2018 13:32:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8AC8E205F7; Thu, 2 Aug 2018 13:32:48 +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 1574320182 for ; Thu, 2 Aug 2018 13:32:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387470AbeHBPYA (ORCPT ); Thu, 2 Aug 2018 11:24:00 -0400 Received: from mout.gmx.net ([212.227.15.19]:51235 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387438AbeHBPYA (ORCPT ); Thu, 2 Aug 2018 11:24:00 -0400 Received: from localhost.localdomain ([113.116.49.58]) by mail.gmx.com (mrgmx002 [212.227.17.184]) with ESMTPSA (Nemesis) id 0McEkx-1fTxPz0jR9-00JbLp; Thu, 02 Aug 2018 15:32:40 +0200 From: Chengguang Xu To: ceph-devel@vger.kernel.org Cc: zyan@redhat.com, idryomov@gmail.com, Chengguang Xu Subject: [PATCH v2 1/2] ceph: introudce a variable to avoid calling atomic_read() twice Date: Thu, 2 Aug 2018 21:32:21 +0800 Message-Id: <20180802133222.3692-1-cgxu519@gmx.com> X-Mailer: git-send-email 2.17.1 X-Provags-ID: V03:K1:ShdeP5hyWvQI9VHdhrc4Hv9ZEjfq/C7TyUD/WAFM63a0x2JJr5a oezdzrpWdmlNFUtsrKSraXDlJsxYNyUOkyvaj+CX8IfiCYg46WNsR2l1hSJxYKz7pisLZTM U7TMvqBrsMTaZFCslBBA0nbmbEq11RcHKYwNqb2/anlnc7thzhObt8zzKNS8zV0uJD+yh3i FPv5NuehOF9X+JLn5Y7IA== X-UI-Out-Filterresults: notjunk:1;V01:K0:2AqKttqX47s=:Ni0NPTGiIgDpj/OtGWGhn9 6WjsND5V8Wh+kOw5u9Tor173o1RsLhDWTZzCXlyXRNe2AkrUPecUiffWV7Ox6bfR/sErgY2TQ 6vlBC9UnRIukZJExA8vDqNumdzdg8IXGSXSKv/bJWuY8lZtr6Nh4VvJ57GVOoAknRkUGIlp4I BsXzdFfbILNbLs/WlR9nZd8TZeSv8UKX2cy/HtuLSLL0TOKXMCXKYXBd3HNo0qi/RIIXbJzSN oB+NxUCuUIMw6frgw7JS/CG/lPCxQKhcAsEtOcxo9mzklJw5TD1o1PC9ray/WOJ+j+p/OMCn3 a7o/4+p3mxXWhdxB2rBqsFXH/qkWtE9buOT7YyaXn9mgFAYEwF9096I4bWIOyrOHt74KYIjB6 vjX9nuNWlYJI9f+Kstxz07+gfsRYx8dhjsbb0/EdctVLgi92hCP6QpmPBnWN0J8QIMAbrwe8F ldRp1RYl6DH+yyDydRssj4nccMu2BMTicmovJKepkZBIneFokRTbRzqBRzO82ARsJLukpo6Yv whtVNPyXkaUqTyMmthTvFGxYkLXGnwrNeBO82g0E8W03bHWwPpnWjyYlA7TKurMXRDXwDsE6i CFz5lrcpFFu3T/0jVLvZxQTfeRevKHirEDBA2ecm5Rxwz3UsV7+RCtJMp6JxethilYFB7XvO7 lKNN0aFjpod6s2FuGbea3KluSJ7dY9U58IW+VJBS3ATbq1PvUq3t7/zmVmGOUSysqAApS64jz pbNSpD1uLUsCWT3BK5QRTGhZk2nylNrfhtu7QN41poccC8CuHFQwksdEl/c= 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 atomic_read() twice in a debug message may return different value each time, so introduce a variable to avoid it. Signed-off-by: Chengguang Xu --- v1->v2: - Keep atomic_t type as it is and only fix the problem of calling atomic_read() twice in a debug message. fs/ceph/snap.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c index 01b0144c0b73..4f8228e58d73 100644 --- a/fs/ceph/snap.c +++ b/fs/ceph/snap.c @@ -63,8 +63,8 @@ void ceph_get_snap_realm(struct ceph_mds_client *mdsc, struct ceph_snap_realm *realm) { - dout("get_realm %p %d -> %d\n", realm, - atomic_read(&realm->nref), atomic_read(&realm->nref)+1); + int nref = atomic_read(&realm->nref); + dout("get_realm %p %d -> %d\n", realm, nref, nref + 1); /* * since we _only_ increment realm refs or empty the empty * list with snap_rwsem held, adjusting the empty list here is @@ -193,8 +193,9 @@ static void __destroy_snap_realm(struct ceph_mds_client *mdsc, static void __put_snap_realm(struct ceph_mds_client *mdsc, struct ceph_snap_realm *realm) { + int nref = atomic_read(&realm->nref); dout("__put_snap_realm %llx %p %d -> %d\n", realm->ino, realm, - atomic_read(&realm->nref), atomic_read(&realm->nref)-1); + nref, nref - 1); if (atomic_dec_and_test(&realm->nref)) __destroy_snap_realm(mdsc, realm); } @@ -205,8 +206,9 @@ static void __put_snap_realm(struct ceph_mds_client *mdsc, void ceph_put_snap_realm(struct ceph_mds_client *mdsc, struct ceph_snap_realm *realm) { + int nref = atomic_read(&realm->nref); dout("put_snap_realm %llx %p %d -> %d\n", realm->ino, realm, - atomic_read(&realm->nref), atomic_read(&realm->nref)-1); + nref, nref - 1); if (!atomic_dec_and_test(&realm->nref)) return; From patchwork Thu Aug 2 13:32:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 10553643 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1777C15A6 for ; Thu, 2 Aug 2018 13:32:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08A4A20182 for ; Thu, 2 Aug 2018 13:32:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F13E7205F7; Thu, 2 Aug 2018 13:32:54 +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 9715720182 for ; Thu, 2 Aug 2018 13:32:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387499AbeHBPYH (ORCPT ); Thu, 2 Aug 2018 11:24:07 -0400 Received: from mout.gmx.net ([212.227.15.15]:36323 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387438AbeHBPYH (ORCPT ); Thu, 2 Aug 2018 11:24:07 -0400 Received: from localhost.localdomain ([113.116.49.58]) by mail.gmx.com (mrgmx002 [212.227.17.184]) with ESMTPSA (Nemesis) id 0MQzIE-1fNg0m0mi6-00ULng; Thu, 02 Aug 2018 15:32:47 +0200 From: Chengguang Xu To: ceph-devel@vger.kernel.org Cc: zyan@redhat.com, idryomov@gmail.com, Chengguang Xu Subject: [PATCH v2 2/2] libceph: introudce a variable to avoid calling refcount_read() twice Date: Thu, 2 Aug 2018 21:32:22 +0800 Message-Id: <20180802133222.3692-2-cgxu519@gmx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180802133222.3692-1-cgxu519@gmx.com> References: <20180802133222.3692-1-cgxu519@gmx.com> X-Provags-ID: V03:K1:Ia1TyXHyz55tyYJkQklUlp0/M6KdCUmjNoQX9JRFVRvpYO6MDXr 1ULuGOUp9tCb+Py9O0adZ12A5kkX9e/2p00cZvLfiNOf8TWL8AhkCiJ/Hrc0VyAASR10Y4L zxCpqgTr7wiDk15NROIJVv7doxvluPPVbkJi3PFdw3sd3t3zrx+Be1ehSdjhPkAvXiM/fkJ XJ7PvfG5rBNL7e1SevKhw== X-UI-Out-Filterresults: notjunk:1;V01:K0:QdzAjpH19xE=:8t5OvU+3Ir8ZjdScks/r3D ZSPLE5if2Jf1/OP8YldEtku3t4Hsajgoy4PH5hihUAV5+/kQOexjfZUNsP8WDAlGF3ibxAXr/ oc2/uWUCJcmpo8fhRLt8a8BuU5YlxioVO2+1oTslV0YfY6sRj3pwWpQBBS4FiSuV1Ebr6hjSR cVlye0i9i3OgiQXNtzMTDi6z/oUrE545PZSwSLdK458kiNHaasGYdv/Ui4RshmVh3aBomGxj+ y9lm8eNuqmnc/7rBzDhUMxUIATiqUDf8EU1cJpC6sxl9IMi4qeYr16zqAHaP2DX/CPXU0506Z +FhC9wSiPF7qngWQG9bwlHFIXzUQs66iCVjCvkqVXSJ1NxePP1GK38qzNjWx3IkMpglnE8WmS OPvMtszXXwISOKstsFYunDVQaXBO4bN2DE7llxMBIxmGElDAbM8LOaGPN2RCdZimTiYoZ8dT+ ms8yz54jkwsZvugShIZ6Vs83H6hhHFqxB4uWtMwhzaOwZACaz2JEyhe7pRPBFpdZ5CFLZUKtL aLlc1bPC2WFFte5taWuDs3j7YZYo6LVoHMR/GP483GhHOYA8p5wJCXeedm2e9kH7+QkMCtutl CJsnPW6TxXLJOC9LgEmPAMjCaNq95KMNaa4fPuygY3E0PNuhgMqX1VqkvVcwGR3AoeorndWO+ tK/CAG5VSibtu2VNpyDHe0qu5nIxLYitnPdpv7hSfb5iTc0YldTMCJ1gqySgp+0KrVzg+hqnq BT++tlEEYU2Uj2LFLnmHbiw3pmghHH0Hfs1GyNY/IHfYe7EixFbYI0fa/IE= 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 in a debug message may return different value each time, so introduce a variable to avoid it. Signed-off-by: Chengguang Xu --- net/ceph/osd_client.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c index 8002b8e9ce24..ee8eb99a06ae 100644 --- a/net/ceph/osd_client.c +++ b/net/ceph/osd_client.c @@ -1155,8 +1155,8 @@ static struct ceph_osd *create_osd(struct ceph_osd_client *osdc, int onum) static struct ceph_osd *get_osd(struct ceph_osd *osd) { if (refcount_inc_not_zero(&osd->o_ref)) { - dout("get_osd %p %d -> %d\n", osd, refcount_read(&osd->o_ref)-1, - refcount_read(&osd->o_ref)); + unsigned int refcnt = refcount_read(&osd->o_ref); + dout("get_osd %p %d -> %d\n", osd, refcnt - 1, refcnt); return osd; } else { dout("get_osd %p FAIL\n", osd); @@ -1166,8 +1166,8 @@ static struct ceph_osd *get_osd(struct ceph_osd *osd) static void put_osd(struct ceph_osd *osd) { - dout("put_osd %p %d -> %d\n", osd, refcount_read(&osd->o_ref), - refcount_read(&osd->o_ref) - 1); + unsigned int refcnt = refcount_read(&osd->o_ref); + dout("put_osd %p %d -> %d\n", osd, refcnt, refcnt - 1); if (refcount_dec_and_test(&osd->o_ref)) { osd_cleanup(osd); kfree(osd);