mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v5 00/13] ntfs: delayed allocation accounting and stale data fixes, part 1
@ 2026-12-04 18:40 Ernest Borowski via B4 Relay
  2026-12-04 18:40 ` [PATCH v5 01/13] iomap: punch out a run of clean blocks in one call Ernest Borowski via B4 Relay
                   ` (12 more replies)
  0 siblings, 13 replies; 15+ messages in thread
From: Ernest Borowski via B4 Relay @ 2026-12-04 18:40 UTC (permalink / raw)
  To: Namjae Jeon, Hyunchul Lee, Baolin Liu
  Cc: Christian Brauner, Christoph Hellwig, Darrick J. Wong, ntfs,
	linux-fsdevel, linux-xfs, linux-kernel, Zhan Xusheng, stable,
	Ernest Borowski, Baolin Liu

ntfs did not give back its delayed allocation reservations
(vol->dirty_clusters) on several paths.  Under a write, truncate and
punch-hole stress test on a 128 MiB volume, the free space statfs()
reports fell from 79 MB to zero in 80 seconds, and writes then failed
with ENOSPC, while $Bitmap stayed correct.  The same paths let buffered
writes into holes show old disk contents.

What each patch does:

   1  iomap: pass each run of clean blocks to ->punch() in one call, so
      ntfs can release a cluster smaller than a folio
   2  iomap: add iomap_dirty_folio_range(), used by patch 10
   3  release the reservations that truncate cuts off
   4  do not consume reservations when fallocate(), direct I/O or
      page_mkwrite() fill a hole
   5  keep the reservations when a cluster allocation fails
   6  release the reservations of an evicted inode or removed stream
   7  do not turn a delalloc run into real clusters when it is split
   8  punch out the clusters a failed buffered write did not use
   9  keep zeroing a new cluster's edges when writeback allocates it
  10  zero the rest of a new cluster after a short copy
  11  read, do not zero, blocks whose cluster a write fault or
      writeback allocated during the copy
  12  zero a write fault's new cluster before the runlist shows it
  13  at writeback, allocate only the clusters of dirty folios

For XFS and ext4, patch 1 only means fewer ->punch() calls, and patch 2
changes nothing.  All patches are Cc stable.

Dependencies (an arrow points to the patch that needs it):

  3 --> 6 --> 8 --> 9 --> 10 <-- 2
              ^     |
              1     +--> 11
  4 --> 5
  12 --> 13
  7

The series applies to ntfs-next of
git://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/ntfs.git at
94ebffe9b5d7, not to master or linux-next.  To get it:

  git fetch https://github.com/xerrni/linux.git ntfs-delalloc-fixes-v5
  git log --oneline 94ebffe9b5d7..FETCH_HEAD

or, on that ntfs-next commit, "b4 shazam" with this message's
Message-ID.

Patch 10 uses ntfs_zero_range_unkillable() from Zhan Xusheng's short
write fix [1], which is in ntfs-next.  Part 2 follows with three
patches: st_blocks of delalloc data and of named streams, and stale data
from direct I/O into holes.

Each bug has a reproducer that fails before its fix and passes after
it: QEMU, a kernel with KASAN, lockdep and UBSAN, clusters from 512 B to
64 KiB, ntfsck -n after every case, Ubuntu 26.04 and Arch Linux.  With
this series all of them pass except the st_blocks check of
delalloc_alloc_failure and the direct I/O case of hole_fill_stale, which
part 2 fixes.  Every test that passed before still passes.

  tests:                    https://github.com/xerrni/linux-ntfs
  ntfs-next:                https://github.com/xerrni/linux-ntfs/actions/runs/47382059705
  ntfs-next + this series:  https://github.com/xerrni/linux-ntfs/actions/runs/47382064876

[1] https://lore.kernel.org/all/20261127031053.3695758-1-zhanxusheng1024@gmail.com/
[2] https://lore.kernel.org/all/20261203040352.1161120-2-liubaolin12138@163.com/
[3] https://github.com/xerrni/linux-ntfs/actions/runs/47389279532 (patch 13)
    https://github.com/xerrni/linux-ntfs/actions/runs/47389286024 ([2])

---
Changes in v5:
- Patch 1: also leave the clean blocks at the end of the scanned part of
  a folio to the next punch.  v4 split a clean 1 KiB cluster at EOF into
  two ->punch() calls, so a failed or short write next to EOF kept one
  cluster reserved.  New reproducer: delalloc_leak_edges.
- Patch 8: when a failed write's rollback keeps the allocation for a
  FALLOC_FL_KEEP_SIZE preallocation, also punch out the write's delalloc
  clusters past the new size.  New reproducer: delalloc_leak_edges.
- Patch 10: while the rest of the cluster is still delalloc, zero it
  instead of dirtying the cached folios as they are (Hyunchul).
- New patches 12 and 13, moved here from part 2.  They close the stale
  data window that patch 10 leaves when writeback or a write fault
  allocates a cluster during a short copy.  New reproducer:
  killed_short_write_wb.
- Patch 13 rather than Baolin Liu's "ntfs: limit writeback allocation to
  the dirty range" [2], which fixes the same bug: with 64 KiB clusters
  fsync() of 384 MiB takes 110-120 ms with patch 13 and 242-260 ms with
  [2], 3 runs each [3].
- Dropped Baolin Liu's Reviewed-by from patches 1, 8 and 10, whose code
  changed.
- fstests on XFS and ext4 still give the same results with and without
  patches 1 and 2:
    https://github.com/xerrni/linux-ntfs/actions/runs/47041482649
    https://github.com/xerrni/linux-ntfs/actions/runs/47041496050
- Rebased onto ntfs-next 94ebffe9b5d7.  ntfs-next was rebased after v4,
  so v4's base is gone from it (Christoph).
- Link to v4: https://patch.msgid.link/20261201-b4-ntfs-delalloc-fixes-v4-0-e5dd6f77016a@proton.me

Changes in v4:
- Patch 10: when zeroing the rest of the cluster fails, also record
  the error with mapping_set_error(), so that fsync() reports it
  (Baolin Liu).  New reproducer: delalloc_tail_zero_failure.
- Patch 10: use ntfs_zero_range_unkillable() from [1] instead of a
  second copy of it, with the lockdep check of the invalidate lock
  that the copy had.
- Rebased onto ntfs-next 329758f9d73b, which adds [1], with no
  conflicts.
- Link to v3: https://patch.msgid.link/20261130-b4-ntfs-delalloc-fixes-v3-0-874d34a6f1fe@proton.me

Changes in v3:
- Patch 1: split an overlong line by storing the punch start in a local
  variable (Christoph).
- Patch 2: iomap_dirty_folio() now calls the same helper as
  iomap_dirty_folio_range() instead of duplicating its code;
  iomap_dirty_folio() still passes the mapping argument it receives,
  since ->dirty_folio can run without the folio lock (Christoph).
- Rebased onto ntfs-next 0d9dc4ba9089, which is based on v7.4-rc4, with
  no conflicts.  The new base includes 6fe08320c3 ("iomap: don't punch
  delalloc under a dirty EOF block"), which touches the same function
  as patch 1; that commit does not affect ntfs, since ntfs's ->punch()
  keeps every partly punched cluster.
- The tests ran on ntfs-next 1975aab5bdb0, which differs from the new
  base only by f11d0178f3 ("ntfs: avoid lock inversion when stream base
  is the containing directory").
- fstests on XFS and ext4 (buffered_iomap) with 1k and 4k blocks give
  the same results with and without patches 1 and 2: XFS passes 156
  (1k) and 158 (4k) tests, ext4 passes 97 (1k) and 99 (4k).  The only
  failure is generic/223 on ext4 with both block sizes, which also
  fails without the patches.
- [1] now points to v12 of Zhan Xusheng's short write fix.
- Link to v2: https://patch.msgid.link/20261124-b4-ntfs-delalloc-fixes-v2-0-f394c800ec03@proton.me

Changes in v2:
- New patch 1 (iomap): one ->punch() call per run of clean blocks, so
  that 1 KiB and 2 KiB clusters of a dirty folio are released after a
  failed or short write (Hyunchul).
- New patch 2 (iomap) and patch 10 (was 7): after a short copy, dirty
  only the rest of the cluster, so the clusters the write did not reach
  in the same folio are still released.
- New patch 5, moved here from part 2: keep the reservations when a
  cluster allocation fails, instead of resetting every file's
  reservation or leaving a delalloc run with none (Hyunchul's question
  on v1 patch 1).
- New patch 11: revalidate the delalloc mapping when a write fault or
  writeback allocated its clusters during the copy, instead of zeroing
  data written through a shared mapping (Hyunchul).
- Patches 3-4 and 6-9 are v1 patches 1-6, unchanged.
- Cc the iomap maintainers and lists for patches 1 and 2.
- Link to v1: https://patch.msgid.link/20261122-b4-ntfs-delalloc-fixes-v1-0-0726f0dce403@proton.me

---
Ernest Borowski (13):
      iomap: punch out a run of clean blocks in one call
      iomap: add a helper to mark a range of a folio dirty
      ntfs: release delalloc reservations cut off by truncate
      ntfs: do not consume delalloc reservations when filling holes
      ntfs: keep delalloc reservations when a cluster allocation fails
      ntfs: release the delalloc reservations of an evicted inode
      ntfs: do not shift the cluster number of a delalloc run on split
      ntfs: punch out the delalloc reservation of a failed buffered write
      ntfs: zero new delalloc clusters even when writeback allocates them
      ntfs: zero the rest of a new cluster after a short buffered write
      ntfs: revalidate a buffered write's mapping after its clusters were allocated
      ntfs: zero a write fault's new cluster before the runlist shows it
      ntfs: allocate delalloc clusters at writeback only for dirty folios

 fs/iomap/buffered-io.c | 114 ++++++-----
 fs/ntfs/attrib.c       | 158 +++++++++++++++-
 fs/ntfs/attrib.h       |   5 +-
 fs/ntfs/file.c         |  34 +++-
 fs/ntfs/inode.c        |  15 +-
 fs/ntfs/inode.h        |   9 +
 fs/ntfs/iomap.c        | 502 +++++++++++++++++++++++++++++++++++++++++--------
 fs/ntfs/iomap.h        |   1 +
 fs/ntfs/lcnalloc.c     |   1 -
 fs/ntfs/runlist.c      |  13 +-
 include/linux/iomap.h  |   1 +
 11 files changed, 715 insertions(+), 138 deletions(-)
---
base-commit: 94ebffe9b5d71d008bff5ff3c202d4980a6f2a55
change-id: 20261122-b4-ntfs-delalloc-fixes-5ba9d4e97353

Best regards,
--  
Ernest Borowski <ernest.borowski.git@proton.me>



^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2026-12-05 13:42 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-04 18:40 [PATCH v5 00/13] ntfs: delayed allocation accounting and stale data fixes, part 1 Ernest Borowski via B4 Relay
2026-12-04 18:40 ` [PATCH v5 01/13] iomap: punch out a run of clean blocks in one call Ernest Borowski via B4 Relay
2026-12-04 18:40 ` [PATCH v5 02/13] iomap: add a helper to mark a range of a folio dirty Ernest Borowski via B4 Relay
2026-12-04 18:40 ` [PATCH v5 03/13] ntfs: release delalloc reservations cut off by truncate Ernest Borowski via B4 Relay
2026-12-04 18:40 ` [PATCH v5 04/13] ntfs: do not consume delalloc reservations when filling holes Ernest Borowski via B4 Relay
2026-12-04 18:40 ` [PATCH v5 05/13] ntfs: keep delalloc reservations when a cluster allocation fails Ernest Borowski via B4 Relay
2026-12-04 18:40 ` [PATCH v5 06/13] ntfs: release the delalloc reservations of an evicted inode Ernest Borowski via B4 Relay
2026-12-04 18:40 ` [PATCH v5 07/13] ntfs: do not shift the cluster number of a delalloc run on split Ernest Borowski via B4 Relay
2026-12-04 18:40 ` [PATCH v5 08/13] ntfs: punch out the delalloc reservation of a failed buffered write Ernest Borowski via B4 Relay
2026-12-04 18:40 ` [PATCH v5 09/13] ntfs: zero new delalloc clusters even when writeback allocates them Ernest Borowski via B4 Relay
2026-12-04 18:40 ` [PATCH v5 10/13] ntfs: zero the rest of a new cluster after a short buffered write Ernest Borowski via B4 Relay
2026-12-04 18:40 ` [PATCH v5 11/13] ntfs: revalidate a buffered write's mapping after its clusters were allocated Ernest Borowski via B4 Relay
2026-12-04 18:40 ` [PATCH v5 12/13] ntfs: zero a write fault's new cluster before the runlist shows it Ernest Borowski via B4 Relay
2026-12-04 18:40 ` [PATCH v5 13/13] ntfs: allocate delalloc clusters at writeback only for dirty folios Ernest Borowski via B4 Relay
2026-12-05 13:42   ` 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®