From patchwork Tue Apr 30 14:00:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13649073 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 07232C4345F for ; Tue, 30 Apr 2024 14:01:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8576D6B009A; Tue, 30 Apr 2024 10:01:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 808A26B009B; Tue, 30 Apr 2024 10:01:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A8646B009C; Tue, 30 Apr 2024 10:01:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 44BC56B009A for ; Tue, 30 Apr 2024 10:01:19 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E2002A0A09 for ; Tue, 30 Apr 2024 14:01:18 +0000 (UTC) X-FDA: 82066360236.04.67A22B0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 3E9E740017 for ; Tue, 30 Apr 2024 14:01:16 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=c985YWO7; spf=pass (imf01.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1714485676; 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=TVvsQkYCcJVRpP2m+QZDwQmmWSsKMODgUlfWruXZbkI=; b=TyacmXyBJrorP1NP6cq6aZ5pJKWA8lijia0F1L/mqN0noXXPoi0bO+bugzd62YbetPcvzi NEf0za68LolGrPFd7DRPtEypMbgFl8jbcP6+PHnskxSoAlUSZ/HE70RHV2DOuwu7cVeaWu 8QmRAssn0qUd8odQ1hyXVoPVAeqtcK4= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=c985YWO7; spf=pass (imf01.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1714485676; a=rsa-sha256; cv=none; b=aXbhmTI+OvlcTokWonoo0br+0uK8FgwqapuAaQtyfaFE+k6lqPSWOLuSCXaUvlUX14jdip H07zzVHVhxMRhGOSw9uKaxmFh0o3i0+UgIuI4OLGZ6/2SX5E3NlP/hMOq/7QjazWknlgLi swWFw1dekiaHIktTbCuRdwDkdC7p7JM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714485675; 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=TVvsQkYCcJVRpP2m+QZDwQmmWSsKMODgUlfWruXZbkI=; b=c985YWO7qxS7MYCWoQD9q2j5WlDqX1OrRpnb3DjUzYa/5JHswqjtVT9u3erBToWHl90T9X rXUvrq+3nfIEsFHaj01FIXrgdek1bwSsLjoPCjehvk/SaIRccTK/3CYFVEXIicl8UO/iQ1 DzP1+Bn4nyK0rhCnGrI8eZOj3eMev68= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-277-zRMsxZfENTaJb65jT9Kr8g-1; Tue, 30 Apr 2024 10:01:09 -0400 X-MC-Unique: zRMsxZfENTaJb65jT9Kr8g-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 E9CEC830D37; Tue, 30 Apr 2024 14:01:06 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71CEA1121313; Tue, 30 Apr 2024 14:01:03 +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 v2 01/22] netfs: Update i_blocks when write committed to pagecache Date: Tue, 30 Apr 2024 15:00:32 +0100 Message-ID: <20240430140056.261997-2-dhowells@redhat.com> In-Reply-To: <20240430140056.261997-1-dhowells@redhat.com> References: <20240430140056.261997-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Rspam-User: X-Rspamd-Queue-Id: 3E9E740017 X-Rspamd-Server: rspam06 X-Stat-Signature: e8cxi9bxs75r6nupoazbjm1sjfx94a5i X-HE-Tag: 1714485676-778844 X-HE-Meta: U2FsdGVkX194a1+3stManZdipXPrw8v7Nf+CdW05vCCDL7belMdt2JKjI5aD2JMZW7UGh3dbeTqV6ZjDhHHKgIT8ZeOiM8ZbABCRyODjZyxvIykjkqEb+ITWmUf0WohntegML+atltx4trXjDUSxgY7jcxIMRRjKr0SQnQu0gU7V0Coc2c4hM4UZvlqjStDi3Vo8mWRpT5qdC2MS6j+G4Urv0MpI7GsNfFlsdeArGRXIw36EPWGeu/GnJB6r19658G97RMomBiS6YKaDqlN4JR4QHt6C3l9Ke+vYCWOOCsH7Y18Bnt+koNFYy57Uz5RtHBEX4yM5/c1FdiV/Kz2GBslLjzdldYB0Cm060dKsBAMFJ6apsbmPx6e4PSHxeS9CtjJQLk3KTfKrp/r3IltIpohD7EJELjwzKMypzX77ToXMlrcjQao/wtGsH82DavzBMlwRHvcJXb54lNQv7+OgfcI4T6DXujJlITD+Mhem4fPQRMWlg7rwz2u2tkWGRN0KdZZezbIa+grKp9ZJKW8oaxb0V/SIaQpYRUMBPEAMbQB2D9uu00jo8c9bkJseNyoyQjQYGFFllLVjmcJoDGBf6LbokIOymzJ4779gwEGGScofJoTbNle/78NS3q11dAlQRD6oV2Lvv3JdlLGynw5Y1LK1xdwbLcmoafe+s2ZzFjB8i2xfc77I2fpKQIkVZnoDewcfXR29A0EI7b4ixTSgnF8vK2yi8HAcPQ+rLi7bYPGvtzbjGHiZDK/nzByuaE/lscL7Dm6XMDo39weO6ElUa5+SeSJsRObowxJQTQYgI6iKftltSpZRbAxMip78yMTJV56pauYZdS9rmS9gtzjVsaWAsTeVuUq+oIvb6ydP1/2pPWsrmba5UwPSmZg/ZU7XMshmPgY/AEYvvTYOVRGzf/YkmLviZzfBt7xLzs52Mdh62Ir876FTQKT/5m0/AIRbawpiVofG1kDrsQYsqfa 89SbyCbM ish5QPp4zki4SzgoKzGwScFO8O4SbCwKzS1hKIDNcKAwFR9k= 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. This maintains cifs commit dbfdff402d89854126658376cbcb08363194d3cd ("smb3: update allocation size more accurately on write completion") which would otherwise be removed by the cifs part of the netfs writeback rewrite. Signed-off-by: David Howells Reviewed-by: Jeff Layton cc: Steve French cc: Shyam Prasad N cc: Rohith Surabattula 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 267b622d923b..f7455a579f21 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 @@ -351,18 +382,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)) {