Skip to content

Commit b194bc4

Browse files
axboebrauner
authored andcommitted
iomap: make buffered writes work with RWF_DONTCACHE
Add iomap buffered write support for RWF_DONTCACHE. If RWF_DONTCACHE is set for a write, mark the folios being written as uncached. Then writeback completion will drop the pages. The write_iter handler simply kicks off writeback for the pages, and writeback completion will take care of the rest. Signed-off-by: "Darrick J. Wong" <djwong@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk> Link: https://lore.kernel.org/r/20250204184047.356762-2-axboe@kernel.dk Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 53cfafd commit b194bc4

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

Documentation/filesystems/iomap/design.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,11 @@ operations:
356356
``IOMAP_NOWAIT`` is often set on behalf of ``IOCB_NOWAIT`` or
357357
``RWF_NOWAIT``.
358358

359+
* ``IOMAP_DONTCACHE`` is set when the caller wishes to perform a
360+
buffered file I/O and would like the kernel to drop the pagecache
361+
after the I/O completes, if it isn't already being used by another
362+
thread.
363+
359364
If it is necessary to read existing file contents from a `different
360365
<https://lore.kernel.org/all/20191008071527.29304-9-hch@lst.de/>`_
361366
device or address range on a device, the filesystem should return that

Documentation/filesystems/iomap/operations.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ These ``struct kiocb`` flags are significant for buffered I/O with iomap:
131131

132132
* ``IOCB_NOWAIT``: Turns on ``IOMAP_NOWAIT``.
133133

134+
* ``IOCB_DONTCACHE``: Turns on ``IOMAP_DONTCACHE``.
135+
134136
Internal per-Folio State
135137
------------------------
136138

fs/iomap/buffered-io.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ struct folio *iomap_get_folio(struct iomap_iter *iter, loff_t pos, size_t len)
594594

595595
if (iter->flags & IOMAP_NOWAIT)
596596
fgp |= FGP_NOWAIT;
597+
if (iter->flags & IOMAP_DONTCACHE)
598+
fgp |= FGP_DONTCACHE;
597599
fgp |= fgf_set_order(len);
598600

599601
return __filemap_get_folio(iter->inode->i_mapping, pos >> PAGE_SHIFT,
@@ -1019,6 +1021,8 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i,
10191021

10201022
if (iocb->ki_flags & IOCB_NOWAIT)
10211023
iter.flags |= IOMAP_NOWAIT;
1024+
if (iocb->ki_flags & IOCB_DONTCACHE)
1025+
iter.flags |= IOMAP_DONTCACHE;
10221026

10231027
while ((ret = iomap_iter(&iter, ops)) > 0)
10241028
iter.status = iomap_write_iter(&iter, i);

include/linux/iomap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ struct iomap_folio_ops {
190190
#define IOMAP_DAX 0
191191
#endif /* CONFIG_FS_DAX */
192192
#define IOMAP_ATOMIC (1 << 9)
193+
#define IOMAP_DONTCACHE (1 << 10)
193194

194195
struct iomap_ops {
195196
/*

0 commit comments

Comments
 (0)