From patchwork Thu Mar 9 18:58:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 9613925 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 41D4860417 for ; Thu, 9 Mar 2017 18:59:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39B5F28654 for ; Thu, 9 Mar 2017 18:59:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2BDA228660; Thu, 9 Mar 2017 18:59:38 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable 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 D05FA28654 for ; Thu, 9 Mar 2017 18:59:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933214AbdCIS6n (ORCPT ); Thu, 9 Mar 2017 13:58:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33422 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932845AbdCIS6m (ORCPT ); Thu, 9 Mar 2017 13:58:42 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 656437E9C0; Thu, 9 Mar 2017 18:58:37 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-66.rdu2.redhat.com [10.10.120.66] (may be forged)) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v29IwZ53014135; Thu, 9 Mar 2017 13:58:36 -0500 Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 24/27] afs: afs_fsync() does two flushes, one of which is redundant From: David Howells To: viro@ZenIV.linux.org.uk Cc: dhowells@redhat.com, linux-fsdevel@vger.kernel.org, linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org Date: Thu, 09 Mar 2017 18:58:34 +0000 Message-ID: <148908591458.16794.9080658582730241249.stgit@warthog.procyon.org.uk> In-Reply-To: <148908574888.16794.14109877851518811944.stgit@warthog.procyon.org.uk> References: <148908574888.16794.14109877851518811944.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 09 Mar 2017 18:58:37 +0000 (UTC) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP afs_fsync() calls filemap_write_and_wait_range() and then does a walk through the writeback records and flushes those - which should achieve exactly the same thing. Get rid of the filemap_write_and_wait_range() since that's uninterruptible, whereas the wait for the writeback records is interruptible. Further, we can at least contract the inode-locked region to just the afs_writeback_call(). Signed-off-by: David Howells --- fs/afs/write.c | 61 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/fs/afs/write.c b/fs/afs/write.c index 6e13e96c3db0..ab89551ab356 100644 --- a/fs/afs/write.c +++ b/fs/afs/write.c @@ -700,21 +700,17 @@ int afs_writeback_all(struct afs_vnode *vnode) * - the return status from this call provides a reliable indication of * whether any write errors occurred for this process. */ -int afs_fsync(struct file *file, loff_t start, loff_t end, int datasync) +static int afs_sync_file(struct file *file, loff_t start, loff_t end, bool sync) { struct inode *inode = file_inode(file); struct afs_writeback *wb, *xwb; struct afs_vnode *vnode = AFS_FS_I(inode); + bool do_sync = false; int ret; _enter("{%x:%u},{n=%pD},%d", vnode->fid.vid, vnode->fid.vnode, file, - datasync); - - ret = filemap_write_and_wait_range(inode->i_mapping, start, end); - if (ret) - return ret; - inode_lock(inode); + sync); /* use a writeback record as a marker in the queue - when this reaches * the front of the queue, all the outstanding writes are either @@ -732,34 +728,55 @@ int afs_fsync(struct file *file, loff_t start, loff_t end, int datasync) wb->usage = 1; wb->state = AFS_WBACK_SYNCING; init_waitqueue_head(&wb->waitq); + INIT_LIST_HEAD(&wb->link); spin_lock(&vnode->writeback_lock); list_for_each_entry(xwb, &vnode->writebacks, link) { - if (xwb->state == AFS_WBACK_PENDING) + switch (xwb->state) { + case AFS_WBACK_PENDING: xwb->state = AFS_WBACK_CONFLICTING; + do_sync = true; + break; + default: + do_sync |= sync; + break; + case AFS_WBACK_SYNCING: + break; + case AFS_WBACK_COMPLETE: + kdebug("Shouldn't see completed records"); + break; + } } - list_add_tail(&wb->link, &vnode->writebacks); + if (do_sync) + list_add_tail(&wb->link, &vnode->writebacks); spin_unlock(&vnode->writeback_lock); - /* push all the outstanding writebacks to the server */ - ret = afs_writeback_all(vnode); - if (ret < 0) { - afs_put_writeback(wb); - _leave(" = %d [wb]", ret); - goto out; + ret = 0; + if (do_sync) { + /* push all the outstanding writebacks to the server */ + inode_lock(inode); + ret = afs_writeback_all(vnode); + inode_unlock(inode); + if (ret < 0) + goto out; + + /* wait for the preceding writes to actually complete */ + ret = wait_event_interruptible(wb->waitq, + wb->state == AFS_WBACK_COMPLETE || + vnode->writebacks.next == &wb->link); } - /* wait for the preceding writes to actually complete */ - ret = wait_event_interruptible(wb->waitq, - wb->state == AFS_WBACK_COMPLETE || - vnode->writebacks.next == &wb->link); +out: afs_put_writeback(wb); _leave(" = %d", ret); -out: - inode_unlock(inode); return ret; } +int afs_fsync(struct file *file, loff_t start, loff_t end, int datasync) +{ + return afs_sync_file(file, start, end, true); +} + /* * Flush out all outstanding writes on a file opened for writing when it is * closed. @@ -771,7 +788,7 @@ int afs_flush(struct file *file, fl_owner_t id) if ((file->f_mode & FMODE_WRITE) == 0) return 0; - return vfs_fsync(file, 0); + return afs_sync_file(file, 0, LLONG_MAX, false); } /*