From patchwork Wed Jul 19 22:09:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 9853275 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 63715602BD for ; Wed, 19 Jul 2017 22:10:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5515828709 for ; Wed, 19 Jul 2017 22:10:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 49BB828718; Wed, 19 Jul 2017 22:10:17 +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 A9DBD28709 for ; Wed, 19 Jul 2017 22:10:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755521AbdGSWKO (ORCPT ); Wed, 19 Jul 2017 18:10:14 -0400 Received: from mail-it0-f66.google.com ([209.85.214.66]:33009 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755272AbdGSWKN (ORCPT ); Wed, 19 Jul 2017 18:10:13 -0400 Received: by mail-it0-f66.google.com with SMTP id t6so860548itb.0 for ; Wed, 19 Jul 2017 15:10:13 -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=eVm/QbQ/r+AreoM6SM+KDtQ84tbc+AioA8HJseiNZo4Q3/D5aNUSkfCx/o8rrJvzCj 6QQ2R1MXLD7F5uATUt5fILjFiKl1QMRT5jI34OAvF7NN9AuqqhjnpRyotEKtWQ4Nqoz0 OK3XvupjoU0DaEDxUCzzQAl56o+ZtP+e7vE1RQKzmFtMxfidmeUqO8L+bPXdY78CuSTl XmrmVEKucGBZ5rtjC4SGogitYWtP9xDwJ3HAYNP6sR9SZTbYRc6ts5038NGoz5qZV9n+ kxGJQnJJh06FBj5csFf9uXicP8NxCDJ2+pYoNcvdWwXYnUfOswHDIFOr8LZTEtXKWrbt lUbg== 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=DquUajQv54HipF1BV85YDQx8Z3zRrYuzLTdf29hDMWRAHbngnSpxb251EFgjWTrTpM 3KgHIk7t1GVnkSuqpBVvrIfD1TAZADHpRzLqBhuQfn98KINwPO73/HSD/CO3em94WvPP n8NnxiSVeZpTZ72SMo7LcsDL95IFsL+9ShREXOrCiY1tecWJJS1yDzcBEBeybkQDpyK9 u2OIHF/gqOczVYpfC9nxOOErk2xguT4pnH4bjTFqFyhZXR2WKJtrJ9T3ysoR4ZWnXDmX HVBBqyBq8UAABBMra2Rl5HVZFe9/cSQ5olxe04SnOHffLbatlLbZyLT6sM7JVrtozhTh 110A== X-Gm-Message-State: AIVw111oK5NgMevhZamU8ZAnsOhC+lpkd+NgGggQog373ywS09PNN/Ll NB3VV2AB42hSsQ== X-Received: by 10.36.203.3 with SMTP id u3mr1422938itg.101.1500502212052; Wed, 19 Jul 2017 15:10:12 -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.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Jul 2017 15:10:11 -0700 (PDT) From: Trond Myklebust To: Chuck Lever , linux-nfs@vger.kernel.org Subject: [PATCH 10/20] NFS: Teach nfs_try_to_update_request() to deal with request page_groups Date: Wed, 19 Jul 2017 18:09:45 -0400 Message-Id: <20170719220955.58210-11-trond.myklebust@primarydata.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170719220955.58210-10-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> <20170719220955.58210-4-trond.myklebust@primarydata.com> <20170719220955.58210-5-trond.myklebust@primarydata.com> <20170719220955.58210-6-trond.myklebust@primarydata.com> <20170719220955.58210-7-trond.myklebust@primarydata.com> <20170719220955.58210-8-trond.myklebust@primarydata.com> <20170719220955.58210-9-trond.myklebust@primarydata.com> <20170719220955.58210-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; } /*