mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ernest Borowski via B4 Relay <devnull+ernest.borowski.git.proton.me@kernel.org>
To: Namjae Jeon <linkinjeon@kernel.org>,
	Hyunchul Lee <hyc.lee@gmail.com>,
	 Baolin Liu <liubaolin12138@163.com>
Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org,
	 Zhan Xusheng <zhanxusheng1024@gmail.com>,
	stable@vger.kernel.org,
	 Ernest Borowski <ernest.borowski.git@proton.me>
Subject: [PATCH 3/7] ntfs: release the delalloc reservations of an evicted inode
Date: Sun, 22 Nov 2026 19:19:39 +0100	[thread overview]
Message-ID: <20261122-b4-ntfs-delalloc-fixes-v1-3-0726f0dce403@proton.me> (raw)
In-Reply-To: <20261122-b4-ntfs-delalloc-fixes-v1-0-0726f0dce403@proton.me>

From: Ernest Borowski <ernest.borowski.git@proton.me>

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
Signed-off-by: Ernest Borowski <ernest.borowski.git@proton.me>
---
 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 cdac846f37..39fa983cd8 100644
--- a/fs/ntfs/attrib.c
+++ b/fs/ntfs/attrib.c
@@ -4390,13 +4390,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 9d6bf03202..faa2dfba3a 100644
--- a/fs/ntfs/attrib.h
+++ b/fs/ntfs/attrib.h
@@ -109,6 +109,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 4fbdcd4596..911e68fa91 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;
 }
@@ -2459,6 +2458,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



  parent reply	other threads:[~2026-11-22 18:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 18:19 [PATCH 0/7] ntfs: delayed allocation accounting and stale data fixes, part 1 Ernest Borowski via B4 Relay
2026-11-22 18:19 ` [PATCH 1/7] ntfs: release delalloc reservations cut off by truncate Ernest Borowski via B4 Relay
2026-11-22 18:19 ` [PATCH 2/7] ntfs: do not consume delalloc reservations when filling holes Ernest Borowski via B4 Relay
2026-11-22 18:19 ` Ernest Borowski via B4 Relay [this message]
2026-11-22 18:19 ` [PATCH 4/7] ntfs: do not shift the cluster number of a delalloc run on split Ernest Borowski via B4 Relay
2026-11-22 18:19 ` [PATCH 5/7] ntfs: punch out the delalloc reservation of a failed buffered write Ernest Borowski via B4 Relay
2026-11-22 18:19 ` [PATCH 6/7] ntfs: zero new delalloc clusters even when writeback allocates them Ernest Borowski via B4 Relay
2026-11-22 18:19 ` [PATCH 7/7] ntfs: zero the rest of a new cluster after a short buffered write Ernest Borowski via B4 Relay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261122-b4-ntfs-delalloc-fixes-v1-3-0726f0dce403@proton.me \
    --to=devnull+ernest.borowski.git.proton.me@kernel.org \
    --cc=ernest.borowski.git@proton.me \
    --cc=hyc.lee@gmail.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liubaolin12138@163.com \
    --cc=ntfs@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=zhanxusheng1024@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®