Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp565513lqh; Thu, 28 Mar 2024 09:36:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW2RCoaJrquYABK6bAOSPYJSa+HkPOLgk389+os1ig9Soak5rMwKKm2r07inUllpk3ZBRXjSwgcR0htLSt02MhAuw+mT2gJz/NxJK3zfw== X-Google-Smtp-Source: AGHT+IGk0p00GYaS7KGhqwjzlSqeMwy3+phb+EkZo18oKwK9mK39rVrNp9mNJiTyEVfUWKcA7Wxj X-Received: by 2002:a05:6358:c00a:b0:17c:b53:98dc with SMTP id kv10-20020a056358c00a00b0017c0b5398dcmr3273735rwc.18.1711643762563; Thu, 28 Mar 2024 09:36:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711643762; cv=pass; d=google.com; s=arc-20160816; b=XZSoJ/8r1hv9uJOHqdRPG7mA4UBOU7/qoWbYpRtaexEnmNlbvhXDgEvxPbkyv7dgvW CCtPmI5cA4ngJnKqIggMzgWmK92tdqVa/8/2PDO/hiomqDeXRUJKqlFW1xRqyCMqs/mu lXVc0lXQxhvHeZ4FFdUpaYDMkgdKTqOicfhkzRGnQ6eY7rIiPvjRBP9kafGYTovzqbL6 PIK3Fk66jz2yNH+0xK1JOVtv+4zEyDbI68roRkeE/2a6vqXQ7XcurxZ3i+ACRSRWoyQ3 0yrT+RoqLhTT14A2RRBVYr93sVwztOqTNvEH0S36UbbYxxoDAmUCKejpZjUhCB5iUR8a 1KYg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=iDQ5YQkdeqSX7Pu2NIHjg+k9McupuXq1Cg/hmfvmEVE=; fh=D72SRyTeGTT5e8cHVnWso1+T4PfZOoBdL/zxY6by6YI=; b=cxz2AMohPLMJyGYf7XsUoSqDWV8bwGHeA7fySP5EY5pMEjPhrhDNl4gShy7fxAwsmC KQuAxsniH35BBV1bntrxvpBmVf2YUz8yCxA2DlpVRjrVnu5EytyH6nsj8iDEgMNvChej flOx6DET+RefhoS25cHRf78M+0q1ki7LGmoGi3EQFtSb3Wh4Dm9LHfe6xw+qaFJyf6Q6 nM+Dr1FtLC+lK0oe81b9cYlvOUhLiSpLcj2L9pIcJNI+1PsIHoIzSb8+DoiMrwDKaIlz dHNLk2fBU7bLhx90KljtJgBsZcTsz6znZMkruaMXbEroejDbK9gdgZKXO52IlU+G+f/R 24FA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bm+yGwbR; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-nfs+bounces-2521-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-2521-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id w18-20020a63af12000000b005f06665a187si1716326pge.534.2024.03.28.09.36.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 09:36:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs+bounces-2521-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bm+yGwbR; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-nfs+bounces-2521-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-2521-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2F579291325 for ; Thu, 28 Mar 2024 16:36:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E0C2C3A1DA; Thu, 28 Mar 2024 16:35:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bm+yGwbR" X-Original-To: linux-nfs@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C9BB1DFE1 for ; Thu, 28 Mar 2024 16:35:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711643721; cv=none; b=ZDJU9VLGrhft+WXPKoZPqRJxJVYcEgyBpRSVEqAnOYYVfwGRYNG9Gle2xqnADAwcqe4uWzEh//PIQD+QgDZXGHRK3ohDBhBiW+wJBcX4DtmMy1AIxswO+ps0F+G3MjB1HYlrjheLuRKjhTcgj99dtxTvx2kGfnWN6E9DrdKUDfQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711643721; c=relaxed/simple; bh=BfnW5EfhEDL95JMcPgV0yx/xbWdEtWGJsEenOfjkE/E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b5O4fnOz9YZnymo6iC8b1FgRfUTbZEFGmwNZjdBcL4HcTNGy5IvpA7mAWFEe7zwwMxG1mNoOieswDnRFwfUJX83L+0tEnch5y3nofBbEKLOJJtcNpiulwHET/pd7hlecMCF5Eb+MdMWRMj+VPstxbGTkY7QFFEJnVufcAfiPJLQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=bm+yGwbR; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711643719; 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=bm+yGwbRR4KJOr8GROxfsxQdJ9wbcPhja/v/bmnlPx2nAFCnaj5F7l1uZD/yI0p28JOqLh 43FjvKEiPV5T37GHLN5cRGplnNaKf/U6fLwgD9PtqH8IWJilgJqHscupTcnDgU43Tvjd0K U/1T1vZe0oUNN+2dijCowRq3Q9H2t9M= 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> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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 --- 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)) {