mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ernest Borowski via B4 Relay <devnull+ernest.borowski.git.proton.me@kernel.org>
To: Namjae Jeon <linkinjeon@kernel.org>,
	Hyunchul Lee <hyc.lee@gmail.com>,
	 Baolin Liu <liubaolin12138@163.com>
Cc: Christian Brauner <brauner@kernel.org>,
	Christoph Hellwig <hch@lst.de>,
	 "Darrick J. Wong" <djwong@kernel.org>,
	ntfs@lists.linux.dev,  linux-fsdevel@vger.kernel.org,
	linux-xfs@vger.kernel.org,  linux-kernel@vger.kernel.org,
	Zhan Xusheng <zhanxusheng1024@gmail.com>,
	 stable@vger.kernel.org, Baolin Liu <liubaolin@kylinos.cn>,
	 Ernest Borowski <ernest.borowski.git@proton.me>
Subject: [PATCH v5 02/13] iomap: add a helper to mark a range of a folio dirty
Date: Fri, 04 Dec 2026 19:40:33 +0100	[thread overview]
Message-ID: <20261204-b4-ntfs-delalloc-fixes-v5-2-1cd0267df2cd@proton.me> (raw)
In-Reply-To: <20261204-b4-ntfs-delalloc-fixes-v5-0-1cd0267df2cd@proton.me>

From: Ernest Borowski <ernest.borowski.git@proton.me>

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.  It and iomap_dirty_folio() share one
internal helper; iomap_dirty_folio() keeps passing the mapping it is
given, as ->dirty_folio may be called without the folio lock.

"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@vger.kernel.org
Reviewed-by: Baolin Liu <liubaolin@kylinos.cn>
Signed-off-by: Ernest Borowski <ernest.borowski.git@proton.me>
---
 fs/iomap/buffered-io.c | 32 ++++++++++++++++++++++++++------
 include/linux/iomap.h  |  1 +
 2 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 2b9bcff7ce..d505668360 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -847,15 +847,35 @@ void iomap_invalidate_folio(struct folio *folio, size_t offset, size_t len)
 }
 EXPORT_SYMBOL_GPL(iomap_invalidate_folio);
 
-bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio)
+static bool __iomap_dirty_folio_range(struct address_space *mapping,
+		struct folio *folio, size_t off, size_t len)
 {
-	struct inode *inode = mapping->host;
-	size_t len = folio_size(folio);
-
-	ifs_alloc(inode, folio, 0);
-	iomap_set_range_dirty(folio, 0, len);
+	ifs_alloc(mapping->host, folio, 0);
+	iomap_set_range_dirty(folio, off, len);
 	return filemap_dirty_folio(mapping, 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.
+ *
+ * Return: true if @folio was clean before, as filemap_dirty_folio() does.
+ */
+bool iomap_dirty_folio_range(struct folio *folio, size_t off, size_t len)
+{
+	return __iomap_dirty_folio_range(folio->mapping, folio, off, len);
+}
+EXPORT_SYMBOL_GPL(iomap_dirty_folio_range);
+
+bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio)
+{
+	return __iomap_dirty_folio_range(mapping, folio, 0, folio_size(folio));
+}
 EXPORT_SYMBOL_GPL(iomap_dirty_folio);
 
 static void
diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index 78a1b7603a..f80da4d8ff 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);
+bool 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



  parent reply	other threads:[~2026-12-04 18:40 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Ernest Borowski via B4 Relay [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204-b4-ntfs-delalloc-fixes-v5-2-1cd0267df2cd@proton.me \
    --to=devnull+ernest.borowski.git.proton.me@kernel.org \
    --cc=brauner@kernel.org \
    --cc=djwong@kernel.org \
    --cc=ernest.borowski.git@proton.me \
    --cc=hch@lst.de \
    --cc=hyc.lee@gmail.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=liubaolin12138@163.com \
    --cc=liubaolin@kylinos.cn \
    --cc=ntfs@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=zhanxusheng1024@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®