Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4008966pxb; Mon, 8 Feb 2021 05:58:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJwyhTMtSUHX6w8S2EIcDU5hxIs5Y6+2Iew6/bynE5PFD7z0rri9HUxoK8PFPvQXjfjgf2e9 X-Received: by 2002:aa7:c407:: with SMTP id j7mr17037160edq.28.1612792722553; Mon, 08 Feb 2021 05:58:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612792722; cv=none; d=google.com; s=arc-20160816; b=QXZxQbizFrOpz7gfuaPdgF9fJ3D1cjMG84lsua3bHBUVlfVZVG6zfkH+31wA6niZaj +RG/AOE88I/G1IBevD0iqvWYuI2D/wlzdeZi+imap/mgPfzwOm83tRr3PqGa229qEhqe 1jRjuySs0OGPN0glHkFfX5tf2NrY5dVku3mH1c2T0tr2W9jXdxjsBjqzgM2UysUvdSiX 52I1b+lo55IhYMtpHf4tz4X2iWTtLkGYBfg6ygoLaQ1FYjbP2qe4m8Ip7COgEAETEEG2 EC1sFAdVw/5nD1F+6eqOeU3xY36VfkbHxp42DD/nDH7nT6fU4nc9C5inw6gGZbGxixPD +92w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pYqWrc+M5iVN5lsy/pO1Gi9GuvKSyFACXP5u5ietoLQ=; b=FtGhp/cqhNDW2t9ljOZKpnRkhweVSHWC4t/F6xa321//Mgrvftd0Lkylis1EIScxFj 4kQvlP+6JKcPw070FI2+OWahEXXHjsmYnWUbgvN6B+EVgSRg+HhbVDFaTlQJqEGM/e8T B0QpuqVLV5+dbccjWtMZGVz4TvLOePld6OvPsLr121GoRhwQbD7e/DDs7yoP1/jsYCvy XKpJD1fVgcnbFI31zxBkLJMbvYQY3jkGXVtpiepwkvZU4ZfD6EoveJuvUjPzp86y3BCq 8AgiYqEEUHaqNvfEDCWR1let3r4Sk/iXAKuJoFuQFBJWtKRP5Cfi6zlt+aWGvgT/44Kw DeqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QVV8ut8C; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r11si15940769edc.353.2021.02.08.05.58.16; Mon, 08 Feb 2021 05:58:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QVV8ut8C; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230386AbhBHN4o (ORCPT + 99 others); Mon, 8 Feb 2021 08:56:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:36836 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231704AbhBHN4c (ORCPT ); Mon, 8 Feb 2021 08:56:32 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8622464E4F; Mon, 8 Feb 2021 13:55:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612792549; bh=KgjE87lOd8x6hjJA30x57vQAmDl5ZJxJhOVvaJ9dOB0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QVV8ut8CLaIcY/Q5lBiWdcEVIn79tXXq+x8DlsHNMYyB9yZpqDS9V4lA45c92Gbr4 xVDM/QxJum/uTPXXTyX7SacTb1MNY4oEexhRiQuE6UOSZkFtNo/qrGqDHjKQyRKFZL qqwU314/Pw/Io8ba+TpXF6cwCors0pxFU5HJI4IyITJ0mvqjoCXktocozxapassCgj 8rpTlICs679w/VMpXfNtYcje37hdiz0KBw7R39zxeab9mNnPCJiejZfJpx0+c5knxJ PDfIaF1L0Jud64XzZ4KbJGLIGiDLMdXbu5JeEEdxrUmk2PL3daCZAhoHLyqm2Rw9ia fprpNGzLlcW3g== From: trondmy@kernel.org To: Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH 2/3] NFS: Optimise sparse writes past the end of file Date: Mon, 8 Feb 2021 08:55:46 -0500 Message-Id: <20210208135547.27153-2-trondmy@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210208135547.27153-1-trondmy@kernel.org> References: <20210208135547.27153-1-trondmy@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust If we're doing a write, and the entire page lies beyond the end-of-file, then we can assume the write can be extended to cover the beginning of the page, since we know the data in that region will be all zeros. Signed-off-by: Trond Myklebust --- fs/nfs/file.c | 4 +--- fs/nfs/write.c | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/fs/nfs/file.c b/fs/nfs/file.c index d02a63af9c15..02795a01c7ef 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -626,13 +626,11 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) /* * O_APPEND implies that we must revalidate the file length. */ - if (iocb->ki_flags & IOCB_APPEND) { + if (iocb->ki_flags & IOCB_APPEND || iocb->ki_pos > i_size_read(inode)) { result = nfs_revalidate_file_size(inode, file); if (result) goto out; } - if (iocb->ki_pos > i_size_read(inode)) - nfs_revalidate_mapping(inode, file->f_mapping); since = filemap_sample_wb_err(file->f_mapping); nfs_start_io_write(inode); diff --git a/fs/nfs/write.c b/fs/nfs/write.c index 639c34fec04a..6193350356a8 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c @@ -1278,19 +1278,21 @@ bool nfs_ctx_key_to_expire(struct nfs_open_context *ctx, struct inode *inode) * the PageUptodate() flag. In this case, we will need to turn off * write optimisations that depend on the page contents being correct. */ -static bool nfs_write_pageuptodate(struct page *page, struct inode *inode) +static bool nfs_write_pageuptodate(struct page *page, struct inode *inode, + unsigned int pagelen) { struct nfs_inode *nfsi = NFS_I(inode); if (nfs_have_delegated_attributes(inode)) goto out; - if (nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE) + if (nfsi->cache_validity & + (NFS_INO_REVAL_PAGECACHE | NFS_INO_INVALID_SIZE)) return false; smp_rmb(); - if (test_bit(NFS_INO_INVALIDATING, &nfsi->flags)) + if (test_bit(NFS_INO_INVALIDATING, &nfsi->flags) && pagelen != 0) return false; out: - if (nfsi->cache_validity & NFS_INO_INVALID_DATA) + if (nfsi->cache_validity & NFS_INO_INVALID_DATA && pagelen != 0) return false; return PageUptodate(page) != 0; } @@ -1310,7 +1312,8 @@ is_whole_file_wrlock(struct file_lock *fl) * If the file is opened for synchronous writes then we can just skip the rest * of the checks. */ -static int nfs_can_extend_write(struct file *file, struct page *page, struct inode *inode) +static int nfs_can_extend_write(struct file *file, struct page *page, + struct inode *inode, unsigned int pagelen) { int ret; struct file_lock_context *flctx = inode->i_flctx; @@ -1318,7 +1321,7 @@ static int nfs_can_extend_write(struct file *file, struct page *page, struct ino if (file->f_flags & O_DSYNC) return 0; - if (!nfs_write_pageuptodate(page, inode)) + if (!nfs_write_pageuptodate(page, inode, pagelen)) return 0; if (NFS_PROTO(inode)->have_delegation(inode, FMODE_WRITE)) return 1; @@ -1356,6 +1359,7 @@ int nfs_updatepage(struct file *file, struct page *page, struct nfs_open_context *ctx = nfs_file_open_context(file); struct address_space *mapping = page_file_mapping(page); struct inode *inode = mapping->host; + unsigned int pagelen = nfs_page_length(page); int status = 0; nfs_inc_stats(inode, NFSIOS_VFSUPDATEPAGE); @@ -1366,8 +1370,8 @@ int nfs_updatepage(struct file *file, struct page *page, if (!count) goto out; - if (nfs_can_extend_write(file, page, inode)) { - count = max(count + offset, nfs_page_length(page)); + if (nfs_can_extend_write(file, page, inode, pagelen)) { + count = max(count + offset, pagelen); offset = 0; } -- 2.29.2