From: Zhan Xusheng <zhanxusheng1024@gmail.com>
To: almaz.alexandrovich@paragon-software.com
Cc: ntfs3@lists.linux.dev, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, zhanxusheng@xiaomi.com
Subject: [PATCH 1/2] fs/ntfs3: allocate only the written range of a hole on writeback
Date: Fri, 20 Nov 2026 21:36:03 +0800 [thread overview]
Message-ID: <20261120133604.427285-1-zhanxusheng1024@gmail.com> (raw)
From: Zhan Xusheng <zhanxusheng@xiaomi.com>
ntfs_writeback_range() maps from the folio to the end of the file with
one ntfs_iomap_begin() call, and for a sparse file that call allocates
the holes it maps. A page stored through a shared mapping reaches
writeback without a delayed allocation, so writing it back allocates
every cluster from that page to the end of the file. Only the page is
written, and ntfs_filemap_close() later raises the valid size over the
rest.
On a volume with 4K clusters, map a 4096-byte sparse file MAP_SHARED for
100 MiB, grow it to 100 MiB with ftruncate() and store 8 bytes at 4096:
97876 KiB are allocated instead of 8 KiB. With a 4 MiB file and the
store at 2M, the 2093056 bytes from 2M + 4K to the end of the file read
back what their clusters held before.
Map only the range being written back for a sparse file.
Fixes: 099ef9ab9203 ("fs/ntfs3: implement iomap-based file operations")
Cc: stable@vger.kernel.org
Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
---
Tested in a VM on 7.4-rc3 (20eef29b7c84), 4K and 64K clusters, with and
without delalloc, with the free space filled with a known pattern first.
The numbers in both changelogs are from 7.4-rc3 without the series.
For a sparse file, writeback now calls ntfs_iomap_begin() for each
dirty range instead of once per extent.
fs/ntfs3/inode.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c
index 45f894d182dd..535a2b0804af 100644
--- a/fs/ntfs3/inode.c
+++ b/fs/ntfs3/inode.c
@@ -1181,7 +1181,11 @@ static ssize_t ntfs_writeback_range(struct iomap_writepage_ctx *wpc,
struct ntfs_inode *ni = ntfs_i(inode);
struct ntfs_sb_info *sbi = ntfs_sb(inode->i_sb);
loff_t i_size_up = ntfs_up_cluster(sbi, inode->i_size);
- loff_t len_max = i_size_up - offset;
+ /*
+ * Map up to EOF in one go, except across the holes of a sparse
+ * file: iomap_begin() allocates what it maps there.
+ */
+ loff_t len_max = is_sparsed(ni) ? len : i_size_up - offset;
err = ni->file.run_da.count ? ni_allocate_da_blocks(ni) : 0;
base-commit: 20eef29b7c8465ac98d7dd6d6f2ac07a8d8056ca
--
2.43.0
next reply other threads:[~2026-11-20 13:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 13:36 Zhan Xusheng [this message]
2026-11-20 13:36 ` [PATCH 2/2] fs/ntfs3: zero new clusters that a write only partly covers Zhan Xusheng
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=20261120133604.427285-1-zhanxusheng1024@gmail.com \
--to=zhanxusheng1024@gmail.com \
--cc=almaz.alexandrovich@paragon-software.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ntfs3@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=zhanxusheng@xiaomi.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