From patchwork Thu Aug 3 13:45:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 9879173 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 C8ACB60360 for ; Thu, 3 Aug 2017 13:46:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BDCC425F31 for ; Thu, 3 Aug 2017 13:46:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2B352886B; Thu, 3 Aug 2017 13:46:22 +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 57A5525F31 for ; Thu, 3 Aug 2017 13:46:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751905AbdHCNpw (ORCPT ); Thu, 3 Aug 2017 09:45:52 -0400 Received: from mail-io0-f195.google.com ([209.85.223.195]:38798 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751804AbdHCNpr (ORCPT ); Thu, 3 Aug 2017 09:45:47 -0400 Received: by mail-io0-f195.google.com with SMTP id o9so1296583iod.5 for ; Thu, 03 Aug 2017 06:45:47 -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=o/MvwZnjesuDZcOnJRDvIeiona05preKd4Y2XaZ//GU=; b=ZDbmmwFM3VN1NRSPQ8H1b9tBha8DU3i06xQkPX6oRCmwGvgsMZedq16K4bMfUp6wvY +TIHW/1649BONjdT7qUmLTxrHjAuwV5Bjq98hYjkY5VtntNi44FaGTTcebcIY815qIZN ku4gJwK3nYD+FVdGyJBafB2a4koaC/GJEioXpC37GOo1nqccQJhEF8j1pwKE8Kn8O2If Ileo/UeU4Yz+UyihXWem9XvGNlkJxP+sEJEcrOSQvbg5CnqBhXyshOhK38FrhclDyvFk +Oc6EfYVf1y2g66y9yoL8RuGqAn4L6cEer6PiF4LqVo5LmmJNkdhCb25udcTe43+T5Zb 4VkQ== 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=o/MvwZnjesuDZcOnJRDvIeiona05preKd4Y2XaZ//GU=; b=p2r7Sqy3x7LmTEMjUCCmD+geETtm0Qhv/7rlBgEw09/bX5JNZRjaPSPtpkOlL3HhWz dJtP/cql+JJ6CSJv6Zv8vAyIghPx3ruqtRCvaVTGdJDG1t5rsdfKRpUi/zq0IcYB/nhw 8vzGSRMgMhuK/yYBdps9skQa312jrFPJV7qcmR6iyLbViMWvNSSlCxabiip/dzDSIMNa iHMvJvL+6kpeLjQroM+nSpYMkGVwz6LU5vCYx8r97aGdZAoxGbFdU72kJfcF7TkGGffZ 6SAwrmASeUgit9WGp///yGH8Z/cUvw5eaC0r8jp7O/+/yYuArKS5/m0l1tvrRUpdyNLn OVBA== X-Gm-Message-State: AIVw113+CyVjS3r0oLW5Ou3O4B7Mg+aaQdw0NbhsHPreQgNtNukkhjhL QCLgW+fxD/L/2w== X-Received: by 10.107.189.65 with SMTP id n62mr1717760iof.191.1501767946947; Thu, 03 Aug 2017 06:45:46 -0700 (PDT) Received: from localhost.localdomain (50-108-95-251.adr01.mskg.mi.frontiernet.net. [50.108.95.251]) by smtp.gmail.com with ESMTPSA id q90sm5759547ioi.41.2017.08.03.06.45.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2017 06:45:46 -0700 (PDT) From: Trond Myklebust To: Chuck Lever , linux-nfs@vger.kernel.org Subject: [PATCH v2 10/28] NFS: Teach nfs_try_to_update_request() to deal with request page_groups Date: Thu, 3 Aug 2017 09:45:05 -0400 Message-Id: <20170803134523.4922-11-trond.myklebust@primarydata.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170803134523.4922-10-trond.myklebust@primarydata.com> References: <20170803134523.4922-1-trond.myklebust@primarydata.com> <20170803134523.4922-2-trond.myklebust@primarydata.com> <20170803134523.4922-3-trond.myklebust@primarydata.com> <20170803134523.4922-4-trond.myklebust@primarydata.com> <20170803134523.4922-5-trond.myklebust@primarydata.com> <20170803134523.4922-6-trond.myklebust@primarydata.com> <20170803134523.4922-7-trond.myklebust@primarydata.com> <20170803134523.4922-8-trond.myklebust@primarydata.com> <20170803134523.4922-9-trond.myklebust@primarydata.com> <20170803134523.4922-10-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 Simplify the code, and avoid some flushes to disk. Signed-off-by: Trond Myklebust --- fs/nfs/write.c | 60 ++++++++++++++++++++-------------------------------------- 1 file changed, 20 insertions(+), 40 deletions(-) diff --git a/fs/nfs/write.c b/fs/nfs/write.c index ee981353d4aa..0b4d1ef168e0 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c @@ -1107,39 +1107,19 @@ static struct nfs_page *nfs_try_to_update_request(struct inode *inode, end = offset + bytes; - 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; - - /* should be handled by nfs_flush_incompatible */ - WARN_ON_ONCE(req->wb_head != req); - WARN_ON_ONCE(req->wb_this_page != req); - - rqend = req->wb_offset + req->wb_bytes; - /* - * Tell the caller to flush out the request if - * the offsets are non-contiguous. - * Note: nfs_flush_incompatible() will already - * have flushed out requests having wrong owners. - */ - if (offset > rqend - || end < req->wb_offset) - goto out_flushme; - - if (nfs_lock_request(req)) - break; + req = nfs_lock_and_join_requests(page); + if (IS_ERR_OR_NULL(req)) + return req; - /* The request is locked, so wait and then retry */ - spin_unlock(&inode->i_lock); - error = nfs_wait_on_request(req); - nfs_release_request(req); - if (error != 0) - goto out_err; - } + rqend = req->wb_offset + req->wb_bytes; + /* + * Tell the caller to flush out the request if + * the offsets are non-contiguous. + * Note: nfs_flush_incompatible() will already + * have flushed out requests having wrong owners. + */ + if (offset > rqend || end < req->wb_offset) + goto out_flushme; /* Okay, the request matches. Update the region */ if (offset < req->wb_offset) { @@ -1150,17 +1130,17 @@ static struct nfs_page *nfs_try_to_update_request(struct inode *inode, req->wb_bytes = end - req->wb_offset; else req->wb_bytes = rqend - req->wb_offset; -out_unlock: - if (req) - nfs_clear_request_commit(req); - spin_unlock(&inode->i_lock); return req; out_flushme: - spin_unlock(&inode->i_lock); - nfs_release_request(req); + /* + * Note: we mark the request dirty here because + * nfs_lock_and_join_requests() cannot preserve + * commit flags, so we have to replay the write. + */ + nfs_mark_request_dirty(req); + nfs_unlock_and_release_request(req); error = nfs_wb_page(inode, page); -out_err: - return ERR_PTR(error); + return (error < 0) ? ERR_PTR(error) : NULL; } /*