Skip to content

Commit 34ecde3

Browse files
axboebrauner
authored andcommitted
iomap: don't lose folio dropbehind state for overwrites
DONTCACHE I/O must have the completion punted to a workqueue, just like what is done for unwritten extents, as the completion needs task context to perform the invalidation of the folio(s). However, if writeback is started off filemap_fdatawrite_range() off generic_sync() and it's an overwrite, then the DONTCACHE marking gets lost as iomap_add_to_ioend() don't look at the folio being added and no further state is passed down to help it know that this is a dropbehind/DONTCACHE write. Check if the folio being added is marked as dropbehind, and set IOMAP_IOEND_DONTCACHE if that is the case. Then XFS can factor this into the decision making of completion context in xfs_submit_ioend(). Additionally include this ioend flag in the NOMERGE flags, to avoid mixing it with unrelated IO. Since this is the 3rd flag that will cause XFS to punt the completion to a workqueue, add a helper so that each one of them can get appropriately commented. This fixes extra page cache being instantiated when the write performed is an overwrite, rather than newly instantiated blocks. Fixes: b2cd5ae ("iomap: make buffered writes work with RWF_DONTCACHE") Signed-off-by: Jens Axboe <[email protected]> Link: https://lore.kernel.org/[email protected] Reviewed-by: Dave Chinner <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 5722bcd commit 34ecde3

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

fs/iomap/buffered-io.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,8 @@ static int iomap_add_to_ioend(struct iomap_writepage_ctx *wpc,
16911691
ioend_flags |= IOMAP_IOEND_UNWRITTEN;
16921692
if (wpc->iomap.flags & IOMAP_F_SHARED)
16931693
ioend_flags |= IOMAP_IOEND_SHARED;
1694+
if (folio_test_dropbehind(folio))
1695+
ioend_flags |= IOMAP_IOEND_DONTCACHE;
16941696
if (pos == wpc->iomap.offset && (wpc->iomap.flags & IOMAP_F_BOUNDARY))
16951697
ioend_flags |= IOMAP_IOEND_BOUNDARY;
16961698

fs/xfs/xfs_aops.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,25 @@ xfs_map_blocks(
436436
return 0;
437437
}
438438

439+
static bool
440+
xfs_ioend_needs_wq_completion(
441+
struct iomap_ioend *ioend)
442+
{
443+
/* Changing inode size requires a transaction. */
444+
if (xfs_ioend_is_append(ioend))
445+
return true;
446+
447+
/* Extent manipulation requires a transaction. */
448+
if (ioend->io_flags & (IOMAP_IOEND_UNWRITTEN | IOMAP_IOEND_SHARED))
449+
return true;
450+
451+
/* Page cache invalidation cannot be done in irq context. */
452+
if (ioend->io_flags & IOMAP_IOEND_DONTCACHE)
453+
return true;
454+
455+
return false;
456+
}
457+
439458
static int
440459
xfs_submit_ioend(
441460
struct iomap_writepage_ctx *wpc,
@@ -460,8 +479,7 @@ xfs_submit_ioend(
460479
memalloc_nofs_restore(nofs_flag);
461480

462481
/* send ioends that might require a transaction to the completion wq */
463-
if (xfs_ioend_is_append(ioend) ||
464-
(ioend->io_flags & (IOMAP_IOEND_UNWRITTEN | IOMAP_IOEND_SHARED)))
482+
if (xfs_ioend_needs_wq_completion(ioend))
465483
ioend->io_bio.bi_end_io = xfs_end_bio;
466484

467485
if (status)

include/linux/iomap.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,16 @@ sector_t iomap_bmap(struct address_space *mapping, sector_t bno,
377377
#define IOMAP_IOEND_BOUNDARY (1U << 2)
378378
/* is direct I/O */
379379
#define IOMAP_IOEND_DIRECT (1U << 3)
380+
/* is DONTCACHE I/O */
381+
#define IOMAP_IOEND_DONTCACHE (1U << 4)
380382

381383
/*
382384
* Flags that if set on either ioend prevent the merge of two ioends.
383385
* (IOMAP_IOEND_BOUNDARY also prevents merges, but only one-way)
384386
*/
385387
#define IOMAP_IOEND_NOMERGE_FLAGS \
386-
(IOMAP_IOEND_SHARED | IOMAP_IOEND_UNWRITTEN | IOMAP_IOEND_DIRECT)
388+
(IOMAP_IOEND_SHARED | IOMAP_IOEND_UNWRITTEN | IOMAP_IOEND_DIRECT | \
389+
IOMAP_IOEND_DONTCACHE)
387390

388391
/*
389392
* Structure for writeback I/O completions.

0 commit comments

Comments
 (0)