]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
xfs: report the correct read/write dio alignment for reflinked inodes
authorChristoph Hellwig <hch@lst.de>
Thu, 9 Jan 2025 08:31:04 +0000 (09:31 +0100)
committerChristian Brauner <brauner@kernel.org>
Thu, 9 Jan 2025 15:23:18 +0000 (16:23 +0100)
For I/O to reflinked blocks we always need to write an entire new
file system block, and the code enforces the file system block alignment
for the entire file if it has any reflinked blocks.

Use the new STATX_DIO_READ_ALIGN flag to report the asymmetric read
vs write alignments for reflinked files.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20250109083109.1441561-5-hch@lst.de
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/xfs/xfs_iops.c

index 6b0228a216176ce578019d0df5738761a4eb9979..40289fe6f5b2b408186fb4d3e7e8fa44692911cf 100644 (file)
@@ -580,9 +580,24 @@ xfs_report_dioalign(
        struct xfs_buftarg      *target = xfs_inode_buftarg(ip);
        struct block_device     *bdev = target->bt_bdev;
 
-       stat->result_mask |= STATX_DIOALIGN;
+       stat->result_mask |= STATX_DIOALIGN | STATX_DIO_READ_ALIGN;
        stat->dio_mem_align = bdev_dma_alignment(bdev) + 1;
-       stat->dio_offset_align = bdev_logical_block_size(bdev);
+
+       /*
+        * For COW inodes, we can only perform out of place writes of entire
+        * allocation units (blocks or RT extents).
+        * For writes smaller than the allocation unit, we must fall back to
+        * buffered I/O to perform read-modify-write cycles.  At best this is
+        * highly inefficient; at worst it leads to page cache invalidation
+        * races.  Tell applications to avoid this by reporting the larger write
+        * alignment in dio_offset_align, and the smaller read alignment in
+        * dio_read_offset_align.
+        */
+       stat->dio_read_offset_align = bdev_logical_block_size(bdev);
+       if (xfs_is_cow_inode(ip))
+               stat->dio_offset_align = xfs_inode_alloc_unitsize(ip);
+       else
+               stat->dio_offset_align = stat->dio_read_offset_align;
 }
 
 static void
@@ -658,7 +673,7 @@ xfs_vn_getattr(
                stat->rdev = inode->i_rdev;
                break;
        case S_IFREG:
-               if (request_mask & STATX_DIOALIGN)
+               if (request_mask & (STATX_DIOALIGN | STATX_DIO_READ_ALIGN))
                        xfs_report_dioalign(ip, stat);
                if (request_mask & STATX_WRITE_ATOMIC)
                        xfs_report_atomic_write(ip, stat);