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=1796409637; b=N0wvTThESeX8m3WbINhF9kWq+sG0ASeCneRFQLWvbOcOheZwfLsQHHdNu+iavLPaDBVU JJsmffyO5iOsp9IIsgLWNnKzl+xSrVB076JYTA83HFnz3CxRwD7Y3ClE5HITJyDhIxT5H 8Gb7vYxeaaWVEXPibgtWO/zzyRKT4vzajEaAXyhY0klFn4myYDuiUg/b6FuyVC1WuW1an dYEv0B6WCRoRfoMmj2Yxu7lxL5TC8D6nCRBHeQVgmX6mVvKEkFuUW4KyE3aNdEOUcwRn2 3HRAQgszTGEXV9cwu50qjHfjazkJRFNZpKae6RacpHgDeiDkHtGRTgBh8q2EqIV2bGA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796409637; 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=TkF+pMQMFIJfUWHfBFOh70IsAClL0mxTTic2iZAvZ5c=; b=voexE+ErbhYyM0DABLTr+KJSwkUZTbBpkblGOp4XRmQ27+7JGbFkU1Jgv7PSBX/0oZXf jnnDqhRIzdox6dvSp1tWot3xTIAQRpqZG6QR3negjxhZwXsbipfgYxjpHBlsOsmGsm3Df C8KOzIEMfHi++zVKVhVTRjdUQ3cdJyLr+l/lzU+BTOaEKZBzscC9p5Yi7L0zuh3xgDKBv VD3yPgjxa9dxtrS7JhEb1fUXNf+DMctjeh3MgldCohHskAKxzf2juVbgI8kGoC8uJMase QE5U8wC31pbJfqlheuQ2e+pJayCnZKZb9fnRPg9aM/39mlW64cwLcD9eAGzbPnR120Q== 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=DlQf+aUP; 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 A68D4606A33C; Fri, 4 Dec 2026 18:40:37 +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=DlQf+aUP 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=1796409637; b=0Gt7NRJdWAIOV3ei6r6f8OeYCJrRWXXEKFMlt0YE3D0b6OI1fBvFC/tOb8bpHiQfAcft cNfZI4CElCahBksO5hmJXOV48oatiEEx3Fdqr4iBjkXidwl3P9RYQtOyiu+7rsbdWYVkg jv1U3aais5y0o+/kzfNmGZGoVFeSj0uOhyAq5GP8F8guXXUm0jUJF8t1qDyUfY4lQvTko 6OKcjT7F8ADCugs53JbX2q84m9c/Xkk5cNYYAlotljJwUfo/6RKkUduVwEl8R1sckOgqv zeklqv7mXapCj3dfm9q4nOUlEaIO3GTu+1WmMbXl/F6y8prVzgnBvR5uCj5EhJF/X7Q== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796409637; 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=TkF+pMQMFIJfUWHfBFOh70IsAClL0mxTTic2iZAvZ5c=; b=irVXTEzNv21oBOKAssnOTaEhGJETp+V9TnwpglLx47qhXJBWQ3gPNRsJ+4oBqJ+VkKyb IUVy3EnkGdpKu+y5ARWpbG7hk7wtB8KfYyRZ5vXbMpE5jKZMYkorZRAISlrxxHcnpYe7c mmsCfsOt8pJkSOYaHZtB0Lpbq3chKSzPgheS8BppsLSkFP5/GMwQXuQhim5LN+RYdObWX iU5f7aLcLV0DAU3lgaetoVKvCrs0ZzIlW+G0+jPmarzxdHpt8jv04yepyQRU9dP2Z7Pn6 nV5vxsC6u1HaXoZB2abzHR5OeumuR97Hfxvt3AOpPG/g2IHar9TogAXsrSzHF4GXAZA== 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 B66E11F00A11; 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=1796409637; bh=TkF+pMQMFIJfUWHfBFOh70IsAClL0mxTTic2iZAvZ5c=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=DlQf+aUPtbtLVQ/dOSJWKSG8xzEohpBskiI2ehrrZ16G2XmKhJWYWv71Mn1G/EaWl A6Q3wnmhoscDul9bOZj8MWpndXvvfF3mJjhVz4z+aWd5D/v6H8WgXfTlDJFk00MyZk Ab655LPulWfz3u3Z428WF7ybKIPTwGPqjKzplOFe3oQb/yTdrF3DiOBml1OTgBY117 hPutvHJRF3ZxpNIWcuTm7iWshl2pxsc2H9fwsoXscrQCXn/U9HU36aIfkTd112N3cV Q/GzXPvLarDr7SDEh1KkQ92rDwCZuUfHYPJPE1vHFcjjy6qFFHW93o4Md7IisKAN0J nKaK02hr0aJkg== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 423FF4DC36; Fri, 4 Dec 2026 18:40:35 +0000 (UTC) From: Ernest Borowski via B4 Relay Date: Fri, 04 Dec 2026 19:40:34 +0100 Subject: [PATCH v5 03/13] 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: <20261204-b4-ntfs-delalloc-fixes-v5-3-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=3455; i=ernest.borowski.git@proton.me; s=default; h=from:subject:message-id; bh=yrDl0yNieND0A1+MgMMYDzkPU3H87mreOYUYvXFu5+k=; b=owGbwMvMwCVWzJ65uCpJ5D/jabUkhmxhToVOGbWq/MQ25r402Q4mY52kA7I500VPJIW9Xt+iu dHU6X1HKQuDGBeDrJgiS8f/GyE+Id8+LYvT6oOZw8oEMoSBi1MAJrKjkuF/XI2anPOy5cZ9WgFK Ap5aLKef9a7M+aOzk3ufUOeFIr21DP/dmK4oxu+I9eV41LHjhDTXbnV+fp4v8yV4fDqKuAvbSjg B 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 Reviewed-by: Baolin Liu 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