[PATCH v2 02/11] iomap: add a helper to mark a range of a folio dirty
From: Ernest Borowski via B4 Relay
Date: Tue Nov 24 2026 - 17:50:26 EST
From: Ernest Borowski <ernest.borowski.git@xxxxxxxxx>
A filesystem that allocates in units larger than a block may need
writeback to write blocks that a buffered write did not copy into. ntfs
reserves whole clusters for delayed allocation, and after a short copy
into a cluster that was a hole, writeback must also write the rest of
that cluster, or the cluster shows its old contents on the disk there.
folio_mark_dirty() marks every block of the folio dirty, so the delalloc
release that follows no longer finds the clean blocks of the clusters
the write did not reach and keeps them reserved: with 1 KiB and 2 KiB
clusters, writeback then allocates a cluster that holds no data.
Add iomap_dirty_folio_range(), which marks the folio and only the blocks
covering a byte range dirty.
"ntfs: zero the rest of a new cluster after a short buffered write"
later in this series needs this, so it goes to stable with it.
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Ernest Borowski <ernest.borowski.git@xxxxxxxxx>
---
fs/iomap/buffered-io.c | 19 +++++++++++++++++++
include/linux/iomap.h | 1 +
2 files changed, 20 insertions(+)
diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 2eb8070e34..8c8851d16f 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -858,6 +858,25 @@ bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio)
}
EXPORT_SYMBOL_GPL(iomap_dirty_folio);
+/**
+ * iomap_dirty_folio_range - mark a range of a folio dirty
+ * @folio: the locked, uptodate folio
+ * @off: byte offset of the range in @folio
+ * @len: length of the range in bytes
+ *
+ * Mark the blocks that cover [@off, @off + @len) and @folio dirty, but none
+ * of the other blocks of @folio, so that writeback writes only those blocks.
+ */
+void iomap_dirty_folio_range(struct folio *folio, size_t off, size_t len)
+{
+ struct address_space *mapping = folio->mapping;
+
+ ifs_alloc(mapping->host, folio, 0);
+ iomap_set_range_dirty(folio, off, len);
+ filemap_dirty_folio(mapping, folio);
+}
+EXPORT_SYMBOL_GPL(iomap_dirty_folio_range);
+
static void
iomap_write_failed(struct inode *inode, loff_t pos, unsigned len)
{
diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index 78a1b7603a..6a6e67b87f 100644
--- a/include/linux/iomap.h
+++ b/include/linux/iomap.h
@@ -445,6 +445,7 @@ struct folio *iomap_get_folio(struct iomap_iter *iter, loff_t pos, size_t len);
bool iomap_release_folio(struct folio *folio, gfp_t gfp_flags);
void iomap_invalidate_folio(struct folio *folio, size_t offset, size_t len);
bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio);
+void iomap_dirty_folio_range(struct folio *folio, size_t off, size_t len);
void iomap_folio_mark_uptodate(struct folio *folio);
int iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len,
iomap_iter_next_fn next,
--
2.56.1