Re: [PATCH v4 10/11] ntfs: zero the rest of a new cluster after a short buffered write
From: Hyunchul Lee
Date: Thu Dec 03 2026 - 20:06:07 EST
Hi Ernest,
> +/*
> + * Make writeback write all of [start, end), the rest of a cluster that was a
> + * hole and that a short buffered write filled only in part. Folios in the
> + * page cache keep their contents (the zeroes __iomap_write_begin() put
> + * there, or data an mmap write added meanwhile), and only their blocks in
> + * the range are dirtied: other clean blocks of the folio may be holes, or
> + * delalloc clusters the write did not reach, which the caller punches out.
> + * The rest of the range is zeroed only while the cluster is still delalloc:
> + * once a write fault or writeback has allocated it, what an mmap write put
> + * there since may be on the disk only, and zeroing the page cache would
> + * overwrite it. The caller holds the invalidate lock.
> + */
> +static int ntfs_dirty_cluster_tail(struct inode *inode, loff_t start,
> + loff_t end)
> +{
> + struct folio *folio;
> + loff_t next;
> + int err = 0;
> +
> + lockdep_assert_held_write(&inode->i_mapping->invalidate_lock);
> + while (!err && start < end) {
> + folio = filemap_lock_folio(inode->i_mapping,
> + start >> PAGE_SHIFT);
> + if (IS_ERR(folio)) {
> + next = min_t(loff_t, round_up(start + 1, PAGE_SIZE),
> + end);
> + if (ntfs_pos_is_delalloc(inode, start))
> + err = ntfs_zero_range_unkillable(inode, start,
> + next - start);
> + } else {
> + bool uptodate = folio_test_uptodate(folio);
> + size_t off = offset_in_folio(folio, start);
> +
> + next = min_t(loff_t, folio_pos(folio) +
> + folio_size(folio), end);
> + if (uptodate)
> + iomap_dirty_folio_range(folio, off,
> + next - start);
Instead of marking this range dirty directly, how about zeroing it with
iomap_zero_range()? __iomap_write_end() marks exactly the zeroed range
dirty.
if (ntfs_pos_is_delalloc(inode, start)) {
ntfs_zero_range_unkillable(...)
continue;
}
folio = filemap_lock_folio(...)
if (IS_ERR(folio))
continue;
if (folio_test_uptodate(folio))
folio_mark_dirty(folio);
...
> + folio_unlock(folio);
> + folio_put(folio);
> + if (!uptodate && ntfs_pos_is_delalloc(inode, start))
> + err = ntfs_zero_range_unkillable(inode, start,
> + next - start);
> + }
> + start = next;
> + }
> + return err;
> +}
> +
--
Thanks,
Hyunchul