Skip to content

Commit 3a0be38

Browse files
committed
iomap: treat a write through cache the same as FUA
Whether we have a write back cache and are using FUA or don't have a write back cache at all is the same situation. Treat them the same. This makes the IOMAP_DIO_WRITE_FUA name a bit misleading, as we have two cases that provide stable writes: 1) Volatile write cache with FUA writes 2) Normal write without a volatile write cache Rename that flag to IOMAP_DIO_STABLE_WRITE to make that clearer, and update some of the FUA comments as well. Reviewed-by: Darrick J. Wong <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Dave Chinner <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 44842f6 commit 3a0be38

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

fs/iomap/direct-io.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* Private flags for iomap_dio, must not overlap with the public ones in
2121
* iomap.h:
2222
*/
23-
#define IOMAP_DIO_WRITE_FUA (1U << 28)
23+
#define IOMAP_DIO_WRITE_THROUGH (1U << 28)
2424
#define IOMAP_DIO_NEED_SYNC (1U << 29)
2525
#define IOMAP_DIO_WRITE (1U << 30)
2626
#define IOMAP_DIO_DIRTY (1U << 31)
@@ -219,7 +219,7 @@ static void iomap_dio_zero(const struct iomap_iter *iter, struct iomap_dio *dio,
219219
/*
220220
* Figure out the bio's operation flags from the dio request, the
221221
* mapping, and whether or not we want FUA. Note that we can end up
222-
* clearing the WRITE_FUA flag in the dio request.
222+
* clearing the WRITE_THROUGH flag in the dio request.
223223
*/
224224
static inline blk_opf_t iomap_dio_bio_opflags(struct iomap_dio *dio,
225225
const struct iomap *iomap, bool use_fua)
@@ -233,7 +233,7 @@ static inline blk_opf_t iomap_dio_bio_opflags(struct iomap_dio *dio,
233233
if (use_fua)
234234
opflags |= REQ_FUA;
235235
else
236-
dio->flags &= ~IOMAP_DIO_WRITE_FUA;
236+
dio->flags &= ~IOMAP_DIO_WRITE_THROUGH;
237237

238238
return opflags;
239239
}
@@ -273,11 +273,13 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter,
273273
* Use a FUA write if we need datasync semantics, this is a pure
274274
* data IO that doesn't require any metadata updates (including
275275
* after IO completion such as unwritten extent conversion) and
276-
* the underlying device supports FUA. This allows us to avoid
277-
* cache flushes on IO completion.
276+
* the underlying device either supports FUA or doesn't have
277+
* a volatile write cache. This allows us to avoid cache flushes
278+
* on IO completion.
278279
*/
279280
if (!(iomap->flags & (IOMAP_F_SHARED|IOMAP_F_DIRTY)) &&
280-
(dio->flags & IOMAP_DIO_WRITE_FUA) && bdev_fua(iomap->bdev))
281+
(dio->flags & IOMAP_DIO_WRITE_THROUGH) &&
282+
(bdev_fua(iomap->bdev) || !bdev_write_cache(iomap->bdev)))
281283
use_fua = true;
282284
}
283285

@@ -553,13 +555,16 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
553555
dio->flags |= IOMAP_DIO_NEED_SYNC;
554556

555557
/*
556-
* For datasync only writes, we optimistically try
557-
* using FUA for this IO. Any non-FUA write that
558-
* occurs will clear this flag, hence we know before
559-
* completion whether a cache flush is necessary.
558+
* For datasync only writes, we optimistically try using
559+
* WRITE_THROUGH for this IO. This flag requires either
560+
* FUA writes through the device's write cache, or a
561+
* normal write to a device without a volatile write
562+
* cache. For the former, Any non-FUA write that occurs
563+
* will clear this flag, hence we know before completion
564+
* whether a cache flush is necessary.
560565
*/
561566
if (!(iocb->ki_flags & IOCB_SYNC))
562-
dio->flags |= IOMAP_DIO_WRITE_FUA;
567+
dio->flags |= IOMAP_DIO_WRITE_THROUGH;
563568
}
564569

565570
/*
@@ -621,10 +626,11 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
621626
iomap_dio_set_error(dio, ret);
622627

623628
/*
624-
* If all the writes we issued were FUA, we don't need to flush the
625-
* cache on IO completion. Clear the sync flag for this case.
629+
* If all the writes we issued were already written through to the
630+
* media, we don't need to flush the cache on IO completion. Clear the
631+
* sync flag for this case.
626632
*/
627-
if (dio->flags & IOMAP_DIO_WRITE_FUA)
633+
if (dio->flags & IOMAP_DIO_WRITE_THROUGH)
628634
dio->flags &= ~IOMAP_DIO_NEED_SYNC;
629635

630636
WRITE_ONCE(iocb->private, dio->submit.poll_bio);

0 commit comments

Comments
 (0)