From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796409638; b=gMKQYSWApCf4hQ7SwWWH9yn87vde+DTtPqqE5FAtaPlSoX519a+T7GprDdDjHFMCemus kybBvRSWPKxqMd1GewtjnDie8j2DkY1ELWpMm4oFyfSty4wNOjkmYiTcKMS/emXQHqGo6 jn00WaZ08eNC/RX/6U5T7UEfm+0UDx6fmFkyWVF/ALydSgXuE3Zbk2L0iX1PEAtxD03vE 7roH3gr5TzAJjSiFd6Cm33vxKMm1jOPgt/+qhQw8bCocUZHmI8ZGcLR9gYWIihqpgyJD+ b/MCF1TjiizAgRalFXwCKC2+Dg2nbveyV+YQ1amh1dtXNYMtGbzInLb+EGqPqnE8O/g== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796409638; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=e00uXDIs6tWnb2yvEqYKWHmwtLA8vI804RfF6K1jG8o=; b=yF/SpI1XHjs4Aojwl9Mqk5QB4BaeKrKIget/l8692VtrGSmrgJseHhnYYRg06PE/KIvW gCUkRFgwOcibc2FZ5v2+C56LuRgegGvb8aKqapM3cJJzyj8iLwAvOtOfL23WC49al9COe j1Mk47xHSjqRoDk6pmrLmAHhTdWE9owfdVPmce6GOtxxeUMU7mCXJch7Xu61ydbIGFgm7 yEgsX+VtGCWW4w5p3uaPGAnqDRO7jxhuWxldFapdsvk9lf4XjqwHYidmUt0A3X35UB748 yXwfzbcxISAUn9xlZdfWhzyIq8ICJqR3qDx0EP/prcMKjcDXoieIcXoUwO1a1qlMwKA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ndWObaoJ; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A210606A68E; Fri, 4 Dec 2026 18:40:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ndWObaoJ Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796409638; b=Ycq4n2Zmmw12+D8j/NfGdoQT/cFnlW6c41aaYNx1oarFCRjcMs1hIRLgXGLktscMPwK+ S7PEzBdB/wH/ruWnu6sLrHVZAFdlw/X1Pj2SghcG56dIt+mFQouktUwDuuHrkzXtYcq11 qXtmb0nGlCSVbWyDDJUeD/H3GSF0vG1Q7+bAg+zv9eQRAeSF/BoSXmz9TGqFOWraxXTy9 //AjHybXhALGRiV2DyDkQwv4HfrUU9wJrcBgj7YPrgdUVgOYhUGJMEz1UdYWYed5R9e0o GPYk/bYhkibQdaL5H6PTaM8PSfhMrMSIoLyJLGJO+PLAS6dxcwSzUVBMAsmTcozi3+g== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796409638; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=e00uXDIs6tWnb2yvEqYKWHmwtLA8vI804RfF6K1jG8o=; b=pmXy7tg9ja0WBEWRbJB6cvpv32SwTgNrQ5DxFMsUWthd80OPgdya9+2LBkUI2iHHV6mY mXa3BxcOHZWDsSkom1qtm7F8yergun1DL+TLp5Sh9lAOebFXCb7cERKITpGqxjfNBGgte 0mXI80aZRgM3AHoAdZGEPgjept0D7yTqNC7uHXDnKvMgO6yRAvsbnrbP56Q9wLT6Cogeg hmWmiECKCJ9eQiV0m8dnUwpQyr8yRoZKgUntAa10HQ0Oyiux3pnH8bbEBTyf23Imb7Hrp 9gM/LD7TplY88Ixht/DU0gZnrPWZeVwzQ/AefNEP5WwwB7SBQuGXJibIbkQXbCVMzcw== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 8C1D71F00A07; Fri, 4 Dec 2026 18:40:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796409638; bh=e00uXDIs6tWnb2yvEqYKWHmwtLA8vI804RfF6K1jG8o=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=ndWObaoJetr92n9jwq6QG9B3SBvIY4t5vtUXoAfKmvrY5yAK0JaysVpFRxmU5WBI/ G4pN+Q0rFcp3P/nLD3B9MkBLk9TrNexQWD4pT1xHeS6b8BtF23Oa2bfLJnmzddKAQH YpgapzpWISguWnS1FqQPCz4AV5JShmpt7OFPiYnafqD6oqz+xCMES546SSV4J8uYm5 e4B3m7DTmf0wumR8CZtdztSX0K/AycGVGdirIdAi+VV+l3diAe4r1AY8RHTCgXIqbD cVk98z+vWpWsI1T5+S+0Au+El8Ozb8S38QZViOKNr0plZq7sYMLI5TyOy0R8QobJjR 17Qzf12OOT1JQ== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 17D6B4DC32; Fri, 4 Dec 2026 18:40:35 +0000 (UTC) From: Ernest Borowski via B4 Relay Date: Fri, 04 Dec 2026 19:40:33 +0100 Subject: [PATCH v5 02/13] iomap: add a helper to mark a range of a folio dirty X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261204-b4-ntfs-delalloc-fixes-v5-2-1cd0267df2cd@proton.me> References: <20261204-b4-ntfs-delalloc-fixes-v5-0-1cd0267df2cd@proton.me> In-Reply-To: <20261204-b4-ntfs-delalloc-fixes-v5-0-1cd0267df2cd@proton.me> To: Namjae Jeon , Hyunchul Lee , Baolin Liu Cc: Christian Brauner , Christoph Hellwig , "Darrick J. Wong" , ntfs@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, Zhan Xusheng , stable@vger.kernel.org, Baolin Liu , Ernest Borowski X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3733; i=ernest.borowski.git@proton.me; s=default; h=from:subject:message-id; bh=AKfIvNSdB6xQ5JqLVB84CjGj2HdAoWjCro143jcOZz0=; b=owGbwMvMwCVWzJ65uCpJ5D/jabUkhmxhTvkA4xffX+/tt4vRyE5Pm6LB8KVi/iGvB/yMVZZM0 hvtlqzuKGVhEONikBVTZOn4fyPEJ+Tbp2VxWn0wc1iZQIYwcHEKwERE1jMyPNXU+qpe9TfuZp5l 6M9kw5f9W49xrxMT28dx6OuG0u3hAgz/A/bY+eh1R8dyce3+Wq2zWjap4HKQZIlhtVjQo0nZXpU 8AA== X-Developer-Key: i=ernest.borowski.git@proton.me; a=openpgp; fpr=88FFD8544C54F6F2A65E2A8E730769A37A6214FF X-Endpoint-Received: by B4 Relay for ernest.borowski.git@proton.me/default with auth_id=1589 X-Original-From: Ernest Borowski Reply-To: ernest.borowski.git@proton.me Content-Transfer-Encoding: 7bit From: Ernest Borowski A filesystem that allocates in units larger than a block may need writeback to write blocks that a buffered write did not copy into. ntfs reserves whole clusters for delayed allocation, and after a short copy into a cluster that was a hole, writeback must also write the rest of that cluster, or the cluster shows its old contents on the disk there. folio_mark_dirty() marks every block of the folio dirty, so the delalloc release that follows no longer finds the clean blocks of the clusters the write did not reach and keeps them reserved: with 1 KiB and 2 KiB clusters, writeback then allocates a cluster that holds no data. Add iomap_dirty_folio_range(), which marks the folio and only the blocks covering a byte range dirty. It and iomap_dirty_folio() share one internal helper; iomap_dirty_folio() keeps passing the mapping it is given, as ->dirty_folio may be called without the folio lock. "ntfs: zero the rest of a new cluster after a short buffered write" later in this series needs this, so it goes to stable with it. Cc: stable@vger.kernel.org Reviewed-by: Baolin Liu Signed-off-by: Ernest Borowski --- fs/iomap/buffered-io.c | 32 ++++++++++++++++++++++++++------ include/linux/iomap.h | 1 + 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 2b9bcff7ce..d505668360 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -847,15 +847,35 @@ void iomap_invalidate_folio(struct folio *folio, size_t offset, size_t len) } EXPORT_SYMBOL_GPL(iomap_invalidate_folio); -bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio) +static bool __iomap_dirty_folio_range(struct address_space *mapping, + struct folio *folio, size_t off, size_t len) { - struct inode *inode = mapping->host; - size_t len = folio_size(folio); - - ifs_alloc(inode, folio, 0); - iomap_set_range_dirty(folio, 0, len); + ifs_alloc(mapping->host, folio, 0); + iomap_set_range_dirty(folio, off, len); return filemap_dirty_folio(mapping, folio); } + +/** + * iomap_dirty_folio_range - mark a range of a folio dirty + * @folio: the locked, uptodate folio + * @off: byte offset of the range in @folio + * @len: length of the range in bytes + * + * Mark the blocks that cover [@off, @off + @len) and @folio dirty, but none + * of the other blocks of @folio, so that writeback writes only those blocks. + * + * Return: true if @folio was clean before, as filemap_dirty_folio() does. + */ +bool iomap_dirty_folio_range(struct folio *folio, size_t off, size_t len) +{ + return __iomap_dirty_folio_range(folio->mapping, folio, off, len); +} +EXPORT_SYMBOL_GPL(iomap_dirty_folio_range); + +bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio) +{ + return __iomap_dirty_folio_range(mapping, folio, 0, folio_size(folio)); +} EXPORT_SYMBOL_GPL(iomap_dirty_folio); static void diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 78a1b7603a..f80da4d8ff 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -445,6 +445,7 @@ struct folio *iomap_get_folio(struct iomap_iter *iter, loff_t pos, size_t len); bool iomap_release_folio(struct folio *folio, gfp_t gfp_flags); void iomap_invalidate_folio(struct folio *folio, size_t offset, size_t len); bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio); +bool iomap_dirty_folio_range(struct folio *folio, size_t off, size_t len); void iomap_folio_mark_uptodate(struct folio *folio); int iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len, iomap_iter_next_fn next, -- 2.56.1