From patchwork Thu Mar 28 16:33:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13608970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E062BCD1283 for ; Thu, 28 Mar 2024 16:35:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FC206B009E; Thu, 28 Mar 2024 12:35:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 585486B009F; Thu, 28 Mar 2024 12:35:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3FEF66B00A0; Thu, 28 Mar 2024 12:35:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 1BBAD6B009E for ; Thu, 28 Mar 2024 12:35:25 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C9A7612031E for ; Thu, 28 Mar 2024 16:35:24 +0000 (UTC) X-FDA: 81946998168.06.3139CE2 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf22.hostedemail.com (Postfix) with ESMTP id D9D63C001C for ; Thu, 28 Mar 2024 16:35:22 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="R/vyLlzn"; spf=pass (imf22.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711643723; a=rsa-sha256; cv=none; b=mKCMj5OV2nPcei/OaRB0jDQ94DCa2x3QiqlzmPVgRYEJwvt8ImVJiyyHBHrWmbUWEsntR+ /sbq62AepUUuOJ3m7i6u0GaELgr7PWhtFjwMXMMmOUSUtLPcxMSmd9pkOVDJOTIhPtXsvY geOwumJY0B8WfUq40StP4T2S+ewVVkM= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="R/vyLlzn"; spf=pass (imf22.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711643723; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=iDQ5YQkdeqSX7Pu2NIHjg+k9McupuXq1Cg/hmfvmEVE=; b=td2Nt8qGORNQEvR0cQxnFUNEClRZhlUFGDjdOeXEz+S12gqsQ0Nw6GTQvGpEwxp4dHufBg xfw23mtdCvv92JtrhaOnQCaLU2zpMtjAie2pIr7mvKO33DsuDwoSv5dRHBuWc/2YSA365R rWnEF/XzUA8uM+GjX2KEr+n8OaOznYE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711643722; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iDQ5YQkdeqSX7Pu2NIHjg+k9McupuXq1Cg/hmfvmEVE=; b=R/vyLlznlJ/TB4L9uRZf5mJUpOFHtIPueODKbzZ/LEZK2Whna3x3eYDZu+4+vT4zxb9C9b NA+vPoPvprlXFN6nNaMPfezF4agx/uE4SdU2s9WHX+rhyk4Lqnzr70oTa3XTy3Tb0XII8y maQXgoVVaWk3q/DH3ipJKffs6jB6Eec= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-196-Sw6sTb4APMeMo8jtP39mKA-1; Thu, 28 Mar 2024 12:35:16 -0400 X-MC-Unique: Sw6sTb4APMeMo8jtP39mKA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 31EB628B6AAF; Thu, 28 Mar 2024 16:35:15 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.146]) by smtp.corp.redhat.com (Postfix) with ESMTP id EEF1E40C6CB1; Thu, 28 Mar 2024 16:35:11 +0000 (UTC) From: David Howells To: Christian Brauner , Jeff Layton , Gao Xiang , Dominique Martinet Cc: David Howells , Matthew Wilcox , Steve French , Marc Dionne , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Eric Van Hensbergen , Ilya Dryomov , netfs@lists.linux.dev, linux-cachefs@redhat.com, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs@lists.linux.dev, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Steve French , Shyam Prasad N , Rohith Surabattula Subject: [PATCH 03/26] netfs: Update i_blocks when write committed to pagecache Date: Thu, 28 Mar 2024 16:33:55 +0000 Message-ID: <20240328163424.2781320-4-dhowells@redhat.com> In-Reply-To: <20240328163424.2781320-1-dhowells@redhat.com> References: <20240328163424.2781320-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: D9D63C001C X-Stat-Signature: qy7u7hb4uniptjr5hy7yw1ryrgf8w9qc X-Rspam-User: X-HE-Tag: 1711643722-981298 X-HE-Meta: U2FsdGVkX1+wLB6H2ugO37svrH73cZPyr1aow+GbTKfIyYz54yvhmF+4jTji6KZqXG5jZe7l5OUDLVXH+Scp4mNlDB22MJy7ZgKSnZlzwcWp44FABXygSWM1KPHIdA2kFE8VMeLQDGIOO8FMxpYyzy5Lx3/3tjYlal7+5YciPPcKSXzjiyv/MiX5/4d7oRYbI8UktjhQNilzAUsNspHOmTIlqQbH8yKiMMRDxtS04wpG1yDLCRQ5+hFWfJk/TvKheN36S7W8Ofhh16sWfiQHAyXKbsU2z/H6+Fu4PGVe50QqwuAhXf0VYYK300E6ULiZASmk3V099ELpmRbFfq3n3fVVrR4jPNX2YO4QToR1+rvEgFHMC9cKcEEn4rl1BV9k3sS+zpXf0xOXWaq6jFG1tzOlxMptTDUKRPgMBaGl8f4Up33aJpFvU86UfJujKaOSETCPr2DIAIH44jkjchiJdcq4dh5JNXlfAw6UlBqtJVq9mUMgydPU2QQ4i4NK72YRceK21LPwiTWRgZ/Ik8h3BMWDW1hRwXCaExt9YoGpG2xviM6nATpNH19jbMkmvgMcyZIHs8EGnCkSlfYTFVgOphJDTnrKCTokJdAs3FmQ+gUM+gkMMB5YpKinNV3gYhPPTNhEC36V61v7CWddxs/q+G5Yosz4XLSZWtPX3r0+8MAS1B5jKNpSHsSAFKc9CgO7zy+U6Jw7PkBOzuc+YtheGz+B/pXOPkbz4PHR3ji6HBi3Nj4N576QYH6SrbwydYdVtL0fUwqbYi9d9dkjGhEPCXX1RQ5arMMw6nGYZ6wXwNnCCljOL2O4G2LofRpRmyvpDz07u2dLQNvjcoO5kqAOfb1eaWLkox7kaS6idDgW/ebLWu2Eh7RultfavnbFav07Dh/n89bBjctV4FiDfL50zoKI7kB24DdhXd+2eiPik69IysAO1akaP6d56lWFBFeuarWDV6/5vZ/BZqNu/9j Ei7HLCIm QnOj4TNmqPgUTMdjyRuF+u3JsIViFd8ZnLPMuZ5HJ+lpaXcSDaVoafZa1m3Bw9fuDShElWNXPuofd5raB66TiUzjdHQJEIhbBXi8x37avbNKSBBy2rLPgTtzPIWMQyyfOgP+oeCmei5eAMA0DGxLdB1G4GJGQpu3/HuNifElSbXG0n5lnqfJO0oN+M3LNyVDoArsbV/ucGrSwqHqZMVTFyQhxnrZC6HFAcxaDMugd2FwclqLBjClerG5c6ELC3/ggZ/lgcZpWEl1+0zxhD3Y8p+zO77G44Qbq6G8hxkKR6HIuXAWd8sYHAw08dvmGbKYhRiKis//Q2ejxwAZNcQQS57X2rMc38SFdSYakrqcteDvcLmEv0mPFqomtjlimnN3MCiKGn5clebzfrGaeIqB3oLanUQZsJuUOp2vq1hqWj5gwg0GTYMl1m+3OkxW1xxl0mDCUrd391UFkd/qtp0XPhJL4nkgPgdb2fZ6BekTUlNx1/GhunA84k9lRhA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Update i_blocks when i_size is updated when we finish making a write to the pagecache to reflect the amount of space we think will be consumed. Signed-off-by: David Howells cc: Steve French cc: Shyam Prasad N cc: Rohith Surabattula cc: Jeff Layton cc: linux-cifs@vger.kernel.org cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org Reviewed-by: Jeff Layton --- fs/netfs/buffered_write.c | 45 +++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/fs/netfs/buffered_write.c b/fs/netfs/buffered_write.c index 9a0d32e4b422..c194655a6dcf 100644 --- a/fs/netfs/buffered_write.c +++ b/fs/netfs/buffered_write.c @@ -130,6 +130,37 @@ static struct folio *netfs_grab_folio_for_write(struct address_space *mapping, mapping_gfp_mask(mapping)); } +/* + * Update i_size and estimate the update to i_blocks to reflect the additional + * data written into the pagecache until we can find out from the server what + * the values actually are. + */ +static void netfs_update_i_size(struct netfs_inode *ctx, struct inode *inode, + loff_t i_size, loff_t pos, size_t copied) +{ + blkcnt_t add; + size_t gap; + + if (ctx->ops->update_i_size) { + ctx->ops->update_i_size(inode, pos); + return; + } + + i_size_write(inode, pos); +#if IS_ENABLED(CONFIG_FSCACHE) + fscache_update_cookie(ctx->cache, NULL, &pos); +#endif + + gap = SECTOR_SIZE - (i_size & (SECTOR_SIZE - 1)); + if (copied > gap) { + add = DIV_ROUND_UP(copied - gap, SECTOR_SIZE); + + inode->i_blocks = min_t(blkcnt_t, + DIV_ROUND_UP(pos, SECTOR_SIZE), + inode->i_blocks + add); + } +} + /** * netfs_perform_write - Copy data into the pagecache. * @iocb: The operation parameters @@ -352,18 +383,10 @@ ssize_t netfs_perform_write(struct kiocb *iocb, struct iov_iter *iter, trace_netfs_folio(folio, trace); /* Update the inode size if we moved the EOF marker */ - i_size = i_size_read(inode); pos += copied; - if (pos > i_size) { - if (ctx->ops->update_i_size) { - ctx->ops->update_i_size(inode, pos); - } else { - i_size_write(inode, pos); -#if IS_ENABLED(CONFIG_FSCACHE) - fscache_update_cookie(ctx->cache, NULL, &pos); -#endif - } - } + i_size = i_size_read(inode); + if (pos > i_size) + netfs_update_i_size(ctx, inode, i_size, pos, copied); written += copied; if (likely(!wreq)) {