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=vc3ZtTy2O4lfRqLRCjJxCVWfNR9SdFSTLgtVjjH3ypRFQe7JZ5AfAAhzBn1ngPl1xs/o RWpn5WnDqzCxFjXt3tebsIv/F/mdIB+5XemznIMnhvNfVaRHN72aFpKwNCyhYB7Rt5Ju2 Ev/iqmDAZ/CmkyF0S/6wHIuumpCuXicDmImeyJlaYE9tJS1O4qIgxNdxn9Ik9jBmRG/NW t/nhQG1fPWJI8ss+xAIZkX+EuBVwSmGJO/VZh8ZRguGp0rX7QkkQ6Dy3pvWuXlaxOUtTv ft/zyGM3Ss0ayW42M+4rB75g+7vleLvlOXPZ0tMt3iv3OEinqhl+JL1pPjDqCgBKJRg== 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=q323dZRw6GHZUI01LMNECklckloj4D8Pa5TUtZtJySs=; b=hl/n7I+PMu/bSZ5mm2rLOmH2ZAEGUx9WKQSp3Rs5sVmCZtwO1mOyTOLTtfcA8e92C0Z1 jur+14TzJjGtc0kkNq+44729PpbIW2ERueLRHfeNopgALht7qK/HzoiDuOahRF/fhg7mN w6Gj9SFKNB/3oO1VgYaLAAcG5WGKDdeupvJRXLFUKCGwRvvTVMtPVVre0FCauMiFELiMT LIbjyg5OPS4iLJBCv0NlwsONkPVA3M2I3GsdMVmW6peu62JGgSE4vsHWlnujyWPC5GG+L EO5kdIopb+QhhNqcCzji8B+m73kCNxV/0FWa+zuLNjdJU9G5SFwh7y6UxR5uP9QeLTw== 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=lOeXIWge; 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 A7D60606A68F; 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=lOeXIWge 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=GNWthlKg9zwzFjg5WAxIOHQjybhyuxy38a4GyGRtf7Ft2oMD2MfPbqk8lXnODM3NxtPp mDf1DRAkrAoSpAxKda+9lMonpy5FrWyBjUFKtHiPXecF9KuL+zbPAmQkCNm+2VGuW3DTH tV1MhS55w1+NVrO5WeWX4VLeCdTYs4KX0FMS3u07CxWXWrTU5LGHRRXd4/9F5n35guxFk RF9fKedSfPWrzqS14fXes1sXe/M7/F/MRhFd1nxE+Wv8Yeo7lJ8xvHWUBL6JSfTw8ZWf2 a96nrkEOm1zeFZg6uG1BI8zPxRRbpiQnEijR2hgVM+SXbcLIvesOCz0+BmQ+tVpItcw== 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=q323dZRw6GHZUI01LMNECklckloj4D8Pa5TUtZtJySs=; b=bXg3N2MfkfxkdK8Beac6fcUw8IBH0Jqguwu0W2X58sUPxPWN9oDYVMF2pBWr492AOCTh cvlgYKsQwV8Wd7l9Xe3uFgD57FEhswCGJ3qflbCSehEBHeN7ADEh/tyY6nGzjSJuMDXhb wUuxz8eq7K5MjBIHahmrmDwp5kwo5FPWeukrD97ccAiNhOoCCWqW1yI3jSF/JyrrWWlNd A6K9qAZVHgzr/7HJxksTZSSa6iP17tyyRFTMTEpZVP1VeWXJs/utCAT47HsEqZrie9bVi TJ/z94vanuEAjPgniVCBXSpAQ6I4K9WOYNoUImcIxh6ddY831GWeIIU02q3QW2r81iQ== 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 A6B8A1F00A13; Fri, 4 Dec 2026 18:40:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796409638; bh=q323dZRw6GHZUI01LMNECklckloj4D8Pa5TUtZtJySs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=lOeXIWgeesUR1FZdQkNsssucQD+z7C38aCxWpCU/UBcxbKAR4h1MMs0ViLB2gozch 1h3jdCsNMcHoaPHXOn5ILIVI/w1S7dZZLOW8UjU+4YuX5gFhMDRZbDQUZTF4CPuBL5 4yn8EV66B4pHVJHlI1YloBOir4Auj3FHkm+AOj53fkGkYOrI2X+lRmLnvwF9JY/W12 fZoJor4FP9FXx9Az4lcGF022BAfy0NdN7ySR6bBMwMdEV4ioReFmeOyVBdigQJPvmZ ZTVtgYz0R+QfaNtaZeIaRRMoRAuiC7kxzUV34ph0lQNwwxpvjGZBBYJD19lavAUdfb xYv+pXrypcb7Q== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id BA7144DC42; Fri, 4 Dec 2026 18:40:35 +0000 (UTC) From: Ernest Borowski via B4 Relay Date: Fri, 04 Dec 2026 19:40:37 +0100 Subject: [PATCH v5 06/13] ntfs: release the delalloc reservations of an evicted inode 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-6-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=4622; i=ernest.borowski.git@proton.me; s=default; h=from:subject:message-id; bh=aJ2blZi61BIaPhiNSTgNCH4CaieNuS9n6omqNfE0pHk=; b=owGbwMvMwCVWzJ65uCpJ5D/jabUkhmxhToWcV8rea2LYK9o7xZVrXmYcvigfw2OvF3Oz6Z/Xy 5VCPzd2lLIwiHExyIopsnT8vxHiE/Lt07I4rT6YOaxMIEMYuDgFYCL7VRkZdmwsky3TvPDmRs0x HqFLTQwmrXKxaa59e8O3y3+L0XaYxshwZ829vUG2Oyw3H56bWbfFenHHzDdvmWJ6lVhvmmTU6Sz mAQA= 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 When an inode is evicted with LCN_DELALLOC runs left in its runlist, truncate_inode_pages_final() drops their dirty folios and the clusters reserved for them in vol->dirty_clusters are never given back. Only the deletion of a base inode released anything, using the per-inode i_dealloc_clusters counter. This leaks free space until unmount when a named stream with delayed data is removed (ntfs_stream_finish_remove() truncates the page cache and ntfs_attr_rm() frees only real clusters), when a file is unlinked while one of its named streams has delayed data (ntfs_cleanup_deleted_inode() drops the stream inode, whose reservation is not covered by the base inode's counter), and when an inode that keeps a delalloc run no dirty folio covers (see the next patches) is evicted. Reproducer: mount with streams_interface=windows, write 1 MiB to f:s, rm f:s (or rm f), sync: statfs() reports 256 (4 KiB) clusters less free space than after a remount. Release the reservations of whatever delalloc runs are left in the runlist when any ntfs inode is evicted, and drop the counter-based release from the deletion path, which would release them twice. Fixes: b041ca562526 ("ntfs: update iomap and address space operations") Cc: stable@vger.kernel.org Reviewed-by: Baolin Liu Signed-off-by: Ernest Borowski --- fs/ntfs/attrib.c | 12 +++++++----- fs/ntfs/attrib.h | 1 + fs/ntfs/inode.c | 12 +++++++++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c index 3944e32764..71fc4ca006 100644 --- a/fs/ntfs/attrib.c +++ b/fs/ntfs/attrib.c @@ -4427,13 +4427,15 @@ static int ntfs_attr_make_resident(struct ntfs_inode *ni, struct ntfs_attr_searc * * 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. + * writeback allocates the clusters. Runs cut off by a truncate, or left in + * the runlist of an inode that is evicted, 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. + * The runlist must be locked for writing. It need not be mapped completely: + * delalloc runs only exist in fragments of the runlist that are mapped. */ -static void ntfs_release_delalloc_from(struct ntfs_inode *ni, s64 start_vcn) +void ntfs_release_delalloc_from(struct ntfs_inode *ni, s64 start_vcn) { struct runlist_element *rl = ni->runlist.rl; s64 nr = 0; diff --git a/fs/ntfs/attrib.h b/fs/ntfs/attrib.h index 0415f817dc..8d72e9180c 100644 --- a/fs/ntfs/attrib.h +++ b/fs/ntfs/attrib.h @@ -110,6 +110,7 @@ int ntfs_attr_fallocate(struct ntfs_inode *ni, loff_t start, loff_t byte_len, bo int ntfs_non_resident_attr_insert_range(struct ntfs_inode *ni, s64 start_vcn, s64 len); int ntfs_non_resident_attr_collapse_range(struct ntfs_inode *ni, s64 start_vcn, s64 len); int ntfs_non_resident_attr_punch_hole(struct ntfs_inode *ni, s64 start_vcn, s64 len); +void ntfs_release_delalloc_from(struct ntfs_inode *ni, s64 start_vcn); int __ntfs_attr_truncate_vfs(struct ntfs_inode *ni, const s64 newsize, const s64 i_size); int ntfs_attr_expand(struct ntfs_inode *ni, const s64 newsize, const s64 prealloc_size); diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c index 3aac1d7d31..651427c31f 100644 --- a/fs/ntfs/inode.c +++ b/fs/ntfs/inode.c @@ -430,7 +430,6 @@ static int ntfs_non_resident_dealloc_clusters(struct ntfs_inode *ni) } } - ntfs_release_dirty_clusters(ni->vol, ni->i_dealloc_clusters); ntfs_attr_put_search_ctx(actx); return err; } @@ -2470,6 +2469,17 @@ void ntfs_evict_big_inode(struct inode *vi) truncate_inode_pages_final(&vi->i_data); + /* + * The dirty folios dropped above never reach writeback. Give back + * the reservations of the delalloc runs they had, for named streams + * and attribute inodes as well as for base inodes. + */ + if (NInoNonResident(ni) && ni->runlist.rl) { + down_write(&ni->runlist.lock); + ntfs_release_delalloc_from(ni, 0); + up_write(&ni->runlist.lock); + } + if (!vi->i_nlink) { if (!NInoAttr(ni)) { /* Never called with extent inodes */ -- 2.56.1