* [PATCH v1 00/13] ntfs: add large folio support for ordinary files
@ 2026-12-03 4:03 Baolin Liu
2026-12-03 4:03 ` [PATCH v1 01/13] ntfs: limit writeback allocation to the dirty range Baolin Liu
` (13 more replies)
0 siblings, 14 replies; 17+ messages in thread
From: Baolin Liu @ 2026-12-03 4:03 UTC (permalink / raw)
To: linkinjeon, hyc.lee; +Cc: ntfs, linux-kernel, Baolin Liu
From: Baolin Liu <liubaolin@kylinos.cn>
This series enables large page-cache folios for ordinary, unnamed NTFS
regular-file data streams through iomap. It applies to ntfs-next at
f674e4b6c315 ("ntfs: serialize export parent reconstruction"), fetched on
26 November 2026, with no additional prerequisite patches.
Large folios require CONFIG_TRANSPARENT_HUGEPAGE; order-0 fallback remains
available. The policy excludes metadata, SYSTEM-marked files, directories,
named/internal streams, MST-protected data, encrypted files and files
already using native or WOF compression when initialized. It covers new
files, O_TMPFILE files and resident files that grow nonresident.
Empty files can change native compression while retaining their original
folio policy. Prepare compressed reads and writes for this case, including
folios spanning compression units. Retained VMAs can still read; writes
through retained shared writable VMAs fault with SIGBUS. New mmap requests
for compressed files remain unsupported.
Patches 1-8 fix writeback, cache-coherency, locking and space-accounting
issues found during validation without large folios. Patch 8 keeps 2% of
the volume, capped at 4096 clusters, for MFT, MFT bitmap and attribute-list
growth. This reduces f_bavail and data capacity, including for root, and
is separate from MFT zone placement. Patches 9-12 handle compression
switching, folio I/O and EOF within a base page. Patch 13 enables large
folios and documents the scope.
Performance measurements compare an order-0 kernel based on 8a27d1f43f1b
with a large-folio-enabled build of the same base. The setup was x86-64
KVM (2 vCPUs, 3 GiB RAM), NVMe-backed raw images on host ext4, 512-byte
NTFS clusters and 1 GiB files. fio 3.41 used one buffered psync worker,
1 MiB sequential I/O and 4 KiB random reads. Tracing was disabled during
timing.
The mixed workload used four VM boots in control/folio/folio/control
order, with five rounds per boot. Values are medians within each boot,
then medians across boots:
Metric Order-0 Large folios Change
Warm sequential read (MiB/s) 16012 18616 +16.3%
Warm random read (MiB/s) 5098 6265 +22.9%
Write + fsync (MiB/s) 2449 2691 +9.9%
mmap page-touch, 50 passes (s) 1.689 1.460 -13.6%
Cold sequential read (MiB/s) 3489 3382 -3.1%
Cold-read task CPU (s/GiB) 0.1295 0.0655 -49.4%
Write task CPU (s/GiB) 0.1550 0.0655 -57.7%
CPU figures are fio task user+system time per GiB, excluding host QEMU
CPU. A follow-up cold-read-only comparison reused the same read-only
image across eight boots (ABBA + BAAB, five rounds per boot). Throughput
was 3568 versus 3619 MiB/s (+1.4%, broadly unchanged), while task CPU
fell from 0.1260 to 0.0655 s/GiB (-48.0%). All boots, including one slow
control boot, are included. These measurements show lower task CPU cost
and gains in cached reads and writes under this VM-backed storage setup;
they do not establish a general cold-read throughput improvement.
Offline consistency checks used ntfsck from ntfsprogs-plus. The x86
guests invoked it as fsck.ntfs -n after unmounting the test volumes.
Functional and regression tests used the same source trees as this
series and its control:
- W=1 fs/ntfs builds at every patch boundary with debug and minimal
configurations; full x86-64 and ARM64 64 KiB-page kernel builds.
- x86-64 KVM: 111 data comparisons and ten offline consistency checks
passed.
- ARM64 TCG with 64 KiB base pages: 136 checks, ten compressed EOF
cases and three offline consistency checks passed; observed folio
orders 1-6.
- Six complete x86-64 KVM xfstests auto runs with identical kernel
configurations and xfstests v2025.11.04-10-gdf376ed02:
Cluster Control pass/fail/notrun Series pass/fail/notrun
512 B 306 / 45 / 212 308 / 43 / 212
4 KiB 309 / 45 / 209 309 / 45 / 209
64 KiB 307 / 45 / 211 307 / 45 / 211
The control includes patches 1-8, so the auto comparison isolates patches
9-13. All 563 selected tests completed per run, retaining the appliance's
210 default exclusions and adding none. There were no new failures or
notruns, and notrun reasons matched.
Existing failures include consistency errors reported by ntfsck on the
scratch filesystem. ARM64 testing did not cover 512 MiB PMD collapse and
still reported the existing MFT extent-record diagnostic on 512-byte
clusters. Some x86 guests reported root ext4/vda I/O errors after
power-down.
Baolin Liu (13):
ntfs: limit writeback allocation to the dirty range
ntfs: read compression units without the block device page cache
ntfs: snapshot resident data for direct reads
ntfs: allow vmalloc for large runlist backups
ntfs: preserve delalloc reservations when allocating holes
ntfs: serialize delalloc reservations with cluster allocation
ntfs: respect space reservations when writing compressed data
ntfs: keep space for MFT growth during delayed allocation
ntfs: serialize compression changes with file access
ntfs: complete compressed reads at folio granularity
ntfs: stop compressed reads at EOF within a base page
ntfs: preserve large folios during compressed writes
ntfs: enable large folios for ordinary files
Documentation/filesystems/ntfs.rst | 34 ++++
fs/ntfs/attrib.c | 15 +-
fs/ntfs/attrlist.c | 2 +-
fs/ntfs/compress.c | 317 +++++++++++++++--------------
fs/ntfs/ea.c | 7 +
fs/ntfs/file.c | 26 ++-
fs/ntfs/inode.c | 10 +
fs/ntfs/iomap.c | 43 +++-
fs/ntfs/lcnalloc.c | 18 +-
fs/ntfs/lcnalloc.h | 13 +-
fs/ntfs/mft.c | 7 +-
fs/ntfs/ntfs_codec.h | 2 +-
fs/ntfs/super.c | 18 +-
fs/ntfs/volume.h | 2 +
14 files changed, 317 insertions(+), 197 deletions(-)
base-commit: f674e4b6c315ebe742d08af80659386992d58ce9
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v1 01/13] ntfs: limit writeback allocation to the dirty range
2026-12-03 4:03 [PATCH v1 00/13] ntfs: add large folio support for ordinary files Baolin Liu
@ 2026-12-03 4:03 ` Baolin Liu
2026-12-03 4:03 ` [PATCH v1 02/13] ntfs: read compression units without the block device page cache Baolin Liu
` (12 subsequent siblings)
13 siblings, 0 replies; 17+ messages in thread
From: Baolin Liu @ 2026-12-03 4:03 UTC (permalink / raw)
To: linkinjeon, hyc.lee; +Cc: ntfs, linux-kernel, Baolin Liu
From: Baolin Liu <liubaolin@kylinos.cn>
A buffered write into a hole reserves space before copying user data.
If the copy faults partway through, writeback can allocate the clean
remainder of the reservation because it maps up to allocated_size.
After fsync and cache eviction, reads can expose old disk contents
instead of zeros. A pwritev with an inaccessible second buffer
reproduces this with order-0 folios.
Limit writeback mappings to the dirty range supplied by iomap. Zero
unwritten edges of newly allocated clusters for writeback as for direct
writes and page_mkwrite, and keep reservation accounting independent
of that zeroing.
Fixes: b041ca562526 ("ntfs: update iomap and address space operations")
Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
---
fs/ntfs/iomap.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/fs/ntfs/iomap.c b/fs/ntfs/iomap.c
index ce916707f69b..8970cadcd31e 100644
--- a/fs/ntfs/iomap.c
+++ b/fs/ntfs/iomap.c
@@ -620,7 +620,8 @@ static int ntfs_write_da_iomap_begin_non_resident(struct inode *inode,
if (balloc == true) {
if (flags & IOMAP_DIRECT ||
- ntfs_iomap_flags & NTFS_IOMAP_FLAGS_MKWRITE) {
+ ntfs_iomap_flags & (NTFS_IOMAP_FLAGS_MKWRITE |
+ NTFS_IOMAP_FLAGS_WRITEBACK)) {
loff_t end = offset + length;
if (vcn_ofs || ((vol->cluster_size > iomap->length) &&
@@ -636,7 +637,8 @@ static int ntfs_write_da_iomap_begin_non_resident(struct inode *inode,
(start_lcn + lcn_count - 1) <<
vol->cluster_size_bits,
vol->cluster_size);
- } else {
+ }
+ if (ntfs_iomap_flags & NTFS_IOMAP_FLAGS_WRITEBACK) {
if (lcn_count > ni->i_dealloc_clusters)
ni->i_dealloc_clusters = 0;
else
@@ -804,8 +806,8 @@ static ssize_t ntfs_writeback_range(struct iomap_writepage_ctx *wpc,
offset >= wpc->iomap.offset + wpc->iomap.length) {
int error;
- error = __ntfs_write_iomap_begin(wpc->inode, offset,
- NTFS_I(wpc->inode)->allocated_size - offset,
+ /* A short write may leave clean delalloc blocks after this range. */
+ error = __ntfs_write_iomap_begin(wpc->inode, offset, len,
IOMAP_WRITE, &wpc->iomap,
NTFS_IOMAP_FLAGS_WRITEBACK);
if (error)
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v1 02/13] ntfs: read compression units without the block device page cache
2026-12-03 4:03 [PATCH v1 00/13] ntfs: add large folio support for ordinary files Baolin Liu
2026-12-03 4:03 ` [PATCH v1 01/13] ntfs: limit writeback allocation to the dirty range Baolin Liu
@ 2026-12-03 4:03 ` Baolin Liu
2026-12-03 4:03 ` [PATCH v1 03/13] ntfs: snapshot resident data for direct reads Baolin Liu
` (11 subsequent siblings)
13 siblings, 0 replies; 17+ messages in thread
From: Baolin Liu @ 2026-12-03 4:03 UTC (permalink / raw)
To: linkinjeon, hyc.lee; +Cc: ntfs, linux-kernel, Baolin Liu
From: Baolin Liu <liubaolin@kylinos.cn>
Native compression writes use BIOs, but reads use the block device page
cache. After clusters are freed and reused, cached device pages can
still contain old data. A file-cache miss can then return stale contents,
as reproduced by rewriting compressed files and reusing their clusters
on an order-0 kernel.
Read compression units with ntfs_bdev_read(), bypassing the device page
cache. Read contiguous clusters within a unit together and use a NOFS
scope while holding the runlist and compression-buffer locks.
Fixes: 495e90fa3348 ("ntfs: update attrib operations")
Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
---
fs/ntfs/compress.c | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/fs/ntfs/compress.c b/fs/ntfs/compress.c
index 82c7c7d29073..8a60f5e13202 100644
--- a/fs/ntfs/compress.c
+++ b/fs/ntfs/compress.c
@@ -19,6 +19,7 @@
#include <linux/blkdev.h>
#include <linux/vmalloc.h>
#include <linux/slab.h>
+#include <linux/sched/mm.h>
#include "attrib.h"
#include "ntfs_codec.h"
@@ -495,13 +496,13 @@ int ntfs_read_compressed_block(struct folio *folio)
* guarantees of start_vcn and end_vcn, no need to round up here.
*/
unsigned int nr_pages = ntfs_cluster_to_pidx(vol, end_vcn - start_vcn);
- unsigned int xpage, max_page, cur_page, cur_ofs, i, page_ofs, page_index;
+ unsigned int xpage, max_page, cur_page, cur_ofs, i;
unsigned int cb_clusters, cb_max_ofs;
int cb_max_page, err = 0;
struct page **pages;
int *completed_pages;
unsigned char xpage_done = 0;
- struct page *lpage;
+ unsigned int nofs_flags;
ntfs_debug("Entering, page->index = 0x%lx, cb_size = 0x%x, nr_pages = %i.",
index, cb_size, nr_pages);
@@ -597,9 +598,10 @@ do_next_cb:
cb_end = cb + cb_size;
rl = NULL;
- for (vcn = start_vcn, start_vcn += cb_clusters; vcn < start_vcn;
- vcn++) {
+ for (vcn = start_vcn, start_vcn += cb_clusters; vcn < start_vcn;) {
bool is_retry = false;
+ s64 clusters;
+ size_t bytes;
if (!rl) {
lock_retry_remap:
@@ -639,22 +641,20 @@ lock_retry_remap:
goto map_rl_err;
}
- page_ofs = ntfs_cluster_to_poff(vol, lcn);
- page_index = ntfs_cluster_to_pidx(vol, lcn);
-
- lpage = read_mapping_page(sb->s_bdev->bd_mapping,
- page_index, NULL);
- if (IS_ERR(lpage)) {
- err = PTR_ERR(lpage);
+ clusters = min(rl->length - (vcn - rl->vcn), start_vcn - vcn);
+ bytes = ntfs_cluster_to_bytes(vol, clusters);
+ /* Compression writes use BIOs and do not update the bdev cache. */
+ nofs_flags = memalloc_nofs_save();
+ err = ntfs_bdev_read(sb->s_bdev, cb_pos,
+ ntfs_cluster_to_bytes(vol, lcn),
+ bytes);
+ memalloc_nofs_restore(nofs_flags);
+ if (err) {
mutex_unlock(&ntfs_cb_lock);
goto read_err;
}
-
- lock_page(lpage);
- memcpy_from_page(cb_pos, lpage, page_ofs, vol->cluster_size);
- unlock_page(lpage);
- put_page(lpage);
- cb_pos += vol->cluster_size;
+ cb_pos += bytes;
+ vcn += clusters;
}
/* Release the lock if we took it. */
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v1 03/13] ntfs: snapshot resident data for direct reads
2026-12-03 4:03 [PATCH v1 00/13] ntfs: add large folio support for ordinary files Baolin Liu
2026-12-03 4:03 ` [PATCH v1 01/13] ntfs: limit writeback allocation to the dirty range Baolin Liu
2026-12-03 4:03 ` [PATCH v1 02/13] ntfs: read compression units without the block device page cache Baolin Liu
@ 2026-12-03 4:03 ` Baolin Liu
2026-12-03 4:03 ` [PATCH v1 04/13] ntfs: allow vmalloc for large runlist backups Baolin Liu
` (10 subsequent siblings)
13 siblings, 0 replies; 17+ messages in thread
From: Baolin Liu @ 2026-12-03 4:03 UTC (permalink / raw)
To: linkinjeon, hyc.lee; +Cc: ntfs, linux-kernel, Baolin Liu
From: Baolin Liu <liubaolin@kylinos.cn>
Resident direct reads copy data to userspace while holding mrec_lock.
A user fault can acquire mmap_lock, reversing the mmap_lock ->
invalidate_lock -> mrec_lock order used by mmap and attribute operations.
Running generic/075 followed by generic/210 or generic/418 exposes this
lockdep cycle.
Copy the resident data into a temporary buffer under mrec_lock, then
release the lock before returning the direct-read mapping to iomap.
Free the snapshot in the end callback, including after failed or partial
user copies. Buffered reads retain their existing locking.
Fixes: d9e00c457d4a ("ntfs: serialize resident iomap reads with mrec_lock")
Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
---
fs/ntfs/iomap.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/fs/ntfs/iomap.c b/fs/ntfs/iomap.c
index 8970cadcd31e..8d4dc339b436 100644
--- a/fs/ntfs/iomap.c
+++ b/fs/ntfs/iomap.c
@@ -280,8 +280,22 @@ static int __ntfs_read_iomap_begin(struct inode *inode, loff_t offset, loff_t le
static int ntfs_read_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
unsigned int flags, struct iomap *iomap, struct iomap *srcmap)
{
- return __ntfs_read_iomap_begin(inode, offset, length, flags, iomap,
- srcmap, true, true);
+ struct ntfs_inode *base_ni;
+ void *data;
+ int err;
+
+ err = __ntfs_read_iomap_begin(inode, offset, length, flags, iomap,
+ srcmap, true, true);
+ if (err || !(flags & IOMAP_DIRECT) || iomap->type != IOMAP_INLINE)
+ return err;
+
+ /* Direct reads may fault on user memory; do not hold mrec_lock. */
+ base_ni = iomap->private;
+ data = kmemdup(iomap->inline_data, iomap->length, GFP_NOFS);
+ mutex_unlock(&base_ni->mrec_lock);
+ iomap->private = NULL;
+ iomap->inline_data = data;
+ return data ? 0 : -ENOMEM;
}
static int ntfs_read_iomap_end(struct inode *inode, loff_t pos, loff_t length,
@@ -291,6 +305,8 @@ static int ntfs_read_iomap_end(struct inode *inode, loff_t pos, loff_t length,
if (base_ni)
mutex_unlock(&base_ni->mrec_lock);
+ else if ((flags & IOMAP_DIRECT) && iomap->type == IOMAP_INLINE)
+ kfree(iomap->inline_data);
return written;
}
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v1 04/13] ntfs: allow vmalloc for large runlist backups
2026-12-03 4:03 [PATCH v1 00/13] ntfs: add large folio support for ordinary files Baolin Liu
` (2 preceding siblings ...)
2026-12-03 4:03 ` [PATCH v1 03/13] ntfs: snapshot resident data for direct reads Baolin Liu
@ 2026-12-03 4:03 ` Baolin Liu
2026-12-03 4:03 ` [PATCH v1 05/13] ntfs: preserve delalloc reservations when allocating holes Baolin Liu
` (9 subsequent siblings)
13 siblings, 0 replies; 17+ messages in thread
From: Baolin Liu @ 2026-12-03 4:03 UTC (permalink / raw)
To: linkinjeon, hyc.lee; +Cc: ntfs, linux-kernel, Baolin Liu
From: Baolin Liu <liubaolin@kylinos.cn>
ntfs_attr_map_cluster() backs up the runlist before merging an allocation.
With sufficient fragmentation, the backup exceeds KMALLOC_MAX_SIZE and
kmemdup() triggers an allocation warning. generic/299 with 512-byte
clusters reproduces this with both order-0 and large-folio kernels.
Use kvmemdup() because the backup need not be physically contiguous.
Both normal cleanup and rollback already support kvfree().
Fixes: 91709ba5d6d7 ("ntfs: protect runlist updates with the runlist lock")
Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
---
fs/ntfs/attrib.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c
index 6ee6b6bcac1d..17854043b716 100644
--- a/fs/ntfs/attrib.c
+++ b/fs/ntfs/attrib.c
@@ -5498,8 +5498,8 @@ int ntfs_attr_map_cluster(struct ntfs_inode *ni, s64 vcn_start, s64 *lcn_start,
lcn = rlc->lcn;
clu_count = rlc->length;
old_rl_count = ni->runlist.count;
- old_rl = kmemdup(ni->runlist.rl,
- old_rl_count * sizeof(*old_rl), GFP_NOFS);
+ old_rl = kvmemdup(ni->runlist.rl,
+ old_rl_count * sizeof(*old_rl), GFP_NOFS);
if (!old_rl) {
err = -ENOMEM;
if (ntfs_cluster_free_from_rl(vol, rlc)) {
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v1 05/13] ntfs: preserve delalloc reservations when allocating holes
2026-12-03 4:03 [PATCH v1 00/13] ntfs: add large folio support for ordinary files Baolin Liu
` (3 preceding siblings ...)
2026-12-03 4:03 ` [PATCH v1 04/13] ntfs: allow vmalloc for large runlist backups Baolin Liu
@ 2026-12-03 4:03 ` Baolin Liu
2026-12-03 4:03 ` [PATCH v1 06/13] ntfs: serialize delalloc reservations with cluster allocation Baolin Liu
` (8 subsequent siblings)
13 siblings, 0 replies; 17+ messages in thread
From: Baolin Liu @ 2026-12-03 4:03 UTC (permalink / raw)
To: linkinjeon, hyc.lee; +Cc: ntfs, linux-kernel, Baolin Liu
From: Baolin Liu <liubaolin@kylinos.cn>
ntfs_attr_map_cluster() always tells the cluster allocator to consume a
delayed-allocation reservation, including when allocating holes for direct
writes or page_mkwrite. This bypasses the space reserved for buffered
writes and releases reservations that belong to those writes.
On an order-0 kernel, buffering 1 MiB to one file and filling the volume
through direct writes to another makes the buffered file's fsync fail
with ENOSPC and loses data.
Consume a reservation only for LCN_DELALLOC runs. Hole allocations must
respect outstanding reservations.
Fixes: 495e90fa3348 ("ntfs: update attrib operations")
Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
---
fs/ntfs/attrib.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c
index 17854043b716..ea3a477c0061 100644
--- a/fs/ntfs/attrib.c
+++ b/fs/ntfs/attrib.c
@@ -5488,7 +5488,7 @@ int ntfs_attr_map_cluster(struct ntfs_inode *ni, s64 vcn_start, s64 *lcn_start,
}
rlc = ntfs_cluster_alloc(vol, vcn, clu_count, lcn_seek_from, DATA_ZONE,
- false, true, true);
+ false, true, lcn == LCN_DELALLOC);
if (IS_ERR(rlc)) {
err = PTR_ERR(rlc);
goto out;
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v1 06/13] ntfs: serialize delalloc reservations with cluster allocation
2026-12-03 4:03 [PATCH v1 00/13] ntfs: add large folio support for ordinary files Baolin Liu
` (4 preceding siblings ...)
2026-12-03 4:03 ` [PATCH v1 05/13] ntfs: preserve delalloc reservations when allocating holes Baolin Liu
@ 2026-12-03 4:03 ` Baolin Liu
2026-12-03 4:03 ` [PATCH v1 07/13] ntfs: respect space reservations when writing compressed data Baolin Liu
` (7 subsequent siblings)
13 siblings, 0 replies; 17+ messages in thread
From: Baolin Liu @ 2026-12-03 4:03 UTC (permalink / raw)
To: linkinjeon, hyc.lee; +Cc: ntfs, linux-kernel, Baolin Liu
From: Baolin Liu <liubaolin@kylinos.cn>
The cluster allocator reads free_clusters before taking lcnbmp_lock, so
competing allocators can both pass the space check using the same free
space. The buffered iomap path also checks space and records its
reservation separately. Both races can let direct writes consume space
promised to buffered writes, causing ENOSPC and data loss at writeback.
Read free_clusters under lcnbmp_lock and hold that lock while checking
and taking a delayed-allocation reservation. Wait for the initial
free-space scan before locking, and release the reservation if runlist
allocation or merging fails.
Fixes: 11ccc9107dc4 ("ntfs: update runlist handling and cluster allocator")
Fixes: b041ca562526 ("ntfs: update iomap and address space operations")
Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
---
fs/ntfs/iomap.c | 13 ++++++++++---
fs/ntfs/lcnalloc.c | 3 +--
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/fs/ntfs/iomap.c b/fs/ntfs/iomap.c
index 8d4dc339b436..b4c9e854676e 100644
--- a/fs/ntfs/iomap.c
+++ b/fs/ntfs/iomap.c
@@ -466,8 +466,16 @@ remap_rl:
if (lcn <= LCN_DELALLOC) {
if (lcn < LCN_DELALLOC) {
+ if (!NVolFreeClusterKnown(vol))
+ wait_event(vol->free_waitq,
+ NVolFreeClusterKnown(vol));
+ /* Reserve space before a competing allocator can take it. */
+ down_write(&vol->lcnbmp_lock);
max_clu_count =
ntfs_available_clusters_count(vol, max_clu_count);
+ if (max_clu_count > 0)
+ ntfs_hold_dirty_clusters(vol, max_clu_count);
+ up_write(&vol->lcnbmp_lock);
if (max_clu_count < 0) {
err = max_clu_count;
up_write(&ni->runlist.lock);
@@ -485,6 +493,7 @@ remap_rl:
rlc = kmalloc(sizeof(struct runlist_element) * 2,
GFP_NOFS);
if (!rlc) {
+ ntfs_release_dirty_clusters(vol, max_clu_count);
up_write(&ni->runlist.lock);
mutex_unlock(&mrec_ni->mrec_lock);
return -ENOMEM;
@@ -502,6 +511,7 @@ remap_rl:
&new_rl_count);
if (IS_ERR(rl)) {
ntfs_error(vol->sb, "Failed to merge runlists");
+ ntfs_release_dirty_clusters(vol, max_clu_count);
up_write(&ni->runlist.lock);
mutex_unlock(&mrec_ni->mrec_lock);
kfree(rlc);
@@ -515,9 +525,6 @@ remap_rl:
up_write(&ni->runlist.lock);
mutex_unlock(&mrec_ni->mrec_lock);
- if (lcn < LCN_DELALLOC)
- ntfs_hold_dirty_clusters(vol, max_clu_count);
-
rl_length = ntfs_cluster_to_bytes(vol, max_clu_count);
if (length > rl_length - vcn_ofs)
iomap->length = rl_length - vcn_ofs;
diff --git a/fs/ntfs/lcnalloc.c b/fs/ntfs/lcnalloc.c
index 7e00016f42ad..a4fe5077dd7f 100644
--- a/fs/ntfs/lcnalloc.c
+++ b/fs/ntfs/lcnalloc.c
@@ -219,10 +219,9 @@ struct runlist_element *ntfs_cluster_alloc(struct ntfs_volume *vol, const s64 st
if (!NVolFreeClusterKnown(vol))
wait_event(vol->free_waitq, NVolFreeClusterKnown(vol));
- free_clusters = atomic64_read(&vol->free_clusters);
-
/* Take the lcnbmp lock for writing. */
down_write(&vol->lcnbmp_lock);
+ free_clusters = atomic64_read(&vol->free_clusters);
if (is_dealloc == false)
free_clusters -= atomic64_read(&vol->dirty_clusters);
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v1 07/13] ntfs: respect space reservations when writing compressed data
2026-12-03 4:03 [PATCH v1 00/13] ntfs: add large folio support for ordinary files Baolin Liu
` (5 preceding siblings ...)
2026-12-03 4:03 ` [PATCH v1 06/13] ntfs: serialize delalloc reservations with cluster allocation Baolin Liu
@ 2026-12-03 4:03 ` Baolin Liu
2026-12-03 4:03 ` [PATCH v1 08/13] ntfs: keep space for MFT growth during delayed allocation Baolin Liu
` (6 subsequent siblings)
13 siblings, 0 replies; 17+ messages in thread
From: Baolin Liu @ 2026-12-03 4:03 UTC (permalink / raw)
To: linkinjeon, hyc.lee; +Cc: ntfs, linux-kernel, Baolin Liu
From: Baolin Liu <liubaolin@kylinos.cn>
Compressed writes allocate clusters synchronously without reserving
delayed-allocation space. Passing is_dealloc=true nevertheless bypasses
the reservation check and releases dirty_clusters for space the writer
never reserved. This can consume space promised to buffered writes.
Use a normal data allocation for compressed writes. This preserves
outstanding reservations and will also respect the metadata reserve
added next, without changing compression-unit placement or the
contiguous-allocation requirement.
Fixes: 495e90fa3348 ("ntfs: update attrib operations")
Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
---
fs/ntfs/compress.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/ntfs/compress.c b/fs/ntfs/compress.c
index 8a60f5e13202..01582f64d4c2 100644
--- a/fs/ntfs/compress.c
+++ b/fs/ntfs/compress.c
@@ -1403,8 +1403,9 @@ static int ntfs_write_cb(struct ntfs_inode *ni, loff_t pos, struct page **pages,
new_length = ntfs_bytes_to_cluster(vol, round_up(bio_size, vol->cluster_size));
+ /* Compressed writes allocate synchronously, without delalloc reservations. */
rlc = ntfs_cluster_alloc(vol, new_vcn, new_length, -1, DATA_ZONE,
- false, true, true);
+ false, true, false);
if (IS_ERR(rlc)) {
err = PTR_ERR(rlc);
goto out;
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v1 08/13] ntfs: keep space for MFT growth during delayed allocation
2026-12-03 4:03 [PATCH v1 00/13] ntfs: add large folio support for ordinary files Baolin Liu
` (6 preceding siblings ...)
2026-12-03 4:03 ` [PATCH v1 07/13] ntfs: respect space reservations when writing compressed data Baolin Liu
@ 2026-12-03 4:03 ` Baolin Liu
2026-12-03 4:03 ` [PATCH v1 09/13] ntfs: serialize compression changes with file access Baolin Liu
` (5 subsequent siblings)
13 siblings, 0 replies; 17+ messages in thread
From: Baolin Liu @ 2026-12-03 4:03 UTC (permalink / raw)
To: linkinjeon, hyc.lee; +Cc: ntfs, linux-kernel, Baolin Liu
From: Baolin Liu <liubaolin@kylinos.cn>
Delayed allocation reserves data clusters but leaves no space for the
MFT or attribute-list growth needed to describe them. Near ENOSPC,
metadata allocation can therefore fail during writeback after buffered
writes have succeeded. Separated writes on a nearly full volume
reproduce the resulting fsync failure and data loss without large folios.
Keep 2% of the volume, capped at 4096 clusters, out of new data allocations
and delayed-allocation reservations. Allow MFT, MFT bitmap and
attribute-list allocations to use this reserve while respecting
outstanding data reservations. Preserve their existing placement policy.
Exclude the reserve from f_bavail and document that data writes cannot
use it, including writes by root. This is an in-memory allocation policy,
separate from MFT zone placement, with the same sizing policy as ext4's
metadata reserve.
Fixes: b041ca562526 ("ntfs: update iomap and address space operations")
Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
---
Documentation/filesystems/ntfs.rst | 15 +++++++++++++++
fs/ntfs/attrib.c | 11 ++++++-----
fs/ntfs/attrlist.c | 2 +-
fs/ntfs/file.c | 3 ++-
fs/ntfs/lcnalloc.c | 15 ++++++++++-----
fs/ntfs/lcnalloc.h | 13 ++++++++++++-
fs/ntfs/mft.c | 7 ++++---
fs/ntfs/super.c | 18 +++++++++++++++---
fs/ntfs/volume.h | 2 ++
9 files changed, 67 insertions(+), 19 deletions(-)
diff --git a/Documentation/filesystems/ntfs.rst b/Documentation/filesystems/ntfs.rst
index 635301117807..f4c1a281f76d 100644
--- a/Documentation/filesystems/ntfs.rst
+++ b/Documentation/filesystems/ntfs.rst
@@ -11,6 +11,7 @@ The Linux NTFS filesystem driver
- Utilities support
- Linux file attributes
- Temporary files
+ - Space accounting
- Supported mount options
@@ -78,6 +79,20 @@ Named stream ioctls cannot create or open streams on an unpublished
temporary file. They can be used after the file has been linked.
+Space accounting
+================
+
+The driver keeps up to 2% of the volume, capped at 4096 clusters, available
+for growth of the MFT and attribute lists. These structures may need more
+space when delayed writes are converted into allocated extents. New file
+data allocations cannot use this reserve, including writes by root.
+
+``statfs(2)`` excludes delayed allocation reservations from ``f_bfree``
+and also excludes the metadata reserve from ``f_bavail``. The reserve is
+an allocation policy, not an on-disk allocation; it is independent of the
+placement preference controlled by ``mft_zone_multiplier``.
+
+
Supported mount options
=======================
diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c
index ea3a477c0061..4dda083598c6 100644
--- a/fs/ntfs/attrib.c
+++ b/fs/ntfs/attrib.c
@@ -2132,7 +2132,7 @@ static int __ntfs_attr_make_non_resident(struct ntfs_inode *ni, const u32 data_s
/* Start by allocating clusters to hold the attribute value. */
rl = ntfs_cluster_alloc(vol, 0,
ntfs_bytes_to_cluster(vol, new_size),
- -1, DATA_ZONE, true, false, false);
+ -1, ntfs_attr_alloc_zone(ni), true, false, false);
if (IS_ERR(rl)) {
err = PTR_ERR(rl);
ntfs_debug("Failed to allocate cluster%s, error code %i.",
@@ -4754,7 +4754,7 @@ static int ntfs_non_resident_attr_expand(struct ntfs_inode *ni, const s64 newsiz
ntfs_bytes_to_cluster(vol, ni->allocated_size),
first_free_vcn -
ntfs_bytes_to_cluster(vol, ni->allocated_size),
- lcn_seek_from, DATA_ZONE, false,
+ lcn_seek_from, ntfs_attr_alloc_zone(ni), false,
ni->type == AT_ATTRIBUTE_LIST, false);
if (IS_ERR(rl)) {
ntfs_debug("Cluster allocation failed (%lld)",
@@ -4783,7 +4783,7 @@ static int ntfs_non_resident_attr_expand(struct ntfs_inode *ni, const s64 newsiz
first_free_vcn -
ntfs_bytes_to_cluster(vol,
ni->allocated_size),
- lcn_seek_from, DATA_ZONE, false,
+ lcn_seek_from, ntfs_attr_alloc_zone(ni), false,
false, false);
if (IS_ERR(rl)) {
err = PTR_ERR(rl);
@@ -5487,8 +5487,9 @@ int ntfs_attr_map_cluster(struct ntfs_inode *ni, s64 vcn_start, s64 *lcn_start,
}
}
- rlc = ntfs_cluster_alloc(vol, vcn, clu_count, lcn_seek_from, DATA_ZONE,
- false, true, lcn == LCN_DELALLOC);
+ rlc = ntfs_cluster_alloc(vol, vcn, clu_count, lcn_seek_from,
+ ntfs_attr_alloc_zone(ni), false, true,
+ lcn == LCN_DELALLOC);
if (IS_ERR(rlc)) {
err = PTR_ERR(rlc);
goto out;
diff --git a/fs/ntfs/attrlist.c b/fs/ntfs/attrlist.c
index 7e7440c5f2ba..8a52343f0a7e 100644
--- a/fs/ntfs/attrlist.c
+++ b/fs/ntfs/attrlist.c
@@ -114,7 +114,7 @@ static int ntfs_attrlist_repack(struct inode *attr_vi,
}
/* A single run keeps the mapping pairs at the minimum size. */
- new_rl = ntfs_cluster_alloc(vol, 0, nr_clusters, -1, DATA_ZONE,
+ new_rl = ntfs_cluster_alloc(vol, 0, nr_clusters, -1, METADATA_ZONE,
true, true, false);
if (IS_ERR(new_rl)) {
err = PTR_ERR(new_rl);
diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
index 7d93a520566e..4a837c599c82 100644
--- a/fs/ntfs/file.c
+++ b/fs/ntfs/file.c
@@ -1261,7 +1261,8 @@ static int ntfs_allocate_range(struct ntfs_inode *ni, int mode, loff_t offset,
need_space = end_vcn - start_vcn;
if (need_space > 0 &&
need_space > (atomic64_read(&vol->free_clusters) -
- atomic64_read(&vol->dirty_clusters))) {
+ atomic64_read(&vol->dirty_clusters) -
+ vol->mft_reserved_clusters)) {
err = -ENOSPC;
goto out;
}
diff --git a/fs/ntfs/lcnalloc.c b/fs/ntfs/lcnalloc.c
index a4fe5077dd7f..f27223a7bb03 100644
--- a/fs/ntfs/lcnalloc.c
+++ b/fs/ntfs/lcnalloc.c
@@ -122,16 +122,18 @@ static s64 max_empty_bit_range(unsigned char *buf, int size)
* @start_vcn: vcn of the first allocated cluster
* @count: number of clusters to allocate
* @start_lcn: starting lcn at which to allocate the clusters or -1 if none
- * @zone: zone from which to allocate (MFT_ZONE or DATA_ZONE)
+ * @zone: allocation policy (MFT_ZONE, DATA_ZONE or METADATA_ZONE)
* @is_extension: if true, the caller is extending an attribute
* @is_contig: if true, require contiguous allocation
- * @is_dealloc: if true, the allocation is for deallocation purposes
+ * @is_dealloc: if true, consume an existing delayed allocation reservation
*
* Allocate @count clusters preferably starting at cluster @start_lcn or at the
* current allocator position if @start_lcn is -1, on the mounted ntfs volume
* @vol. @zone is either DATA_ZONE for allocation of normal clusters or
* MFT_ZONE for allocation of clusters for the master file table, i.e. the
- * $MFT/$DATA attribute.
+ * $MFT/$DATA attribute. METADATA_ZONE uses DATA_ZONE placement but may use
+ * the metadata reserve, as may MFT_ZONE. Neither may consume outstanding
+ * delayed allocation reservations.
*
* @start_vcn specifies the vcn of the first allocated cluster. This makes
* merging the resulting runlist with the old runlist easier.
@@ -222,8 +224,11 @@ struct runlist_element *ntfs_cluster_alloc(struct ntfs_volume *vol, const s64 st
/* Take the lcnbmp lock for writing. */
down_write(&vol->lcnbmp_lock);
free_clusters = atomic64_read(&vol->free_clusters);
- if (is_dealloc == false)
+ if (!is_dealloc) {
free_clusters -= atomic64_read(&vol->dirty_clusters);
+ if (zone == DATA_ZONE)
+ free_clusters -= vol->mft_reserved_clusters;
+ }
if (free_clusters < count) {
err = -ENOSPC;
@@ -252,7 +257,7 @@ struct runlist_element *ntfs_cluster_alloc(struct ntfs_volume *vol, const s64 st
zone_start = start_lcn;
if (zone_start < 0) {
- if (zone == DATA_ZONE)
+ if (zone != MFT_ZONE)
zone_start = vol->data1_zone_pos;
else
zone_start = vol->mft_zone_pos;
diff --git a/fs/ntfs/lcnalloc.h b/fs/ntfs/lcnalloc.h
index d9ac622e4658..8ed1427e3458 100644
--- a/fs/ntfs/lcnalloc.h
+++ b/fs/ntfs/lcnalloc.h
@@ -18,15 +18,26 @@
* FIRST_ZONE For sanity checking.
* MFT_ZONE Allocate from $MFT zone.
* DATA_ZONE Allocate from $DATA zone.
+ * METADATA_ZONE Use $DATA placement, allowing the metadata reserve.
* LAST_ZONE For sanity checking.
*/
enum {
FIRST_ZONE = 0,
MFT_ZONE = 0,
DATA_ZONE = 1,
- LAST_ZONE = 1,
+ METADATA_ZONE = 2,
+ LAST_ZONE = 2,
};
+static inline int ntfs_attr_alloc_zone(const struct ntfs_inode *ni)
+{
+ if (ni->mft_no == FILE_MFT)
+ return ni->type == AT_DATA ? MFT_ZONE : METADATA_ZONE;
+ if (ni->type == AT_ATTRIBUTE_LIST)
+ return METADATA_ZONE;
+ return DATA_ZONE;
+}
+
struct runlist_element *ntfs_cluster_alloc(struct ntfs_volume *vol,
const s64 start_vcn, const s64 count, const s64 start_lcn,
const int zone,
diff --git a/fs/ntfs/mft.c b/fs/ntfs/mft.c
index 34fccfaa11c5..7b935a1f89e3 100644
--- a/fs/ntfs/mft.c
+++ b/fs/ntfs/mft.c
@@ -1410,7 +1410,8 @@ static int ntfs_mft_bitmap_extend_allocation_nolock(struct ntfs_volume *vol)
*/
if (*b != 0xff && !(*b & tb) &&
vol->lcn_empty_bits_per_page[ll >> PAGE_SHIFT] &&
- ntfs_available_clusters_count(vol, 1) > 0) {
+ atomic64_read(&vol->free_clusters) >
+ atomic64_read(&vol->dirty_clusters)) {
/* Next cluster is free, allocate it. */
*b |= tb;
folio_mark_dirty(folio);
@@ -1432,8 +1433,8 @@ static int ntfs_mft_bitmap_extend_allocation_nolock(struct ntfs_volume *vol)
up_write(&vol->lcnbmp_lock);
alloc_cluster:
/* Allocate a cluster from the DATA_ZONE. */
- rl2 = ntfs_cluster_alloc(vol, rl[1].vcn, 1, lcn, DATA_ZONE,
- true, false, false);
+ rl2 = ntfs_cluster_alloc(vol, rl[1].vcn, 1, lcn, METADATA_ZONE,
+ true, false, false);
if (IS_ERR(rl2)) {
up_write(&mftbmp_ni->runlist.lock);
ntfs_error(vol->sb,
diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
index 39ff56cecf62..d9f3ffa66104 100644
--- a/fs/ntfs/super.c
+++ b/fs/ntfs/super.c
@@ -14,6 +14,7 @@
#include <linux/sched/mm.h>
#include <linux/fs_context.h>
#include <linux/fs_parser.h>
+#include <linux/math64.h>
#include "sysctl.h"
#include "logfile.h"
@@ -1034,6 +1035,16 @@ static void ntfs_setup_allocators(struct ntfs_volume *vol)
{
s64 mft_zone_size, mft_lcn;
+ /*
+ * Keep a bounded pool for the metadata needed to describe new runs.
+ * Delayed allocation reserves data before its mapping pairs are built;
+ * allowing data to consume all free clusters can strand those writes.
+ * Like ext4's metadata reserve, use 2% of the volume, capped at 4096
+ * clusters. This is separate from the MFT zone's placement preference.
+ */
+ vol->mft_reserved_clusters = min_t(s64, div_s64(vol->nr_clusters, 50),
+ 4096);
+
ntfs_debug("vol->mft_zone_multiplier = 0x%x",
vol->mft_zone_multiplier);
/* Determine the size of the MFT zone. */
@@ -2423,7 +2434,7 @@ s64 ntfs_available_clusters_count(struct ntfs_volume *vol, s64 nr_clusters)
wait_event(vol->free_waitq, NVolFreeClusterKnown(vol));
free_clusters = atomic64_read(&vol->free_clusters) -
- atomic64_read(&vol->dirty_clusters);
+ atomic64_read(&vol->dirty_clusters) - vol->mft_reserved_clusters;
if (free_clusters <= 0)
return -ENOSPC;
else if (free_clusters < nr_clusters)
@@ -2557,8 +2568,9 @@ static int ntfs_statfs(struct dentry *dentry, struct kstatfs *sfs)
if (size < 0LL)
size = 0LL;
- /* Free blocks avail to non-superuser, same as above on NTFS. */
- sfs->f_bavail = sfs->f_bfree = size;
+ sfs->f_bfree = size;
+ /* The metadata reserve is unavailable to file data, even for root. */
+ sfs->f_bavail = max_t(s64, size - vol->mft_reserved_clusters, 0);
/* Number of inodes in filesystem (at this point in time). */
read_lock_irqsave(&mft_ni->size_lock, flags);
diff --git a/fs/ntfs/volume.h b/fs/ntfs/volume.h
index ed5c0ccb9cd9..284c3d81aa57 100644
--- a/fs/ntfs/volume.h
+++ b/fs/ntfs/volume.h
@@ -89,6 +89,7 @@
* @bad_clusters: Number of clusters recorded in $BadClus:$Bad.
* @free_mft_records: Track the free mft records.
* @dirty_clusters: Number of clusters that are dirty.
+ * @mft_reserved_clusters: Space kept for MFT and attribute list growth.
* @sparse_compression_unit: Size of compression/sparse unit in clusters.
* @lcn_empty_bits_per_page: Number of empty bits per page in the LCN bitmap.
* @precalc_work: Work structure for background pre-calculation tasks.
@@ -163,6 +164,7 @@ struct ntfs_volume {
atomic64_t free_clusters;
atomic64_t free_mft_records;
atomic64_t dirty_clusters;
+ s64 mft_reserved_clusters;
u8 sparse_compression_unit;
unsigned int *lcn_empty_bits_per_page;
struct work_struct precalc_work;
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v1 09/13] ntfs: serialize compression changes with file access
2026-12-03 4:03 [PATCH v1 00/13] ntfs: add large folio support for ordinary files Baolin Liu
` (7 preceding siblings ...)
2026-12-03 4:03 ` [PATCH v1 08/13] ntfs: keep space for MFT growth during delayed allocation Baolin Liu
@ 2026-12-03 4:03 ` Baolin Liu
2026-12-03 4:03 ` [PATCH v1 10/13] ntfs: complete compressed reads at folio granularity Baolin Liu
` (4 subsequent siblings)
13 siblings, 0 replies; 17+ messages in thread
From: Baolin Liu @ 2026-12-03 4:03 UTC (permalink / raw)
To: linkinjeon, hyc.lee; +Cc: ntfs, linux-kernel, Baolin Liu
From: Baolin Liu <liubaolin@kylinos.cn>
An empty file can change native compression through system.ntfs_attrib
or system.ntfs_attrib_be while a VMA still references its page cache.
Serialize the attribute update with faults using the mapping invalidate
lock, and discard the old cache after a successful compression change.
Check direct-I/O eligibility under the inode lock so compression cannot
change between the check and the operation. Return SIGBUS for writes
through shared writable VMAs retained across compression enablement;
iomap must not write compressed data. Retained VMAs can still read, while
new mmap requests for compressed files remain unsupported.
Keep the mapping's folio-order limits unchanged after initialization.
Fixes: fc053f05ca28 ("ntfs: add reparse and ea operations")
Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
---
fs/ntfs/ea.c | 7 +++++++
fs/ntfs/file.c | 23 +++++++++++++++--------
2 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/fs/ntfs/ea.c b/fs/ntfs/ea.c
index 08a053be3e30..3f88baa8ff15 100644
--- a/fs/ntfs/ea.c
+++ b/fs/ntfs/ea.c
@@ -950,9 +950,16 @@ static int ntfs_setxattr(const struct xattr_handler *handler,
goto out;
if (S_ISREG(inode->i_mode)) {
+ bool compression_changed = (ni->flags ^ fattr) &
+ FILE_ATTR_COMPRESSED;
+
+ filemap_invalidate_lock(inode->i_mapping);
mutex_lock(&ni->mrec_lock);
err = ntfs_new_attr_flags(ni, fattr);
mutex_unlock(&ni->mrec_lock);
+ if (!err && compression_changed)
+ truncate_pagecache(inode, 0);
+ filemap_invalidate_unlock(inode->i_mapping);
if (err)
goto out;
}
diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
index 4a837c599c82..f78405bd373f 100644
--- a/fs/ntfs/file.c
+++ b/fs/ntfs/file.c
@@ -708,11 +708,12 @@ ssize_t ntfs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
if (NVolShutdown(NTFS_SB(sb)))
return -EIO;
- if ((NInoCompressed(NTFS_I(vi)) || NInoWofCompressed(NTFS_I(vi)) ||
- NInoEncrypted(NTFS_I(vi))) && iocb->ki_flags & IOCB_DIRECT)
- return -EOPNOTSUPP;
-
inode_lock_shared(vi);
+ if ((NInoCompressed(NTFS_I(vi)) || NInoWofCompressed(NTFS_I(vi)) ||
+ NInoEncrypted(NTFS_I(vi))) && iocb->ki_flags & IOCB_DIRECT) {
+ ret = -EOPNOTSUPP;
+ goto inode_unlock;
+ }
if (iocb->ki_flags & IOCB_DIRECT) {
size_t count = iov_iter_count(to);
@@ -867,15 +868,17 @@ ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
return -EOPNOTSUPP;
}
- if (NInoCompressed(ni) && iocb->ki_flags & IOCB_DIRECT)
- return -EOPNOTSUPP;
-
if (iocb->ki_flags & IOCB_NOWAIT) {
if (!inode_trylock(vi))
return -EAGAIN;
} else
inode_lock(vi);
+ if (NInoCompressed(ni) && iocb->ki_flags & IOCB_DIRECT) {
+ ret = -EOPNOTSUPP;
+ goto out_lock;
+ }
+
ret = generic_write_checks(iocb, from);
if (ret <= 0)
goto out_lock;
@@ -1012,7 +1015,11 @@ static vm_fault_t ntfs_filemap_page_mkwrite(struct vm_fault *vmf)
* exclusively while invalidating pagecache and changing extents.
*/
filemap_invalidate_lock_shared(mapping);
- ret = iomap_page_mkwrite(vmf, ntfs_page_mkwrite_iomap_next, NULL);
+ /* A mapping created before an empty file was made compressed survives. */
+ if (NInoCompressed(NTFS_I(inode)))
+ ret = VM_FAULT_SIGBUS;
+ else
+ ret = iomap_page_mkwrite(vmf, ntfs_page_mkwrite_iomap_next, NULL);
filemap_invalidate_unlock_shared(mapping);
sb_end_pagefault(inode->i_sb);
return ret;
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v1 10/13] ntfs: complete compressed reads at folio granularity
2026-12-03 4:03 [PATCH v1 00/13] ntfs: add large folio support for ordinary files Baolin Liu
` (8 preceding siblings ...)
2026-12-03 4:03 ` [PATCH v1 09/13] ntfs: serialize compression changes with file access Baolin Liu
@ 2026-12-03 4:03 ` Baolin Liu
2026-12-03 4:03 ` [PATCH v1 11/13] ntfs: stop compressed reads at EOF within a base page Baolin Liu
` (3 subsequent siblings)
13 siblings, 0 replies; 17+ messages in thread
From: Baolin Liu @ 2026-12-03 4:03 UTC (permalink / raw)
To: linkinjeon, hyc.lee; +Cc: ntfs, linux-kernel, Baolin Liu
From: Baolin Liu <liubaolin@kylinos.cn>
An empty file can retain its folio policy and existing VMAs when native
compression is enabled. The compression reader must therefore handle a
target folio spanning several compression units without unlocking it
after the first base page.
Read the units intersecting the target and count completed base pages,
bounded by i_size. Complete neighbouring order-0 pages independently and
leave neighbouring large folios to their own reads. Mark the target
uptodate only after all required pages complete, zero its uninitialized
tail, and unlock it once. Use common error cleanup to release neighbour
references and leave an incomplete target non-uptodate.
Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
---
fs/ntfs/compress.c | 220 +++++++++++++++++--------------------------
fs/ntfs/ntfs_codec.h | 2 +-
2 files changed, 89 insertions(+), 133 deletions(-)
diff --git a/fs/ntfs/compress.c b/fs/ntfs/compress.c
index 01582f64d4c2..0f41591db1b5 100644
--- a/fs/ntfs/compress.c
+++ b/fs/ntfs/compress.c
@@ -124,6 +124,24 @@ static inline void handle_bounds_compressed_page(struct page *page,
}
}
+/* Complete neighbouring base pages, but keep the target folio locked. */
+static void ntfs_end_compressed_page(struct page **pages, unsigned int index,
+ struct folio *target, unsigned int *nr_completed,
+ loff_t i_size, s64 initialized_size)
+{
+ struct page *page = pages[index];
+
+ handle_bounds_compressed_page(page, i_size, initialized_size);
+ if (page_folio(page) == target) {
+ (*nr_completed)++;
+ } else {
+ SetPageUptodate(page);
+ unlock_page(page);
+ put_page(page);
+ }
+ pages[index] = NULL;
+}
+
/*
* ntfs_decompress - decompress a compression block into an array of pages
* @dest_pages: destination array of pages
@@ -132,39 +150,36 @@ static inline void handle_bounds_compressed_page(struct page *page,
* @dest_ofs: current offset within @dest_pages[@dest_index] (IN/OUT)
* @dest_max_index: maximum index into @dest_pages (IN)
* @dest_max_ofs: maximum offset within @dest_pages[@dest_max_index] (IN)
- * @xpage: the target page (-1 if none) (IN)
- * @xpage_done: set to 1 if xpage was completed successfully (IN/OUT)
+ * @target: locked target folio (IN)
+ * @nr_completed: number of completed pages in @target (IN/OUT)
* @cb_start: compression block to decompress (IN)
* @cb_size: size of compression block @cb_start in bytes (IN)
* @i_size: file size when we started the read (IN)
* @initialized_size: initialized file size when we started the read (IN)
*
- * The caller must have disabled preemption. ntfs_decompress() reenables it when
- * the critical section is finished.
+ * The caller must hold ntfs_cb_lock. ntfs_decompress() releases it after
+ * it has finished accessing the shared compression buffer.
*
* This decompresses the compression block @cb_start into the array of
* destination pages @dest_pages starting at index @dest_index into @dest_pages
* and at offset @dest_pos into the page @dest_pages[@dest_index].
*
- * When the page @dest_pages[@xpage] is completed, @xpage_done is set to 1.
- * If xpage is -1 or @xpage has not been completed, @xpage_done is not modified.
+ * Completed pages in @target are counted in @nr_completed. The caller
+ * marks @target uptodate and unlocks it once all of its pages are filled.
*
* @cb_start is a pointer to the compression block which needs decompressing
* and @cb_size is the size of @cb_start in bytes (8-64kiB).
*
* Return 0 if success or -EOVERFLOW on error in the compressed stream.
- * @xpage_done indicates whether the target page (@dest_pages[@xpage]) was
- * completed during the decompression of the compression block (@cb_start).
*
* Warning: This function *REQUIRES* PAGE_SIZE >= 4096 or it will blow up
* unpredicatbly! You have been warned!
*
- * Note to hackers: This function may not sleep until it has finished accessing
- * the compression block @cb_start as it is a per-CPU buffer.
*/
static int ntfs_decompress(struct page *dest_pages[], int completed_pages[],
int *dest_index, int *dest_ofs, const int dest_max_index,
- const int dest_max_ofs, const int xpage, char *xpage_done,
+ const int dest_max_ofs, struct folio *target,
+ unsigned int *nr_completed,
u8 *const cb_start, const u32 cb_size, const loff_t i_size,
const s64 initialized_size)
{
@@ -220,20 +235,9 @@ return_error:
for (i = 0; i < nr_completed_pages; i++) {
int di = completed_pages[i];
- dp = dest_pages[di];
- /*
- * If we are outside the initialized size, zero
- * the out of bounds page range.
- */
- handle_bounds_compressed_page(dp, i_size,
- initialized_size);
- SetPageUptodate(dp);
- unlock_page(dp);
- if (di == xpage)
- *xpage_done = 1;
- else
- put_page(dp);
- dest_pages[di] = NULL;
+ ntfs_end_compressed_page(dest_pages, di, target,
+ nr_completed, i_size,
+ initialized_size);
}
}
return err;
@@ -450,7 +454,7 @@ return_overflow:
* When we are called the page has already been verified to be locked and the
* attribute is known to be non-resident, not encrypted, but compressed.
*
- * 1. Determine which compression block(s) @page is in.
+ * 1. Determine which compression block(s) @folio spans.
* 2. Get hold of all pages corresponding to this/these compression block(s).
* 3. Read the (first) compression block.
* 4. Decompress it into the corresponding pages.
@@ -485,7 +489,7 @@ int ntfs_read_compressed_block(struct folio *folio)
* The first vcn after the last wanted vcn (minimum alignment is again
* PAGE_SIZE.
*/
- s64 end_vcn = ((((s64)(index + 1UL) << PAGE_SHIFT) + cb_size - 1)
+ s64 end_vcn = ((folio_next_pos(folio) + cb_size - 1)
& ~cb_size_mask) >> vol->cluster_size_bits;
/* Number of compression blocks (cbs) in the wanted vcn range. */
unsigned int nr_cbs = ntfs_cluster_to_bytes(vol, end_vcn - start_vcn) >>
@@ -501,7 +505,7 @@ int ntfs_read_compressed_block(struct folio *folio)
int cb_max_page, err = 0;
struct page **pages;
int *completed_pages;
- unsigned char xpage_done = 0;
+ unsigned int nr_completed = 0, nr_target_pages;
unsigned int nofs_flags;
ntfs_debug("Entering, page->index = 0x%lx, cb_size = 0x%x, nr_pages = %i.",
@@ -527,12 +531,11 @@ int ntfs_read_compressed_block(struct folio *folio)
}
/*
- * We have already been given one page, this is the one we must do.
- * Once again, the alignment guarantees keep it simple.
+ * The target folio stays locked until all of its pages have been read.
+ * Neighbouring base pages can be completed independently.
*/
offset = ntfs_cluster_to_pidx(vol, start_vcn);
xpage = index - offset;
- pages[xpage] = page;
/*
* The remaining pages need to be allocated and inserted into the page
* cache, alignment guarantees keep all the below much simpler. (-8
@@ -541,34 +544,39 @@ int ntfs_read_compressed_block(struct folio *folio)
i_size = i_size_read(VFS_I(ni));
initialized_size = ni->initialized_size;
read_unlock_irqrestore(&ni->size_lock, flags);
- max_page = ((i_size + PAGE_SIZE - 1) >> PAGE_SHIFT) -
- offset;
- /* Is the page fully outside i_size? (truncate in progress) */
- if (xpage >= max_page) {
+ /* Is the folio fully outside i_size? (truncate in progress) */
+ if (folio_pos(folio) >= i_size) {
kfree(pages);
kfree(completed_pages);
- zero_user_segments(page, 0, PAGE_SIZE, 0, 0);
+ folio_zero_segment(folio, 0, folio_size(folio));
ntfs_debug("Compressed read outside i_size - truncated?");
- SetPageUptodate(page);
- unlock_page(page);
+ folio_mark_uptodate(folio);
+ folio_unlock(folio);
return 0;
}
+ max_page = ((i_size + PAGE_SIZE - 1) >> PAGE_SHIFT) - offset;
if (nr_pages < max_page)
max_page = nr_pages;
+ nr_target_pages = min_t(unsigned int, folio_nr_pages(folio),
+ max_page - xpage);
for (i = 0; i < max_page; i++, offset++) {
- if (i != xpage)
- pages[i] = grab_cache_page_nowait(mapping, offset);
+ if (folio_contains(folio, offset)) {
+ pages[i] = folio_file_page(folio, offset);
+ continue;
+ }
+ pages[i] = grab_cache_page_nowait(mapping, offset);
page = pages[i];
if (page) {
/*
* We only (re)read the page if it isn't already read
* in and/or dirty or we would be losing data or at
- * least wasting our time.
+ * least wasting our time. A neighbouring large folio needs
+ * its own complete read.
*/
- if (!PageDirty(page) && (!PageUptodate(page))) {
+ if (!folio_test_large(page_folio(page)) &&
+ !PageDirty(page) && !PageUptodate(page))
continue;
- }
unlock_page(page);
put_page(page);
pages[i] = NULL;
@@ -677,32 +685,25 @@ lock_retry_remap:
cb_max_page >>= PAGE_SHIFT;
/* Catch end of file inside a compression block. */
- if (cb_max_page > max_page)
+ if (cb_max_page > max_page) {
cb_max_page = max_page;
+ cb_max_ofs = 0;
+ }
if (vcn == start_vcn - cb_clusters) {
/* Sparse cb, zero out page range overlapping the cb. */
ntfs_debug("Found sparse compression block.");
/* We can sleep from now on, so we drop lock. */
mutex_unlock(&ntfs_cb_lock);
- if (cb_max_ofs)
- cb_max_page--;
for (; cur_page < cb_max_page; cur_page++) {
page = pages[cur_page];
if (page) {
memzero_page(page, cur_ofs, PAGE_SIZE - cur_ofs);
- SetPageUptodate(page);
- unlock_page(page);
- if (cur_page == xpage)
- xpage_done = 1;
- else
- put_page(page);
- pages[cur_page] = NULL;
+ ntfs_end_compressed_page(pages, cur_page, folio,
+ &nr_completed, i_size, initialized_size);
}
cb_pos += PAGE_SIZE - cur_ofs;
cur_ofs = 0;
- if (cb_pos >= cb_end)
- break;
}
/* If we have a partial final page, deal with it now. */
if (cb_max_ofs && cb_pos < cb_end) {
@@ -718,13 +719,9 @@ lock_retry_remap:
} else if (vcn == start_vcn) {
/* We can't sleep so we need two stages. */
unsigned int cur2_page = cur_page;
- unsigned int cur_ofs2 = cur_ofs;
- u8 *cb_pos2 = cb_pos;
ntfs_debug("Found uncompressed compression block.");
/* Uncompressed cb, copy it to the destination pages. */
- if (cb_max_ofs)
- cb_max_page--;
/* First stage: copy data into destination pages. */
for (; cur_page < cb_max_page; cur_page++) {
page = pages[cur_page];
@@ -733,8 +730,6 @@ lock_retry_remap:
PAGE_SIZE - cur_ofs);
cb_pos += PAGE_SIZE - cur_ofs;
cur_ofs = 0;
- if (cb_pos >= cb_end)
- break;
}
/* If we have a partial final page, deal with it now. */
if (cb_max_ofs && cb_pos < cb_end) {
@@ -750,34 +745,16 @@ lock_retry_remap:
/* Second stage: finalize pages. */
for (; cur2_page < cb_max_page; cur2_page++) {
page = pages[cur2_page];
- if (page) {
- /*
- * If we are outside the initialized size, zero
- * the out of bounds page range.
- */
- handle_bounds_compressed_page(page, i_size,
- initialized_size);
- SetPageUptodate(page);
- unlock_page(page);
- if (cur2_page == xpage)
- xpage_done = 1;
- else
- put_page(page);
- pages[cur2_page] = NULL;
- }
- cb_pos2 += PAGE_SIZE - cur_ofs2;
- cur_ofs2 = 0;
- if (cb_pos2 >= cb_end)
- break;
+ if (page)
+ ntfs_end_compressed_page(pages, cur2_page, folio,
+ &nr_completed, i_size, initialized_size);
}
} else {
/* Compressed cb, decompress it into the destination page(s). */
- unsigned int prev_cur_page = cur_page;
-
ntfs_debug("Found compressed compression block.");
err = ntfs_lznt1_codec_ops.decompress_pages(pages, completed_pages, &cur_page,
- &cur_ofs, cb_max_page, cb_max_ofs, xpage,
- &xpage_done, cb_pos, cb_size - (cb_pos - cb),
+ &cur_ofs, cb_max_page, cb_max_ofs, folio,
+ &nr_completed, cb_pos, cb_size - (cb_pos - cb),
i_size, initialized_size);
/*
* We can sleep from now on, lock already dropped by
@@ -785,54 +762,42 @@ lock_retry_remap:
*/
if (err) {
ntfs_error(vol->sb,
- "ntfs_decompress() failed in inode 0x%llx with error code %i. Skipping this compression block.",
+ "ntfs_decompress() failed in inode 0x%llx with error code %i.",
ni->mft_no, -err);
- /* Release the unfinished pages. */
- for (; prev_cur_page < cur_page; prev_cur_page++) {
- page = pages[prev_cur_page];
- if (page) {
- flush_dcache_page(page);
- unlock_page(page);
- if (prev_cur_page != xpage)
- put_page(page);
- pages[prev_cur_page] = NULL;
- }
- }
+ goto out;
}
}
- /* Do we have more work to do? */
- if (nr_cbs)
+ /* Stop at EOF even if the target folio spans more compression units. */
+ if (nr_cbs && cur_page < max_page)
goto do_next_cb;
- /* Clean up if we have any pages left. Should never happen. */
- for (cur_page = 0; cur_page < max_page; cur_page++) {
- page = pages[cur_page];
- if (page) {
- folio = page_folio(page);
-
- ntfs_error(vol->sb,
- "Still have pages left! Terminating them with extreme prejudice. Inode 0x%llx, page index 0x%lx.",
- ni->mft_no, folio->index);
- flush_dcache_folio(folio);
- folio_unlock(folio);
- if (cur_page != xpage)
- folio_put(folio);
- pages[cur_page] = NULL;
+out:
+ /* Only neighbouring pages hold references acquired by this read. */
+ for (i = 0; i < max_page; i++) {
+ page = pages[i];
+ if (page && page_folio(page) != folio) {
+ unlock_page(page);
+ put_page(page);
}
}
-
- /* We no longer need the list of pages. */
kfree(pages);
kfree(completed_pages);
- /* If we have completed the requested page, we return success. */
- if (likely(xpage_done))
- return 0;
+ if (nr_completed == nr_target_pages) {
+ loff_t end = min_t(loff_t, i_size, initialized_size);
+ size_t valid = clamp_t(loff_t, end - folio_pos(folio),
+ 0, folio_size(folio));
- ntfs_debug("Failed. Returning error code %s.", err == -EOVERFLOW ?
- "EOVERFLOW" : (!err ? "EIO" : "unknown error"));
- return err < 0 ? err : -EIO;
+ folio_zero_segment(folio, valid, folio_size(folio));
+ flush_dcache_folio(folio);
+ folio_mark_uptodate(folio);
+ err = 0;
+ } else if (!err) {
+ err = -EIO;
+ }
+ folio_unlock(folio);
+ return err;
map_rl_err:
ntfs_error(vol->sb, "ntfs_map_runlist() failed. Cannot read compression block.");
@@ -848,18 +813,9 @@ read_err:
ntfs_error(vol->sb, "IO error while reading compressed data.");
err_out:
- for (i = cur_page; i < max_page; i++) {
- page = pages[i];
- if (page) {
- flush_dcache_page(page);
- unlock_page(page);
- if (i != xpage)
- put_page(page);
- }
- }
- kfree(pages);
- kfree(completed_pages);
- return -EIO;
+ if (!err)
+ err = -EIO;
+ goto out;
}
/*
diff --git a/fs/ntfs/ntfs_codec.h b/fs/ntfs/ntfs_codec.h
index 6030055fb0c1..df52aeb23f95 100644
--- a/fs/ntfs/ntfs_codec.h
+++ b/fs/ntfs/ntfs_codec.h
@@ -36,7 +36,7 @@ struct ntfs_codec_ops {
int completed_pages[],
int *dest_index, int *dest_ofs,
int dest_max_index, int dest_max_ofs,
- int xpage, char *xpage_done,
+ struct folio *target, unsigned int *nr_completed,
u8 *cb_start, u32 cb_size,
loff_t i_size, s64 initialized_size);
int (*compress_subblock)(struct compress_context *pctx,
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v1 11/13] ntfs: stop compressed reads at EOF within a base page
2026-12-03 4:03 [PATCH v1 00/13] ntfs: add large folio support for ordinary files Baolin Liu
` (9 preceding siblings ...)
2026-12-03 4:03 ` [PATCH v1 10/13] ntfs: complete compressed reads at folio granularity Baolin Liu
@ 2026-12-03 4:03 ` Baolin Liu
2026-12-03 4:03 ` [PATCH v1 12/13] ntfs: preserve large folios during compressed writes Baolin Liu
` (2 subsequent siblings)
13 siblings, 0 replies; 17+ messages in thread
From: Baolin Liu @ 2026-12-03 4:03 UTC (permalink / raw)
To: linkinjeon, hyc.lee; +Cc: ntfs, linux-kernel, Baolin Liu
From: Baolin Liu <liubaolin@kylinos.cn>
With 64 KiB base pages and 512-byte clusters, a page contains eight 8 KiB
compression units. If EOF precedes the end of the page, cur_page does
not reach max_page. The reader then accesses compression units beyond
EOF and can return EIO when their runlist mapping is absent. This also
affects order-0 folios.
Stop after the compression unit containing the last file byte. If it
leaves a partial base page, zero the remainder and complete that page
before finishing the target folio. Preserve errors for missing mappings
within the file.
Fixes: 1e9ea7e04472 ("Revert "fs: Remove NTFS classic"")
Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
---
fs/ntfs/compress.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/fs/ntfs/compress.c b/fs/ntfs/compress.c
index 0f41591db1b5..1fff4fee7849 100644
--- a/fs/ntfs/compress.c
+++ b/fs/ntfs/compress.c
@@ -769,9 +769,20 @@ lock_retry_remap:
}
/* Stop at EOF even if the target folio spans more compression units. */
- if (nr_cbs && cur_page < max_page)
+ if (nr_cbs && cur_page < max_page &&
+ ntfs_cluster_to_bytes(vol, start_vcn) < i_size)
goto do_next_cb;
+ /* EOF can precede the end of a base page when cb_size < PAGE_SIZE. */
+ if (cur_ofs && cur_page < max_page) {
+ page = pages[cur_page];
+ if (page) {
+ zero_user_segment(page, cur_ofs, PAGE_SIZE);
+ ntfs_end_compressed_page(pages, cur_page, folio,
+ &nr_completed, i_size, initialized_size);
+ }
+ }
+
out:
/* Only neighbouring pages hold references acquired by this read. */
for (i = 0; i < max_page; i++) {
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v1 12/13] ntfs: preserve large folios during compressed writes
2026-12-03 4:03 [PATCH v1 00/13] ntfs: add large folio support for ordinary files Baolin Liu
` (10 preceding siblings ...)
2026-12-03 4:03 ` [PATCH v1 11/13] ntfs: stop compressed reads at EOF within a base page Baolin Liu
@ 2026-12-03 4:03 ` Baolin Liu
2026-12-03 4:03 ` [PATCH v1 13/13] ntfs: enable large folios for ordinary files Baolin Liu
2026-12-03 4:23 ` [PATCH v1 00/13] ntfs: add large folio support " liubaolin
13 siblings, 0 replies; 17+ messages in thread
From: Baolin Liu @ 2026-12-03 4:03 UTC (permalink / raw)
To: linkinjeon, hyc.lee; +Cc: ntfs, linux-kernel, Baolin Liu
From: Baolin Liu <liubaolin@kylinos.cn>
Overwriting a whole compression unit can still update only part of a
large folio. Skipping the read of a non-uptodate folio would leave the
rest of its data uninitialized.
Read such folios before updating the unit, then revalidate their mapping
and uptodate state after locking. Reuse one lock and reference for pages
in the same folio, select pages by file index, and use folio-relative
copy offsets.
Release each distinct folio once on completion or acquisition failure.
Clear uptodate for the whole folio after a failed compression write so
subsequent reads reload it from storage.
Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
---
fs/ntfs/compress.c | 55 ++++++++++++++++++++++++++++++++++++++--------
1 file changed, 46 insertions(+), 9 deletions(-)
diff --git a/fs/ntfs/compress.c b/fs/ntfs/compress.c
index 1fff4fee7849..2959a16969df 100644
--- a/fs/ntfs/compress.c
+++ b/fs/ntfs/compress.c
@@ -1435,6 +1435,35 @@ out:
return err;
}
+/* A partial compression unit must preserve the rest of a large folio. */
+static struct folio *ntfs_compress_get_folio(struct address_space *mapping,
+ pgoff_t index, bool full_cb)
+{
+ struct folio *folio;
+
+retry:
+ if (full_cb) {
+ folio = filemap_grab_folio(mapping, index);
+ if (IS_ERR(folio))
+ return folio;
+ if (!folio_test_large(folio) || folio_test_uptodate(folio))
+ return folio;
+ folio_unlock(folio);
+ folio_put(folio);
+ }
+
+ folio = read_mapping_folio(mapping, index, NULL);
+ if (IS_ERR(folio))
+ return folio;
+ folio_lock(folio);
+ if (folio->mapping != mapping || !folio_test_uptodate(folio)) {
+ folio_unlock(folio);
+ folio_put(folio);
+ goto retry;
+ }
+ return folio;
+}
+
int ntfs_compress_write(struct ntfs_inode *ni, loff_t pos, size_t count,
struct iov_iter *from)
{
@@ -1491,12 +1520,18 @@ int ntfs_compress_write(struct ntfs_inode *ni, loff_t pos, size_t count,
}
for (i = 0; i < pages_per_cb; i++) {
- if (full_cb)
- folio = filemap_grab_folio(mapping, index + i);
- else
- folio = read_mapping_folio(mapping, index + i, NULL);
+ /* Several pages of a compression unit can share one lock. */
+ if (i && folio_contains(page_folio(pages[i - 1]), index + i)) {
+ pages[i] = folio_file_page(page_folio(pages[i - 1]),
+ index + i);
+ continue;
+ }
+ folio = ntfs_compress_get_folio(mapping, index + i, full_cb);
if (IS_ERR(folio)) {
for (ip = 0; ip < i; ip++) {
+ if (ip + 1 < i && page_folio(pages[ip]) ==
+ page_folio(pages[ip + 1]))
+ continue;
folio_unlock(page_folio(pages[ip]));
folio_put(page_folio(pages[ip]));
}
@@ -1504,9 +1539,7 @@ int ntfs_compress_write(struct ntfs_inode *ni, loff_t pos, size_t count,
goto out;
}
- if (!full_cb)
- folio_lock(folio);
- pages[i] = folio_page(folio, 0);
+ pages[i] = folio_file_page(folio, index + i);
}
WARN_ON(!bytes);
@@ -1518,8 +1551,10 @@ int ntfs_compress_write(struct ntfs_inode *ni, loff_t pos, size_t count,
size_t cp, tail = PAGE_SIZE - off;
page = pages[ip];
- cp = copy_folio_from_iter_atomic(page_folio(page), off,
- min(tail, bytes), from);
+ cp = copy_folio_from_iter_atomic(page_folio(page),
+ offset_in_folio(page_folio(page),
+ pos + copied),
+ min(tail, bytes), from);
flush_dcache_page(page);
copied += cp;
@@ -1550,6 +1585,8 @@ int ntfs_compress_write(struct ntfs_inode *ni, loff_t pos, size_t count,
release_pages:
for (i = 0; i < pages_per_cb; i++) {
folio = page_folio(pages[i]);
+ if (i + 1 < pages_per_cb && folio == page_folio(pages[i + 1]))
+ continue;
if (!err) {
folio_clear_dirty(folio);
folio_mark_uptodate(folio);
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v1 13/13] ntfs: enable large folios for ordinary files
2026-12-03 4:03 [PATCH v1 00/13] ntfs: add large folio support for ordinary files Baolin Liu
` (11 preceding siblings ...)
2026-12-03 4:03 ` [PATCH v1 12/13] ntfs: preserve large folios during compressed writes Baolin Liu
@ 2026-12-03 4:03 ` Baolin Liu
2026-12-03 4:23 ` [PATCH v1 00/13] ntfs: add large folio support " liubaolin
13 siblings, 0 replies; 17+ messages in thread
From: Baolin Liu @ 2026-12-03 4:03 UTC (permalink / raw)
To: linkinjeon, hyc.lee; +Cc: ntfs, linux-kernel, Baolin Liu
From: Baolin Liu <liubaolin@kylinos.cn>
Enable large page-cache folios for ordinary, unnamed regular-file data
streams. The iomap read, readahead, buffered-write and writeback paths
already support them. Keep the minimum order at zero for base-page
fallback.
At inode initialization, exclude metadata, SYSTEM-marked files,
directories, named/internal streams, MST-protected data, encrypted files,
and files already using native or WOF compression. Newly created files,
O_TMPFILE files and resident files that grow nonresident use the same
initialization path. The preceding compression changes handle empty
files that change compression state without changing their folio policy.
Document the CONFIG_TRANSPARENT_HUGEPAGE dependency and retained-VMA
restrictions. No mount option or on-disk format change is needed.
Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
---
Documentation/filesystems/ntfs.rst | 19 +++++++++++++++++++
fs/ntfs/inode.c | 10 ++++++++++
2 files changed, 29 insertions(+)
diff --git a/Documentation/filesystems/ntfs.rst b/Documentation/filesystems/ntfs.rst
index f4c1a281f76d..31f91589bc74 100644
--- a/Documentation/filesystems/ntfs.rst
+++ b/Documentation/filesystems/ntfs.rst
@@ -12,6 +12,7 @@ The Linux NTFS filesystem driver
- Linux file attributes
- Temporary files
- Space accounting
+ - Large folios
- Supported mount options
@@ -93,6 +94,24 @@ an allocation policy, not an on-disk allocation; it is independent of the
placement preference controlled by ``mft_zone_multiplier``.
+Large folios
+============
+
+With ``CONFIG_TRANSPARENT_HUGEPAGE`` enabled, ordinary regular files support
+large page-cache folios through iomap. This includes newly created files,
+``O_TMPFILE`` files and resident files that grow into non-resident data.
+The minimum folio order remains zero; allocation may fall back to base pages.
+No mount option or on-disk format change is needed.
+
+System metadata, directories, named streams, encrypted files and files loaded
+with native or WOF compression retain their existing folio policy. Empty files
+can still switch native compression on or off through ``system.ntfs_attrib``
+or ``system.ntfs_attrib_be``. The mapping keeps its original folio order limits;
+the native compression paths also handle large folios encountered after a
+switch. Shared writable mappings created before enabling compression cannot
+write compressed data; such writes fault with ``SIGBUS``.
+
+
Supported mount options
=======================
diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c
index 4fbdcd459652..05733cda433c 100644
--- a/fs/ntfs/inode.c
+++ b/fs/ntfs/inode.c
@@ -684,6 +684,8 @@ static struct lock_class_key ntfs_dir_inval_lock_key;
void ntfs_set_vfs_operations(struct inode *inode, mode_t mode, dev_t dev)
{
+ struct ntfs_inode *ni = NTFS_I(inode);
+
if (S_ISDIR(mode)) {
if (!NInoAttr(NTFS_I(inode))) {
inode->i_op = &ntfs_dir_inode_ops;
@@ -708,6 +710,14 @@ void ntfs_set_vfs_operations(struct inode *inode, mode_t mode, dev_t dev)
else
inode->i_mapping->a_ops = &ntfs_aops;
}
+
+ /* Enable large folios only for ordinary, uncompressed data streams. */
+ if (S_ISREG(mode) && ni->type == AT_DATA && !ni->name_len &&
+ !NInoAttr(ni) && ni->mft_no >= FILE_first_user &&
+ !(ni->flags & FILE_ATTR_SYSTEM) && !NInoMstProtected(ni) &&
+ !NInoCompressed(ni) && !NInoWofCompressed(ni) &&
+ !NInoEncrypted(ni))
+ mapping_set_large_folios(inode->i_mapping);
}
static bool ntfs_non_resident_sizes_inconsistent(struct inode *vi,
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v1 00/13] ntfs: add large folio support for ordinary files
2026-12-03 4:03 [PATCH v1 00/13] ntfs: add large folio support for ordinary files Baolin Liu
` (12 preceding siblings ...)
2026-12-03 4:03 ` [PATCH v1 13/13] ntfs: enable large folios for ordinary files Baolin Liu
@ 2026-12-03 4:23 ` liubaolin
2026-12-03 5:30 ` Namjae Jeon
13 siblings, 1 reply; 17+ messages in thread
From: liubaolin @ 2026-12-03 4:23 UTC (permalink / raw)
To: linkinjeon, hyc.lee; +Cc: ntfs, linux-kernel, Baolin Liu
在 2026/12/3 12:03, Baolin Liu 写道:
> From: Baolin Liu <liubaolin@kylinos.cn>
>
> This series enables large page-cache folios for ordinary, unnamed NTFS
> regular-file data streams through iomap. It applies to ntfs-next at
> f674e4b6c315 ("ntfs: serialize export parent reconstruction"), fetched on
> 26 November 2026, with no additional prerequisite patches.
>
> Large folios require CONFIG_TRANSPARENT_HUGEPAGE; order-0 fallback remains
> available. The policy excludes metadata, SYSTEM-marked files, directories,
> named/internal streams, MST-protected data, encrypted files and files
> already using native or WOF compression when initialized. It covers new
> files, O_TMPFILE files and resident files that grow nonresident.
>
> Empty files can change native compression while retaining their original
> folio policy. Prepare compressed reads and writes for this case, including
> folios spanning compression units. Retained VMAs can still read; writes
> through retained shared writable VMAs fault with SIGBUS. New mmap requests
> for compressed files remain unsupported.
>
> Patches 1-8 fix writeback, cache-coherency, locking and space-accounting
> issues found during validation without large folios. Patch 8 keeps 2% of
> the volume, capped at 4096 clusters, for MFT, MFT bitmap and attribute-list
> growth. This reduces f_bavail and data capacity, including for root, and
> is separate from MFT zone placement. Patches 9-12 handle compression
> switching, folio I/O and EOF within a base page. Patch 13 enables large
> folios and documents the scope.
>
> Performance measurements compare an order-0 kernel based on 8a27d1f43f1b
> with a large-folio-enabled build of the same base. The setup was x86-64
> KVM (2 vCPUs, 3 GiB RAM), NVMe-backed raw images on host ext4, 512-byte
> NTFS clusters and 1 GiB files. fio 3.41 used one buffered psync worker,
> 1 MiB sequential I/O and 4 KiB random reads. Tracing was disabled during
> timing.
>
> The mixed workload used four VM boots in control/folio/folio/control
> order, with five rounds per boot. Values are medians within each boot,
> then medians across boots:
>
> Metric Order-0 Large folios Change
> Warm sequential read (MiB/s) 16012 18616 +16.3%
> Warm random read (MiB/s) 5098 6265 +22.9%
> Write + fsync (MiB/s) 2449 2691 +9.9%
> mmap page-touch, 50 passes (s) 1.689 1.460 -13.6%
> Cold sequential read (MiB/s) 3489 3382 -3.1%
> Cold-read task CPU (s/GiB) 0.1295 0.0655 -49.4%
> Write task CPU (s/GiB) 0.1550 0.0655 -57.7%
>
> CPU figures are fio task user+system time per GiB, excluding host QEMU
> CPU. A follow-up cold-read-only comparison reused the same read-only
> image across eight boots (ABBA + BAAB, five rounds per boot). Throughput
> was 3568 versus 3619 MiB/s (+1.4%, broadly unchanged), while task CPU
> fell from 0.1260 to 0.0655 s/GiB (-48.0%). All boots, including one slow
> control boot, are included. These measurements show lower task CPU cost
> and gains in cached reads and writes under this VM-backed storage setup;
> they do not establish a general cold-read throughput improvement.
>
> Offline consistency checks used ntfsck from ntfsprogs-plus. The x86
> guests invoked it as fsck.ntfs -n after unmounting the test volumes.
>
> Functional and regression tests used the same source trees as this
> series and its control:
>
> - W=1 fs/ntfs builds at every patch boundary with debug and minimal
> configurations; full x86-64 and ARM64 64 KiB-page kernel builds.
> - x86-64 KVM: 111 data comparisons and ten offline consistency checks
> passed.
> - ARM64 TCG with 64 KiB base pages: 136 checks, ten compressed EOF
> cases and three offline consistency checks passed; observed folio
> orders 1-6.
> - Six complete x86-64 KVM xfstests auto runs with identical kernel
> configurations and xfstests v2025.11.04-10-gdf376ed02:
>
> Cluster Control pass/fail/notrun Series pass/fail/notrun
> 512 B 306 / 45 / 212 308 / 43 / 212
> 4 KiB 309 / 45 / 209 309 / 45 / 209
> 64 KiB 307 / 45 / 211 307 / 45 / 211
>
> The control includes patches 1-8, so the auto comparison isolates patches
> 9-13. All 563 selected tests completed per run, retaining the appliance's
> 210 default exclusions and adding none. There were no new failures or
> notruns, and notrun reasons matched.
>
> Existing failures include consistency errors reported by ntfsck on the
> scratch filesystem. ARM64 testing did not cover 512 MiB PMD collapse and
> still reported the existing MFT extent-record diagnostic on 512-byte
> clusters. Some x86 guests reported root ext4/vda I/O errors after
> power-down.
>
> Baolin Liu (13):
> ntfs: limit writeback allocation to the dirty range
> ntfs: read compression units without the block device page cache
> ntfs: snapshot resident data for direct reads
> ntfs: allow vmalloc for large runlist backups
> ntfs: preserve delalloc reservations when allocating holes
> ntfs: serialize delalloc reservations with cluster allocation
> ntfs: respect space reservations when writing compressed data
> ntfs: keep space for MFT growth during delayed allocation
> ntfs: serialize compression changes with file access
> ntfs: complete compressed reads at folio granularity
> ntfs: stop compressed reads at EOF within a base page
> ntfs: preserve large folios during compressed writes
> ntfs: enable large folios for ordinary files
>
> Documentation/filesystems/ntfs.rst | 34 ++++
> fs/ntfs/attrib.c | 15 +-
> fs/ntfs/attrlist.c | 2 +-
> fs/ntfs/compress.c | 317 +++++++++++++++--------------
> fs/ntfs/ea.c | 7 +
> fs/ntfs/file.c | 26 ++-
> fs/ntfs/inode.c | 10 +
> fs/ntfs/iomap.c | 43 +++-
> fs/ntfs/lcnalloc.c | 18 +-
> fs/ntfs/lcnalloc.h | 13 +-
> fs/ntfs/mft.c | 7 +-
> fs/ntfs/ntfs_codec.h | 2 +-
> fs/ntfs/super.c | 18 +-
> fs/ntfs/volume.h | 2 +
> 14 files changed, 317 insertions(+), 197 deletions(-)
>
>
> base-commit: f674e4b6c315ebe742d08af80659386992d58ce9
Hi Namjae and Hyunchul,
I've posted a 13-patch series adding large folio support for ordinary
NTFS files. It covers buffered I/O and mmap for unnamed, uncompressed
data streams, while keeping order-0 fallback:
https://lore.kernel.org/all/20261203040352.1161120-1-liubaolin12138@163.com/
In my x86-64 KVM tests with NVMe-backed storage and 512-byte
clusters, warm sequential reads improved by 16.3% and warm random reads
by 22.9%. Buffered writes including fsync improved by 9.9%. fio task CPU
time per GiB also fell by about 48% for cold reads and 57.7% for writes.
I also ran kvm-xfstests auto with 512-byte, 4 KiB and 64 KiB
clusters. With the same baseline fixes in both kernels, we saw no new
failures or skips after adding large folio support. The cover letter has
the detailed results.
I also plan to work with some colleagues and friends to investigate
the existing failures and the reasons for the skipped tests.
When you have a chance, I'd appreciate your review and any suggestions.
Thanks,
Baolin.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v1 00/13] ntfs: add large folio support for ordinary files
2026-12-03 4:23 ` [PATCH v1 00/13] ntfs: add large folio support " liubaolin
@ 2026-12-03 5:30 ` Namjae Jeon
2026-12-03 10:10 ` liubaolin
0 siblings, 1 reply; 17+ messages in thread
From: Namjae Jeon @ 2026-12-03 5:30 UTC (permalink / raw)
To: liubaolin; +Cc: hyc.lee, ntfs, linux-kernel, Baolin Liu
On Thu, Dec 3, 2026 at 1:23 PM liubaolin <liubaolin12138@163.com> wrote:
>
>
>
> 在 2026/12/3 12:03, Baolin Liu 写道:
> > From: Baolin Liu <liubaolin@kylinos.cn>
> >
> > This series enables large page-cache folios for ordinary, unnamed NTFS
> > regular-file data streams through iomap. It applies to ntfs-next at
> > f674e4b6c315 ("ntfs: serialize export parent reconstruction"), fetched on
> > 26 November 2026, with no additional prerequisite patches.
> >
> > Large folios require CONFIG_TRANSPARENT_HUGEPAGE; order-0 fallback remains
> > available. The policy excludes metadata, SYSTEM-marked files, directories,
> > named/internal streams, MST-protected data, encrypted files and files
> > already using native or WOF compression when initialized. It covers new
> > files, O_TMPFILE files and resident files that grow nonresident.
> >
> > Empty files can change native compression while retaining their original
> > folio policy. Prepare compressed reads and writes for this case, including
> > folios spanning compression units. Retained VMAs can still read; writes
> > through retained shared writable VMAs fault with SIGBUS. New mmap requests
> > for compressed files remain unsupported.
> >
> > Patches 1-8 fix writeback, cache-coherency, locking and space-accounting
> > issues found during validation without large folios. Patch 8 keeps 2% of
> > the volume, capped at 4096 clusters, for MFT, MFT bitmap and attribute-list
> > growth. This reduces f_bavail and data capacity, including for root, and
> > is separate from MFT zone placement. Patches 9-12 handle compression
> > switching, folio I/O and EOF within a base page. Patch 13 enables large
> > folios and documents the scope.
> >
> > Performance measurements compare an order-0 kernel based on 8a27d1f43f1b
> > with a large-folio-enabled build of the same base. The setup was x86-64
> > KVM (2 vCPUs, 3 GiB RAM), NVMe-backed raw images on host ext4, 512-byte
> > NTFS clusters and 1 GiB files. fio 3.41 used one buffered psync worker,
> > 1 MiB sequential I/O and 4 KiB random reads. Tracing was disabled during
> > timing.
> >
> > The mixed workload used four VM boots in control/folio/folio/control
> > order, with five rounds per boot. Values are medians within each boot,
> > then medians across boots:
> >
> > Metric Order-0 Large folios Change
> > Warm sequential read (MiB/s) 16012 18616 +16.3%
> > Warm random read (MiB/s) 5098 6265 +22.9%
> > Write + fsync (MiB/s) 2449 2691 +9.9%
> > mmap page-touch, 50 passes (s) 1.689 1.460 -13.6%
> > Cold sequential read (MiB/s) 3489 3382 -3.1%
> > Cold-read task CPU (s/GiB) 0.1295 0.0655 -49.4%
> > Write task CPU (s/GiB) 0.1550 0.0655 -57.7%
> >
> > CPU figures are fio task user+system time per GiB, excluding host QEMU
> > CPU. A follow-up cold-read-only comparison reused the same read-only
> > image across eight boots (ABBA + BAAB, five rounds per boot). Throughput
> > was 3568 versus 3619 MiB/s (+1.4%, broadly unchanged), while task CPU
> > fell from 0.1260 to 0.0655 s/GiB (-48.0%). All boots, including one slow
> > control boot, are included. These measurements show lower task CPU cost
> > and gains in cached reads and writes under this VM-backed storage setup;
> > they do not establish a general cold-read throughput improvement.
> >
> > Offline consistency checks used ntfsck from ntfsprogs-plus. The x86
> > guests invoked it as fsck.ntfs -n after unmounting the test volumes.
> >
> > Functional and regression tests used the same source trees as this
> > series and its control:
> >
> > - W=1 fs/ntfs builds at every patch boundary with debug and minimal
> > configurations; full x86-64 and ARM64 64 KiB-page kernel builds.
> > - x86-64 KVM: 111 data comparisons and ten offline consistency checks
> > passed.
> > - ARM64 TCG with 64 KiB base pages: 136 checks, ten compressed EOF
> > cases and three offline consistency checks passed; observed folio
> > orders 1-6.
> > - Six complete x86-64 KVM xfstests auto runs with identical kernel
> > configurations and xfstests v2025.11.04-10-gdf376ed02:
> >
> > Cluster Control pass/fail/notrun Series pass/fail/notrun
> > 512 B 306 / 45 / 212 308 / 43 / 212
> > 4 KiB 309 / 45 / 209 309 / 45 / 209
> > 64 KiB 307 / 45 / 211 307 / 45 / 211
> >
> > The control includes patches 1-8, so the auto comparison isolates patches
> > 9-13. All 563 selected tests completed per run, retaining the appliance's
> > 210 default exclusions and adding none. There were no new failures or
> > notruns, and notrun reasons matched.
> >
> > Existing failures include consistency errors reported by ntfsck on the
> > scratch filesystem. ARM64 testing did not cover 512 MiB PMD collapse and
> > still reported the existing MFT extent-record diagnostic on 512-byte
> > clusters. Some x86 guests reported root ext4/vda I/O errors after
> > power-down.
> >
> > Baolin Liu (13):
> > ntfs: limit writeback allocation to the dirty range
> > ntfs: read compression units without the block device page cache
> > ntfs: snapshot resident data for direct reads
> > ntfs: allow vmalloc for large runlist backups
> > ntfs: preserve delalloc reservations when allocating holes
> > ntfs: serialize delalloc reservations with cluster allocation
> > ntfs: respect space reservations when writing compressed data
> > ntfs: keep space for MFT growth during delayed allocation
> > ntfs: serialize compression changes with file access
> > ntfs: complete compressed reads at folio granularity
> > ntfs: stop compressed reads at EOF within a base page
> > ntfs: preserve large folios during compressed writes
> > ntfs: enable large folios for ordinary files
> >
> > Documentation/filesystems/ntfs.rst | 34 ++++
> > fs/ntfs/attrib.c | 15 +-
> > fs/ntfs/attrlist.c | 2 +-
> > fs/ntfs/compress.c | 317 +++++++++++++++--------------
> > fs/ntfs/ea.c | 7 +
> > fs/ntfs/file.c | 26 ++-
> > fs/ntfs/inode.c | 10 +
> > fs/ntfs/iomap.c | 43 +++-
> > fs/ntfs/lcnalloc.c | 18 +-
> > fs/ntfs/lcnalloc.h | 13 +-
> > fs/ntfs/mft.c | 7 +-
> > fs/ntfs/ntfs_codec.h | 2 +-
> > fs/ntfs/super.c | 18 +-
> > fs/ntfs/volume.h | 2 +
> > 14 files changed, 317 insertions(+), 197 deletions(-)
> >
> >
> > base-commit: f674e4b6c315ebe742d08af80659386992d58ce9
>
> Hi Namjae and Hyunchul,
> I've posted a 13-patch series adding large folio support for ordinary
> NTFS files. It covers buffered I/O and mmap for unnamed, uncompressed
> data streams, while keeping order-0 fallback:
> https://lore.kernel.org/all/20261203040352.1161120-1-liubaolin12138@163.com/
Okay, could you please check Sashiko's review comments ?
https://sashiko.dev/#/patchset/20261203040352.1161120-1-liubaolin12138%40163.com
>
> In my x86-64 KVM tests with NVMe-backed storage and 512-byte
> clusters, warm sequential reads improved by 16.3% and warm random reads
> by 22.9%. Buffered writes including fsync improved by 9.9%. fio task CPU
> time per GiB also fell by about 48% for cold reads and 57.7% for writes.
> I also ran kvm-xfstests auto with 512-byte, 4 KiB and 64 KiB
> clusters. With the same baseline fixes in both kernels, we saw no new
> failures or skips after adding large folio support. The cover letter has
> the detailed results.
Thanks for the work and test:)
>
> I also plan to work with some colleagues and friends to investigate
> the existing failures and the reasons for the skipped tests.
Sounds good.
> When you have a chance, I'd appreciate your review and any suggestions.
Okay, I will check it.
Thanks!
>
> Thanks,
> Baolin.
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v1 00/13] ntfs: add large folio support for ordinary files
2026-12-03 5:30 ` Namjae Jeon
@ 2026-12-03 10:10 ` liubaolin
0 siblings, 0 replies; 17+ messages in thread
From: liubaolin @ 2026-12-03 10:10 UTC (permalink / raw)
To: Namjae Jeon; +Cc: hyc.lee, ntfs, linux-kernel, Baolin Liu
在 2026/12/3 13:30, Namjae Jeon 写道:
> On Thu, Dec 3, 2026 at 1:23 PM liubaolin <liubaolin12138@163.com> wrote:
>>
>>
>>
>> 在 2026/12/3 12:03, Baolin Liu 写道:
>>> From: Baolin Liu <liubaolin@kylinos.cn>
>>>
>>> This series enables large page-cache folios for ordinary, unnamed NTFS
>>> regular-file data streams through iomap. It applies to ntfs-next at
>>> f674e4b6c315 ("ntfs: serialize export parent reconstruction"), fetched on
>>> 26 November 2026, with no additional prerequisite patches.
>>>
>>> Large folios require CONFIG_TRANSPARENT_HUGEPAGE; order-0 fallback remains
>>> available. The policy excludes metadata, SYSTEM-marked files, directories,
>>> named/internal streams, MST-protected data, encrypted files and files
>>> already using native or WOF compression when initialized. It covers new
>>> files, O_TMPFILE files and resident files that grow nonresident.
>>>
>>> Empty files can change native compression while retaining their original
>>> folio policy. Prepare compressed reads and writes for this case, including
>>> folios spanning compression units. Retained VMAs can still read; writes
>>> through retained shared writable VMAs fault with SIGBUS. New mmap requests
>>> for compressed files remain unsupported.
>>>
>>> Patches 1-8 fix writeback, cache-coherency, locking and space-accounting
>>> issues found during validation without large folios. Patch 8 keeps 2% of
>>> the volume, capped at 4096 clusters, for MFT, MFT bitmap and attribute-list
>>> growth. This reduces f_bavail and data capacity, including for root, and
>>> is separate from MFT zone placement. Patches 9-12 handle compression
>>> switching, folio I/O and EOF within a base page. Patch 13 enables large
>>> folios and documents the scope.
>>>
>>> Performance measurements compare an order-0 kernel based on 8a27d1f43f1b
>>> with a large-folio-enabled build of the same base. The setup was x86-64
>>> KVM (2 vCPUs, 3 GiB RAM), NVMe-backed raw images on host ext4, 512-byte
>>> NTFS clusters and 1 GiB files. fio 3.41 used one buffered psync worker,
>>> 1 MiB sequential I/O and 4 KiB random reads. Tracing was disabled during
>>> timing.
>>>
>>> The mixed workload used four VM boots in control/folio/folio/control
>>> order, with five rounds per boot. Values are medians within each boot,
>>> then medians across boots:
>>>
>>> Metric Order-0 Large folios Change
>>> Warm sequential read (MiB/s) 16012 18616 +16.3%
>>> Warm random read (MiB/s) 5098 6265 +22.9%
>>> Write + fsync (MiB/s) 2449 2691 +9.9%
>>> mmap page-touch, 50 passes (s) 1.689 1.460 -13.6%
>>> Cold sequential read (MiB/s) 3489 3382 -3.1%
>>> Cold-read task CPU (s/GiB) 0.1295 0.0655 -49.4%
>>> Write task CPU (s/GiB) 0.1550 0.0655 -57.7%
>>>
>>> CPU figures are fio task user+system time per GiB, excluding host QEMU
>>> CPU. A follow-up cold-read-only comparison reused the same read-only
>>> image across eight boots (ABBA + BAAB, five rounds per boot). Throughput
>>> was 3568 versus 3619 MiB/s (+1.4%, broadly unchanged), while task CPU
>>> fell from 0.1260 to 0.0655 s/GiB (-48.0%). All boots, including one slow
>>> control boot, are included. These measurements show lower task CPU cost
>>> and gains in cached reads and writes under this VM-backed storage setup;
>>> they do not establish a general cold-read throughput improvement.
>>>
>>> Offline consistency checks used ntfsck from ntfsprogs-plus. The x86
>>> guests invoked it as fsck.ntfs -n after unmounting the test volumes.
>>>
>>> Functional and regression tests used the same source trees as this
>>> series and its control:
>>>
>>> - W=1 fs/ntfs builds at every patch boundary with debug and minimal
>>> configurations; full x86-64 and ARM64 64 KiB-page kernel builds.
>>> - x86-64 KVM: 111 data comparisons and ten offline consistency checks
>>> passed.
>>> - ARM64 TCG with 64 KiB base pages: 136 checks, ten compressed EOF
>>> cases and three offline consistency checks passed; observed folio
>>> orders 1-6.
>>> - Six complete x86-64 KVM xfstests auto runs with identical kernel
>>> configurations and xfstests v2025.11.04-10-gdf376ed02:
>>>
>>> Cluster Control pass/fail/notrun Series pass/fail/notrun
>>> 512 B 306 / 45 / 212 308 / 43 / 212
>>> 4 KiB 309 / 45 / 209 309 / 45 / 209
>>> 64 KiB 307 / 45 / 211 307 / 45 / 211
>>>
>>> The control includes patches 1-8, so the auto comparison isolates patches
>>> 9-13. All 563 selected tests completed per run, retaining the appliance's
>>> 210 default exclusions and adding none. There were no new failures or
>>> notruns, and notrun reasons matched.
>>>
>>> Existing failures include consistency errors reported by ntfsck on the
>>> scratch filesystem. ARM64 testing did not cover 512 MiB PMD collapse and
>>> still reported the existing MFT extent-record diagnostic on 512-byte
>>> clusters. Some x86 guests reported root ext4/vda I/O errors after
>>> power-down.
>>>
>>> Baolin Liu (13):
>>> ntfs: limit writeback allocation to the dirty range
>>> ntfs: read compression units without the block device page cache
>>> ntfs: snapshot resident data for direct reads
>>> ntfs: allow vmalloc for large runlist backups
>>> ntfs: preserve delalloc reservations when allocating holes
>>> ntfs: serialize delalloc reservations with cluster allocation
>>> ntfs: respect space reservations when writing compressed data
>>> ntfs: keep space for MFT growth during delayed allocation
>>> ntfs: serialize compression changes with file access
>>> ntfs: complete compressed reads at folio granularity
>>> ntfs: stop compressed reads at EOF within a base page
>>> ntfs: preserve large folios during compressed writes
>>> ntfs: enable large folios for ordinary files
>>>
>>> Documentation/filesystems/ntfs.rst | 34 ++++
>>> fs/ntfs/attrib.c | 15 +-
>>> fs/ntfs/attrlist.c | 2 +-
>>> fs/ntfs/compress.c | 317 +++++++++++++++--------------
>>> fs/ntfs/ea.c | 7 +
>>> fs/ntfs/file.c | 26 ++-
>>> fs/ntfs/inode.c | 10 +
>>> fs/ntfs/iomap.c | 43 +++-
>>> fs/ntfs/lcnalloc.c | 18 +-
>>> fs/ntfs/lcnalloc.h | 13 +-
>>> fs/ntfs/mft.c | 7 +-
>>> fs/ntfs/ntfs_codec.h | 2 +-
>>> fs/ntfs/super.c | 18 +-
>>> fs/ntfs/volume.h | 2 +
>>> 14 files changed, 317 insertions(+), 197 deletions(-)
>>>
>>>
>>> base-commit: f674e4b6c315ebe742d08af80659386992d58ce9
>>
>> Hi Namjae and Hyunchul,
>> I've posted a 13-patch series adding large folio support for ordinary
>> NTFS files. It covers buffered I/O and mmap for unnamed, uncompressed
>> data streams, while keeping order-0 fallback:
>> https://lore.kernel.org/all/20261203040352.1161120-1-liubaolin12138@163.com/
> Okay, could you please check Sashiko's review comments ?
>
> https://sashiko.dev/#/patchset/20261203040352.1161120-1-liubaolin12138%40163.com
Hi Namjae,
Sure, I'll go through Sashiko's comments, address any issues I find,
and send v2 as soon as I can.
Thanks,
Baolin.
>
>>
>> In my x86-64 KVM tests with NVMe-backed storage and 512-byte
>> clusters, warm sequential reads improved by 16.3% and warm random reads
>> by 22.9%. Buffered writes including fsync improved by 9.9%. fio task CPU
>> time per GiB also fell by about 48% for cold reads and 57.7% for writes.
>> I also ran kvm-xfstests auto with 512-byte, 4 KiB and 64 KiB
>> clusters. With the same baseline fixes in both kernels, we saw no new
>> failures or skips after adding large folio support. The cover letter has
>> the detailed results.
> Thanks for the work and test:)
>>
>> I also plan to work with some colleagues and friends to investigate
>> the existing failures and the reasons for the skipped tests.
> Sounds good.
>> When you have a chance, I'd appreciate your review and any suggestions.
> Okay, I will check it.
>
> Thanks!
>>
>> Thanks,
>> Baolin.
>>
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2026-12-03 10:10 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-03 4:03 [PATCH v1 00/13] ntfs: add large folio support for ordinary files Baolin Liu
2026-12-03 4:03 ` [PATCH v1 01/13] ntfs: limit writeback allocation to the dirty range Baolin Liu
2026-12-03 4:03 ` [PATCH v1 02/13] ntfs: read compression units without the block device page cache Baolin Liu
2026-12-03 4:03 ` [PATCH v1 03/13] ntfs: snapshot resident data for direct reads Baolin Liu
2026-12-03 4:03 ` [PATCH v1 04/13] ntfs: allow vmalloc for large runlist backups Baolin Liu
2026-12-03 4:03 ` [PATCH v1 05/13] ntfs: preserve delalloc reservations when allocating holes Baolin Liu
2026-12-03 4:03 ` [PATCH v1 06/13] ntfs: serialize delalloc reservations with cluster allocation Baolin Liu
2026-12-03 4:03 ` [PATCH v1 07/13] ntfs: respect space reservations when writing compressed data Baolin Liu
2026-12-03 4:03 ` [PATCH v1 08/13] ntfs: keep space for MFT growth during delayed allocation Baolin Liu
2026-12-03 4:03 ` [PATCH v1 09/13] ntfs: serialize compression changes with file access Baolin Liu
2026-12-03 4:03 ` [PATCH v1 10/13] ntfs: complete compressed reads at folio granularity Baolin Liu
2026-12-03 4:03 ` [PATCH v1 11/13] ntfs: stop compressed reads at EOF within a base page Baolin Liu
2026-12-03 4:03 ` [PATCH v1 12/13] ntfs: preserve large folios during compressed writes Baolin Liu
2026-12-03 4:03 ` [PATCH v1 13/13] ntfs: enable large folios for ordinary files Baolin Liu
2026-12-03 4:23 ` [PATCH v1 00/13] ntfs: add large folio support " liubaolin
2026-12-03 5:30 ` Namjae Jeon
2026-12-03 10:10 ` liubaolin
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®