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=1796146964; b=jHo8RbKT7znrv3DfrLjgLp4dBZOL6DkQt3H5+YinQzAZPMtK31M1o93fqRFe3g3CetDo vOWO5duASxbizm6shK6/H/qSzTvMyMVSB/z1KDT4CFm+jABVUwhB4b/Ap00mlwPkDSIIR E8ioCKnTa5Tw+Irr+Lw/w+s76u1WjhVin2bJbbA9Vh4JcVx5CNaZEcPcRZpooICAV4cVZ PSkYZdtCvm02Fo6LE3cMNj/5IcbswaWjPFi6x51pq9FQfATqG94Ir2Wom+5Viuegi48vs YBw3TCQfbxRrUxHhhWuH1F5ZNM4vFw1xPQbByjz2PZFE1hQ1XRRXijtKtwJf37V2nAQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796146964; 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=6VUYhWg6ViBeUt5AyWgVTXW/Sv21J/rjxUa8V17TRyo=; b=eH9XHoNz5oLyXxm8fFzlWP7S7q7BlISkHGhCnKOBSaxoRJ1+crgGdK24g+Zz3m7UUyx7 scKp6wbgITBdBX2cTbidapxMK9lJznZaAMhKY0eVjItv06OxCqaPS6FxkG5UntN4bsjlR TTt40Qrgx+b0992h/bJeNn8SrvALoYQmtSJo5AC2VG5tdsuJ3q6dfHT+Nm/KqO8UngOUJ ZdY6pv+6B/Rq5e7eesYjOMml7OnBN5+gkn52VADqGxV2P5U4DgWBKkoeLkvim/fhP9FuJ xARDdWGKbA6BXsDvCFbBaWhm+1xB29uy9jP1YJCf2DvGr9QNY0JiOJv+gLp3UJ7v7HQ== 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=oK7kh7ef; 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 A17C8606A322; Tue, 1 Dec 2026 17:42:44 +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=oK7kh7ef 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=1796146964; b=uXAxbWxJdo7kI6IHUAPNF959cYI+G3QlJtabuLksI8DbPg2hGDNjphRXUbXdIwYYbrqK fYFSAxqH9hl80laqjoANXYilsQGz/weMlEoRPMKDWRSlLfWNZZig44lQjBDr7i+l7j23u zyqOfVJUUqqcF7oa1ZFfuF12H5kavNRhWNCSkVu2irrl6XbBgyDLuFJCXzKH4Jg2MBgas V7oXd3D8lZut5hv7ATIwwJHsTbfSnVP81Igb9rCZnBmn/qRJ++T2cyzDUvQrT012ahA/p NCOYaVtM3KW6fO9tYX15uamdUyih2sWiXwWB2/OjKnSksAaub5T9xjr6WTyULD7x7yw== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796146964; 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=6VUYhWg6ViBeUt5AyWgVTXW/Sv21J/rjxUa8V17TRyo=; b=CuvVrlF7M+PnUbL+WL8Ix3fLmPeKFrytwhCwspsMwpqg3EvlADq9zZk+pZLUTh2iVrW+ Vhdmf8fb5Z0NOOiRlllRrjA/N4rMv2KAH/88FetOa2QprBB6Lf5tkOMrrwXoB8iWekvLP VhcnL/FevMo/aqcvugucox7QDBKHIKu75Y8fcPRhUY6H7enGgWxhi0dpswfm3jOZrJTY9 /vVO7oHPUMkX6ikQXNLk5pJHVZUuHF5kOxpCzpIcwAl570NUHjSgbXH6NrvNNZDtbkVO1 9qb+8eHzDkiI3inRidWTZ+E42m8iT+/jbFb76U5ofkjNyCTBJ0u+Q/+6OiqgyczTnzw== 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 414B51F00926; Tue, 1 Dec 2026 17:42:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796146964; bh=6VUYhWg6ViBeUt5AyWgVTXW/Sv21J/rjxUa8V17TRyo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=oK7kh7ef9WLkZRuLb+KuRqr0IVloRsfUpCMfJqtNriRzWbRpZdLmB+IQ9KeRQMsjR xKYsbje4wnRezHj12aXmX30vG7H6yJ/Rxh3Fx7E3oVI4GBAgHLf/bGQADcLxOwBoTA e0k626FRhoH2PpPfeiY9ttvKY7hxb6h3gNjfXLi8vE/riqV9V5DvvI7vMWr/ryOC+H Imm9KsvG4tKOOWzlZj+4cKA78oLjuTf4i+WYQy8A8J2/rRc1XKoMHcOSm2oZd0ZFFv F/XvrbS6jk8DwGQgMpdwF1LfZRrv+IV/ExL+O+ohBBYsxEZpKOLofqQcwqV8miWcMo uhiF3mKlJbunQ== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 6A3D34EF06; Tue, 1 Dec 2026 17:42:38 +0000 (UTC) From: Ernest Borowski via B4 Relay Date: Tue, 01 Dec 2026 18:42:36 +0100 Subject: [PATCH v4 01/11] iomap: punch out a run of clean blocks in one call 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: <20261201-b4-ntfs-delalloc-fixes-v4-1-e5dd6f77016a@proton.me> References: <20261201-b4-ntfs-delalloc-fixes-v4-0-e5dd6f77016a@proton.me> In-Reply-To: <20261201-b4-ntfs-delalloc-fixes-v4-0-e5dd6f77016a@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, Ernest Borowski X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2270; i=ernest.borowski.git@proton.me; s=default; h=from:subject:message-id; bh=z+t625oBzNmoK37OeXIqS/dGLd/ss59a6nfEOJp02Y0=; b=owGbwMvMwCVWzJ65uCpJ5D/jabUkhmx+du7X75h9701kWBBbfUx4Ut/JyigR3eUOC//86T82h W2LPdfWjlIWBjEuBlkxRZaO/zdCfEK+fVoWp9UHM4eVCWQIAxenAEwkJIThf+7BFI0tnhPT99Up WP/SzfgvtrnR+dd8nxLh7ernd7/RmM3wV+YgT96b45t/S131Cp+88t6m9w8jJ9bwL4mLY+jw25r zgB8A 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 iomap_write_delalloc_ifs_punch() calls ->punch() once for every clean block of a dirty folio. A file system that reserves delayed allocation space in units larger than a block can release a unit only when one call covers it whole. ntfs reserves whole clusters and uses 512 byte blocks, so with 1 KiB clusters a buffered write into a hole that fails after zeroing the first cluster of a 4 KiB folio leaves the other three clusters of that folio reserved, and writeback later allocates them. Pass each run of contiguous clean blocks to ->punch() in one call. XFS and ext4 punch any range they are given, so for them this only means fewer calls. "ntfs: punch out the delalloc reservation of a failed buffered write" later in this series needs this, so it goes to stable with it. Cc: stable@vger.kernel.org Signed-off-by: Ernest Borowski --- fs/iomap/buffered-io.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 25915c0f5e..b6dd56f1bd 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1364,6 +1364,9 @@ static void iomap_write_delalloc_ifs_punch(struct inode *inode, * blocks within a folio which are marked uptodate * but not dirty. In that case it is necessary to punch * out such blocks to avoid leaking any delalloc blocks. + * Pass each run of clean blocks in one call: a file system + * that reserves space in units larger than a block can only + * release a unit that it sees whole. */ ifs = folio->private; if (!ifs) @@ -1374,9 +1377,13 @@ static void iomap_write_delalloc_ifs_punch(struct inode *inode, last_blk = offset_in_folio(folio, last_byte) >> blkbits; while ((first_blk = ifs_next_clean_block(folio, first_blk, last_blk)) <= last_blk) { - punch(inode, folio_pos(folio) + (first_blk << blkbits), - 1 << blkbits, iomap); - first_blk++; + loff_t pos = folio_pos(folio) + (first_blk << blkbits); + unsigned int next_blk; + + next_blk = ifs_next_dirty_block(folio, first_blk + 1, last_blk); + punch(inode, pos, (loff_t)(next_blk - first_blk) << blkbits, + iomap); + first_blk = next_blk; } } -- 2.56.1