From patchwork Wed Jul 19 22:09:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 9853261 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 873A1602BD for ; Wed, 19 Jul 2017 22:10:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7935228700 for ; Wed, 19 Jul 2017 22:10:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E5A328717; Wed, 19 Jul 2017 22:10:07 +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=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 2410D28700 for ; Wed, 19 Jul 2017 22:10:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753354AbdGSWKF (ORCPT ); Wed, 19 Jul 2017 18:10:05 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:33078 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753904AbdGSWKE (ORCPT ); Wed, 19 Jul 2017 18:10:04 -0400 Received: by mail-io0-f196.google.com with SMTP id n64so823950ioo.0 for ; Wed, 19 Jul 2017 15:10:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=+5nD9Aea5VFQPcRhrkYIxJt3O15jD8g1xmVcdqNwkxw=; b=NcxsXA47WpIOqeJUtSuGv0I8xt3I0dpQ3DtrrEwbhF1HrmSVHJfm4aTTbCLd+bWFew ZtSBl9vt95aCW7T2uWttbtYoQOzGxA/Ohm5pEqdnJ/QGlJCisaZj7p8VAcWJmWEAr/H6 FwzCERtpJnfAoI01qXlroSrf4PnllhkriXCfK4eN71ZA0mJ71KzTAntHw1uNtHlO+1H0 qDhaSlv5MUXTQFXDICbpOpSSwuIidCm+b5R/FQrTULv3GLK+FhsAKrY2Ke7Ui3O9w8mP /DQ1CSrrPjHxHmJKEYvc0OYuvTztve57Pn59us2jrxyIE+sU56QHzalm+Iw+ygGZhiRI +AOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=+5nD9Aea5VFQPcRhrkYIxJt3O15jD8g1xmVcdqNwkxw=; b=OfEOwdF5XUYjPEJSGIpzZSNfWGGqSX8BdGWLhks9Bwrwp7B+A7dS1i54wRF8J5u0UE An6N6mbGuho+45sK8hiO9BHZtMRx4albqyr2VhAYCxe2bMA/LIhT+/ih9EzRCE2x4dyU CyT4hjYNsp1ZYSdHev5kQkKAZYeK6aq6CBwV1aAmy9pqVvGPHBeDXbo5m05CpT42h3bZ nFkRb5diGBlc/LkTL1epNOvhGHpqjx99RLbf/FT895a88udO1zF9EF9cIy7VhLN0Uuu+ 70AHnVzAGSavWHvWVOlacKJGIDsejlIyRLtrqbyoRE0vyUxWh3nyE8FxDL3qxk5jcMmC G90w== X-Gm-Message-State: AIVw110dcL8GgeR7XPzK8znNwuxADoEhKh4l9hnGrv+kQlhlM4XmRT9l yUZFXP3CSt5JSTkZXxU= X-Received: by 10.107.55.8 with SMTP id e8mr1560197ioa.89.1500502204298; Wed, 19 Jul 2017 15:10:04 -0700 (PDT) Received: from leira.trondhjem.org (c-68-49-162-121.hsd1.mi.comcast.net. [68.49.162.121]) by smtp.gmail.com with ESMTPSA id 9sm518333iop.9.2017.07.19.15.10.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Jul 2017 15:10:03 -0700 (PDT) From: Trond Myklebust To: Chuck Lever , linux-nfs@vger.kernel.org Subject: [PATCH 03/20] NFS: Reduce lock contention in nfs_try_to_update_request() Date: Wed, 19 Jul 2017 18:09:38 -0400 Message-Id: <20170719220955.58210-4-trond.myklebust@primarydata.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170719220955.58210-3-trond.myklebust@primarydata.com> References: <20170719220955.58210-1-trond.myklebust@primarydata.com> <20170719220955.58210-2-trond.myklebust@primarydata.com> <20170719220955.58210-3-trond.myklebust@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Micro-optimisation to move the lockless check into the for(;;) loop. Signed-off-by: Trond Myklebust --- fs/nfs/write.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/fs/nfs/write.c b/fs/nfs/write.c index 06e150c4e315..bb019096c331 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c @@ -1097,13 +1097,12 @@ static struct nfs_page *nfs_try_to_update_request(struct inode *inode, unsigned int end; int error; - if (!PagePrivate(page)) - return NULL; - end = offset + bytes; - spin_lock(&inode->i_lock); for (;;) { + if (!(PagePrivate(page) || PageSwapCache(page))) + return NULL; + spin_lock(&inode->i_lock); req = nfs_page_find_head_request_locked(NFS_I(inode), page); if (req == NULL) goto out_unlock; @@ -1132,7 +1131,6 @@ static struct nfs_page *nfs_try_to_update_request(struct inode *inode, nfs_release_request(req); if (error != 0) goto out_err; - spin_lock(&inode->i_lock); } /* Okay, the request matches. Update the region */