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=1796146968; b=a2N2fMXBZf77DnSfzRp6xa3Zis+eNGB7WfOtEAnEmBgCgpMsRLZG62lyOZYbR3UHVdVf xl7jsi1LyaNrfsEaq/kvQVEvf9fOptWcA8Hsqe4PJ2bNJxd+K3u6UyPQED3/WP/vg9S4h hTSSK8wAoJqvgxOZdjbYYdBLYrMLF6F6hC2yYFfaCHcWrKav0OSTj6lrW5RwhuLz/A12+ vpz0tDqPpPFYJnAQfV5tqnZ5WFe5EirjP79XsER4qJux2XyH3vxRdk04TbQB7b5Lw0JcA 2QKrpzJSWD+WBBQ8y2wqXNWtBxTWhkjt7JUczXd3VqHDNi/ObsitTHyTots8Q1MoHow== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796146968; 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=HFDP8xWRuhs1eYZbiLgb0TBsprXg4JjYN5lAiuuLT78=; b=KH9ks4Bbm5gkt71DxmQsLx+ydTExIzw2gTHh+PWG4GOx6DJi9EyZsSIuMMaO9pC8ezb0 XMUrP9wppcF9QChhFAGbRBQ4CXwcASa75Wwxig0Ydot97eTga9KnS0Ye2Gv0CS1/jZkd6 2V0L8NxN86vgbFqMFDphc2VWu3R05zBaJb0gv/2RiX9G0hfySpleQiK7II18zUeql3q6Q pxnFQecs+DXOek3gpKuTzaDAVRSuz2EcygAVUPo97EEBV0qDPuJvPiQyAbHkEYOO8JQET ZOiH/Y39ngG2W/ybckGKCNcKC8Zd8j3tB1gATglWPu2aWbG5xqQ22edG4QpoZTG6E8w== 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="YMYjH/zK"; 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 390AC606A320; Tue, 1 Dec 2026 17:42:48 +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=YMYjH/zK 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=1796146967; b=dtAOkDTbdUSArl29JDBMYiVSRMw8gpTFtDYWfT2SvPx3WbpoZ/qStZAQgwDS18lQJWet 2NwCzEZD+LD+GenMCdpzt3iM0Z+Z3E8aJOnUaJwVi2M67NNho17BeSpvRSIaE9lXTSAtp e+qWEgfelRn6J+qbqR2ti94vT33esth1aM1k9gpqHA/X+pjavw5mz4zvcw1xZGbfJq6x9 p7LjSszi/+Wh/SGHUdVz+ycQP6r0sf6MfgNlN2Ao8EcXoJZYYkaJ/OjzvEiBNkBqbCim0 Ozj1QT4H4ylZTpTfv6auIg2ksFgGK7FbEraNcLsNdqoOxD3DE5hw1OTOFMi0c5Iu2vQ== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796146967; 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=HFDP8xWRuhs1eYZbiLgb0TBsprXg4JjYN5lAiuuLT78=; b=SKrdk7cEr6dOhz/FLWUzNj00jZD6bCmUpUHyTUIm+Syie2FxLsh3MaFx6cDFE0m7lnYr bajIQFPNkj6YtNxr6MTYiBwr+9d3RQ+mUTRsoMFO+TxWCsZ2FrCDE75CC+i1kPNe+mJAh XZZtbOCxR9i2OJ79LBDnblNLNNcz/HLGKRPplZb/StzZjKAEpw8SU7gLflLBCGMJwAWt+ MPSOBQZU7JNjsTR+ATPMZhMERvJvxEDeo7fx07f1PFFoGIA/mpOUWGDI2LLfc7Js1aOrx fMle8kkXhB7lKnpBcelMeL0rkhEZ5RzTOKBZl2uoqoj6EutP+L4K17I1hiYQLKPToSQ== 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 436B31F0093B; 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=1796146967; bh=HFDP8xWRuhs1eYZbiLgb0TBsprXg4JjYN5lAiuuLT78=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=YMYjH/zK84rVURWBCkNizJ1OKxLeVPbVIouquEliBma1TogBtZD0p+JmURR0R4OYk gQnFq42w6YA9SdK2asnFCChuNFKvBHk4P3vjP6zkSEKZl0i9lkfWJLd/cq2DwRcSaN 8tdSwK1f51ptw3t0AicLtLuW8I604RvkdRZAVpXxuqU32LpryezqTi6r0LSHxAcgOV rEX791DlmHkbK8Fv7TDlDhXqu2ZyC8K29Ff4BKYCYT9kq70q7PqPQEPrX2jkmd7y3j n11TValvfPc25z8Al/MxCfI/R2j5eANdNgvEkOrameaa9JQArJUvOcWOUVod5oX7vW PB7VBB1TQ8iew== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id B0D7F4EF17; Tue, 1 Dec 2026 17:42:38 +0000 (UTC) From: Ernest Borowski via B4 Relay Date: Tue, 01 Dec 2026 18:42:38 +0100 Subject: [PATCH v4 03/11] ntfs: release delalloc reservations cut off by truncate 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-3-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=3407; i=ernest.borowski.git@proton.me; s=default; h=from:subject:message-id; bh=tmQ4vqMokHW0oe8O3tmxTL3OoC+1wmp58KH1tQVk3og=; b=owGbwMvMwCVWzJ65uCpJ5D/jabUkhmx+dh7DXSU746zOC7X4OSUwzU62OSrzu/TYA43giV/XW HG3ZQt3lLIwiHExyIopsnT8vxHiE/Lt07I4rT6YOaxMIEMYuDgFYCKr3RkZNiv5PqldlcByON3j 7OzdvNs2Vc5K7d+6qWqT3t3a7nfcexgZ3vcXOr7WF9l5+LOk1t3XNdyVsZ3r9s9dzHTGKH6uTuE nRgA= 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 buffered write into a hole turns the hole into an LCN_DELALLOC run and reserves its clusters in vol->dirty_clusters (ntfs_write_simple_iomap_begin_non_resident()). Writeback hands the reservation back when ntfs_cluster_alloc() allocates the run. A truncate that cuts off delalloc runs before writeback drops their dirty folios, frees the clusters of the attribute with ntfs_cluster_free(), which skips everything that is not a real cluster, and removes the runs with ntfs_rl_truncate_nolock(). Nothing gives the reservation back, so the free space reported by statfs() and used by ntfs_available_clusters_count() shrinks by that many clusters until the volume is unmounted. $Bitmap is not affected. Workloads that rewrite files (open(O_TRUNC) + write) or truncate freshly written data lose free space quickly: a test that writes, truncates and punches holes in six 400 KiB files on a 128 MiB volume sees statfs() free space drop from 79 MB to zero in 80 seconds, after which writes fail with ENOSPC or come back short. A 1 MiB buffered write followed by ftruncate(fd, 0) and sync leaves 256 (4 KiB) clusters reserved. Release the reservation of the delalloc runs that the shrink cuts off, before the runlist is truncated. Fixes: 495e90fa3348 ("ntfs: update attrib operations") Cc: stable@vger.kernel.org Signed-off-by: Ernest Borowski --- fs/ntfs/attrib.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c index c192333be8..3f19fd2ec7 100644 --- a/fs/ntfs/attrib.c +++ b/fs/ntfs/attrib.c @@ -4420,6 +4420,37 @@ static int ntfs_attr_make_resident(struct ntfs_inode *ni, struct ntfs_attr_searc return 0; } +/* + * ntfs_release_delalloc_from - give back the reservation of delalloc runs + * @ni: non-resident ntfs attribute whose runlist is about to be truncated + * @start_vcn: first vcn that is cut off + * + * Delayed allocation reserves vol->dirty_clusters for every LCN_DELALLOC + * cluster when the buffered write is done and only gives it back when + * writeback allocates the clusters. Runs cut off by a truncate never reach + * writeback (their dirty folios are dropped from the page cache), so their + * reservation has to be released here or it is lost until unmount. + * + * The runlist must be mapped completely and locked for writing. + */ +static void ntfs_release_delalloc_from(struct ntfs_inode *ni, s64 start_vcn) +{ + struct runlist_element *rl = ni->runlist.rl; + s64 nr = 0; + + lockdep_assert_held_write(&ni->runlist.lock); + + for (; rl && rl->length; rl++) { + if (rl->lcn != LCN_DELALLOC || rl->vcn + rl->length <= start_vcn) + continue; + nr += rl->vcn + rl->length - max(rl->vcn, start_vcn); + } + if (!nr) + return; + ntfs_release_dirty_clusters(ni->vol, nr); + ni->i_dealloc_clusters -= min_t(s64, nr, ni->i_dealloc_clusters); +} + /* * ntfs_non_resident_attr_shrink - shrink a non-resident, open ntfs attribute * @ni: non-resident ntfs attribute to shrink @@ -4516,6 +4547,8 @@ static int ntfs_non_resident_attr_shrink(struct ntfs_inode *ni, } ntfs_attr_put_search_ctx(ctx); + ntfs_release_delalloc_from(ni, first_free_vcn); + /* Truncate the runlist itself. */ if (ntfs_rl_truncate_nolock(vol, &ni->runlist, first_free_vcn)) { /* -- 2.56.1