Skip to content
  • Dave Chinner's avatar
    iomap: Use FUA for pure data O_DSYNC DIO writes · 3460cac1
    Dave Chinner authored
    
    
    If we are doing direct IO writes with datasync semantics, we often
    have to flush metadata changes along with the data write. However,
    if we are overwriting existing data, there are no metadata changes
    that we need to flush. In this case, optimising the IO by using
    FUA write makes sense.
    
    We know from the IOMAP_F_DIRTY flag as to whether a specific inode
    requires a metadata flush - this is currently used by DAX to ensure
    extent modification as stable in page fault operations. For direct
    IO writes, we can use it to determine if we need to flush metadata
    or not once the data is on disk.
    
    Hence if we have been returned a mapped extent that is not new and
    the IO mapping is not dirty, then we can use a FUA write to provide
    datasync semantics. This allows us to short-cut the
    generic_write_sync() call in IO completion and hence avoid
    unnecessary operations. This makes pure direct IO data write
    behaviour identical to the way block devices use REQ_FUA to provide
    datasync semantics.
    
    On a FUA enabled device, a synchronous direct IO write workload
    (sequential 4k overwrites in 32MB file) had the following results:
    
    # xfs_io -fd -c "pwrite -V 1 -D 0 32m" /mnt/scratch/boo
    
    kernel		time	write()s	write iops	Write b/w
    ------		----	--------	----------	---------
    (no dsync)	 4s	2173/s		2173		8.5MB/s
    vanilla		22s	 370/s		 750		1.4MB/s
    patched		19s	 420/s		 420		1.6MB/s
    
    The patched code clearly doesn't send cache flushes anymore, but
    instead uses FUA (confirmed via blktrace), and performance improves
    a bit as a result. However, the benefits will be higher on workloads
    that mix O_DSYNC overwrites with other write IO as we won't be
    flushing the entire device cache on every DSYNC overwrite IO
    anymore.
    
    Signed-Off-By: default avatarDave Chinner <dchinner@redhat.com>
    Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
    Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
    Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
    3460cac1