add STATX_DIO_READ_ALIGN v3
Subsystems (4)
Hi all,
[I hope that no one gets too annoyed by the rapid resends, but s we're
down to comment an man page tweaks I thought I'd stick to the fast pace]
file systems that write out of place usually require different alignment for direct I/O writes than what they can do for reads. This series tries to address this by adding yet another statx field.
Changes from v2:
- more comment and man page tweaks
Changes from v1:
- improve the comment in xfs_report_dioalign based on a contribution from Darrick
- improve man page wording and formatting
- also report the larger alignment in XFS_IOC_DIOINFO
Changes from RFC:
- add a cleanup patch for xfs_vn_getattr
- use xfs_inode_alloc_unitsize in xfs_vn_getattr
- improve a comment in XFS
Diffstat:
fs/stat.c | 1 fs/xfs/xfs_ioctl.c | 11 ++++- fs/xfs/xfs_iops.c | 62 +++++++++++++++++----------- include/linux/stat.h | 1 include/uapi/linux/stat.h | 99 ++++++++++++++++++++++++++++++++++------------ 5 files changed, 125 insertions(+), 49 deletions(-)
PATCH 1/5 fs: reformat the statx definition
The comments after the declaration are becoming rather unreadable with long enough comments. Move them into lines of their own.
--- include/uapi/linux/stat.h | 95 +++++++++++++++++++++++++++++---------- 1 file changed, 72 insertions(+), 23 deletions(-)
include/uapi/linux/stat.h +72 -23
@@ -98,43 +98,92 @@ struct statx_timestamp {*/ struct statx {/* 0x00 */ -__u32 stx_mask;/* What results were written [uncond] */ -__u32 stx_blksize;/* Preferred general I/O size [uncond] */ -__u64 stx_attributes;/* Flags conveying information about the file [uncond] */ +/* What results were written [uncond] */ +__u32 stx_mask; + +/* Preferred general I/O size [uncond] */ +__u32 stx_blksize; + +/* Flags conveying information about the file [uncond] */ +__u64 stx_attributes; +/* 0x10 */ -__u32 stx_nlink;/* Number of hard links */ -__u32 stx_uid;/* User ID of owner */ -__u32 stx_gid;/* Group ID of owner */ -__u16 stx_mode;/* File mode */ +/* Number of hard links */ +__u32 stx_nlink; + +/* User ID of owner */ +__u32 stx_uid; + +/* Group ID of owner */ +__u32 stx_gid; + +/* File mode */ +__u16 stx_mode;__u16 __spare0[1 ]; +/* 0x20 */ -__u64 stx_ino;/* Inode number */ -__u64 stx_size;/* File size */ -__u64 stx_blocks;/* Number of 512-byte blocks allocated */ -__u64 stx_attributes_mask;/* Mask to show what's supported in stx_attributes */ +/* Inode number */ +__u64 stx_ino; + +/* File size */ +__u64 stx_size; + +/* Number of 512-byte blocks allocated */ +__u64 stx_blocks; + +/* Mask to show what's supported in stx_attributes */ +__u64 stx_attributes_mask; +/* 0x40 */ -struct statx_timestamp stx_atime;/* Last access time */ -struct statx_timestamp stx_btime;/* File creation time */ -struct statx_timestamp stx_ctime;/* Last attribute change time */ -struct statx_timestamp stx_mtime;/* Last data modification time */ +/* Last access time */ +struct statx_timestamp stx_atime; + +/* File creation time */ +struct statx_timestamp stx_btime; + +/* Last attribute change time */ +struct statx_timestamp stx_ctime; + +/* Last data modification time */ +struct statx_timestamp stx_mtime; +/* 0x80 */ -__u32 stx_rdev_major;/* Device ID of special file [if bdev/cdev] */ +/* Device ID of special file [if bdev/cdev] */ +__u32 stx_rdev_major;__u32 stx_rdev_minor; -__u32 stx_dev_major;/* ID of device containing file [uncond] */ + +/* ID of device containing file [uncond] */ +__u32 stx_dev_major;__u32 stx_dev_minor; +/* 0x90 */ __u64 stx_mnt_id; -__u32 stx_dio_mem_align;/* Memory buffer alignment for direct I/O */ -__u32 stx_dio_offset_align;/* File offset alignment for direct I/O */ + +/* Memory buffer alignment for direct I/O */ +__u32 stx_dio_mem_align; + +/* File offset alignment for direct I/O */ +__u32 stx_dio_offset_align; +/* 0xa0 */ -__u64 stx_subvol;/* Subvolume identifier */ -__u32 stx_atomic_write_unit_min;/* Min atomic write unit in bytes */ -__u32 stx_atomic_write_unit_max;/* Max atomic write unit in bytes */ +/* Subvolume identifier */ +__u64 stx_subvol; + +/* Min atomic write unit in bytes */ +__u32 stx_atomic_write_unit_min; + +/* Max atomic write unit in bytes */ +__u32 stx_atomic_write_unit_max; +/* 0xb0 */ -__u32 stx_atomic_write_segments_max;/* Max atomic write segment count */ +/* Max atomic write segment count */ +__u32 stx_atomic_write_segments_max; +__u32 __spare1[1 ]; +/* 0xb8 */ __u64 __spare3[9 ];/* Spare space for future expansion */ +/* 0x100 */ };
Signature · 1 line
2.45.2
PATCH 2/5 fs: add STATX_DIO_READ_ALIGN
In reply to Christoph HellwigAdd a separate dio read align field, as many out of place write file systems can easily do reads aligned to the device sector size, but require bigger alignment for writes.
This is usually papered over by falling back to buffered I/O for smaller writes and doing read-modify-write cycles, but performance for this sucks, so applications benefit from knowing the actual write alignment.
--- fs/stat.c | 1 + include/linux/stat.h | 1 + include/uapi/linux/stat.h | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-)
fs/stat.c +1 -0
@@ -725,6 +725,7 @@ cp_statx(const struct kstat *stat, struct statx __user *buffer) tmp.stx_mnt_id = stat->mnt_id; tmp.stx_dio_mem_align = stat->dio_mem_align; tmp.stx_dio_offset_align = stat->dio_offset_align; + tmp.stx_dio_read_offset_align = stat->dio_read_offset_align; tmp.stx_subvol = stat->subvol; tmp.stx_atomic_write_unit_min = stat->atomic_write_unit_min; tmp.stx_atomic_write_unit_max = stat->atomic_write_unit_max;
include/linux/stat.h +1 -0
@@ -52,6 +52,7 @@ struct kstat {u64 mnt_id;u32 dio_mem_align;u32 dio_offset_align; +u32 dio_read_offset_align;u64 change_cookie;u64 subvol;u32 atomic_write_unit_min;
include/uapi/linux/stat.h +3 -1
@@ -179,7 +179,8 @@ struct statx {/* Max atomic write segment count */ __u32 stx_atomic_write_segments_max; -__u32 __spare1[1 ]; +/* File offset alignment for direct I/O reads */ +__u32 stx_dio_read_offset_align;/* 0xb8 */ __u64 __spare3[9 ];/* Spare space for future expansion */
@@ -213,6 +214,7 @@ struct statx {#define STATX_MNT_ID_UNIQUE 0x00004000U/* Want/got extended stx_mount_id */ #define STATX_SUBVOL 0x00008000U/* Want/got stx_subvol */ #define STATX_WRITE_ATOMIC 0x00010000U/* Want/got atomic_write_* fields */ +#define STATX_DIO_READ_ALIGN 0x00020000U/* Want/got dio read alignment info */ #define STATX__RESERVED 0x80000000U/* Reserved for future struct statx expansion */
Signature · 1 line
2.45.2
PATCH 3/5 xfs: cleanup xfs_vn_getattr
In reply to Christoph HellwigSplit the two bits of optional statx reporting into their own helpers so that they are self-contained instead of deeply indented in the main getattr handler.
--- fs/xfs/xfs_iops.c | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-)
fs/xfs/xfs_iops.c +23 -24
@@ -573,17 +573,28 @@ xfs_stat_blksize( }static void -xfs_get_atomic_write_attr ( +xfs_report_dioalign (struct xfs_inode *ip, -unsigned int *unit_min, -unsigned int *unit_max) +struct kstat *stat) { -if (!xfs_inode_can_atomicwrite (ip)) { - *unit_min = *unit_max =0 ; -return ; - } +struct xfs_buftarg *target =xfs_inode_buftarg (ip); +struct block_device *bdev = target->bt_bdev; - *unit_min = *unit_max = ip->i_mount->m_sb.sb_blocksize; + stat->result_mask |=STATX_DIOALIGN ; + stat->dio_mem_align =bdev_dma_alignment (bdev) +1 ; + stat->dio_offset_align =bdev_logical_block_size (bdev); +} + +static void +xfs_report_atomic_write ( +struct xfs_inode *ip, +struct kstat *stat) +{ +unsigned int unit_min =0 , unit_max =0 ; + +if (xfs_inode_can_atomicwrite (ip)) + unit_min = unit_max = ip->i_mount->m_sb.sb_blocksize; +generic_fill_statx_atomic_writes (stat, unit_min, unit_max); }STATIC int
@@ -647,22 +658,10 @@ xfs_vn_getattr( stat->rdev = inode->i_rdev;break ;case S_IFREG : -if (request_mask &STATX_DIOALIGN ) { -struct xfs_buftarg *target =xfs_inode_buftarg (ip); -struct block_device *bdev = target->bt_bdev; - - stat->result_mask |=STATX_DIOALIGN ; - stat->dio_mem_align =bdev_dma_alignment (bdev) +1 ; - stat->dio_offset_align =bdev_logical_block_size (bdev); - } -if (request_mask &STATX_WRITE_ATOMIC ) { -unsigned int unit_min, unit_max; - -xfs_get_atomic_write_attr (ip, &unit_min, - &unit_max); -generic_fill_statx_atomic_writes (stat, - unit_min, unit_max); - } +if (request_mask &STATX_DIOALIGN ) +xfs_report_dioalign (ip, stat); +if (request_mask &STATX_WRITE_ATOMIC ) +xfs_report_atomic_write (ip, stat); fallthrough;default : stat->blksize =xfs_stat_blksize (ip);
Signature · 1 line
2.45.2
PATCH 4/5 xfs: report the correct read/write dio alignment for reflinked inodes
In reply to Christoph HellwigFor 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.
--- fs/xfs/xfs_iops.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
fs/xfs/xfs_iops.c +18 -3
@@ -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);
Signature · 1 line
2.45.2
PATCH 5/5 xfs: report larger dio alignment for COW inodes
In reply to Christoph HellwigFor 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. Mirror the larger value reported in the statx in the dio_offset_align in the xfs-specific XFS_IOC_DIOINFO ioctl for the same reason.
Don't bother adding a new field for the read alignment to this legacy ioctl as all new users should use statx instead.
--- fs/xfs/xfs_ioctl.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
fs/xfs/xfs_ioctl.c +10 -1
@@ -1204,7 +1204,16 @@ xfs_file_ioctl(struct xfs_buftarg *target =xfs_inode_buftarg (ip);struct dioattr da; - da.d_mem = da.d_miniosz = target->bt_logical_sectorsize; + da.d_mem = target->bt_logical_sectorsize; + +/* +* See xfs_report_dioalign() for an explanation about why this +* reports a value larger than the sector size for COW inodes. +*/ +if (xfs_is_cow_inode (ip)) + da.d_miniosz =xfs_inode_alloc_unitsize (ip); +else + da.d_miniosz = target->bt_logical_sectorsize; da.d_maxiosz =INT_MAX & ~(da.d_miniosz -1 );if (copy_to_user (arg, &da,sizeof (da)))
Signature · 1 line
2.45.2
PATCH 1/1 statx.2: document STATX_DIO_READ_ALIGN
In reply to Christoph HellwigDocument the new STATX_DIO_READ_ALIGN flag and the new stx_dio_read_offset_align field guarded by it.
--- man/man2/statx.2 | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)
man/man2/statx.2 +25 -1
@@ -76,6 +76,9 @@ struct statx { __u32 stx_atomic_write_unit_min; __u32 stx_atomic_write_unit_max; __u32 stx_atomic_write_segments_max; + + /* File offset alignment for direct I/O reads */ + __u32 stx_dio_read_offset_align; }; .EE .in
@@ -261,7 +264,7 @@ STATX_BTIME Want stx_btime STATX_ALL The same as STATX_BASIC_STATS | STATX_BTIME. It is deprecated and should not be used. STATX_MNT_ID Want stx_mnt_id (since Linux 5.8) -STATX_DIOALIGN Want stx_dio_mem_align and stx_dio_offset_align +STATX_DIOALIGN Want stx_dio_mem_align and stx_dio_offset_align. (since Linux 6.1; support varies by filesystem) STATX_MNT_ID_UNIQUE Want unique stx_mnt_id (since Linux 6.8) STATX_SUBVOL Want stx_subvol
@@ -270,6 +273,8 @@ STATX_WRITE_ATOMIC Want stx_atomic_write_unit_min, stx_atomic_write_unit_max, and stx_atomic_write_segments_max. (since Linux 6.11; support varies by filesystem) +STATX_DIO_READ_ALIGN Want stx_dio_read_offset_align. + (since Linux 6.14; support varies by filesystem) .TE .in .P
@@ -467,6 +472,25 @@ This will only be nonzero if .I stx_dio_mem_align is nonzero, and vice versa. .TP +.I stx_dio_read_offset_align +The alignment (in bytes) required for file offsets and I/O segment lengths for +direct I/O reads +.RB ( O_DIRECT ) +on this file. +If zero, the limit in +.I stx_dio_offset_align +applies for reads as well. +If non-zero, this value must be smaller than or equal to +.I stx_dio_offset_align +which must be provided by the file system if requested by the application. +The memory alignment in +.I stx_dio_mem_align +is not affected by this value. +.IP +.B STATX_DIO_READ_ALIGN +.RI ( stx_dio_offset_align ) +is supported by xfs on regular files since Linux 6.14. +.TP .I stx_subvol Subvolume number of the current file. .IP
Signature · 1 line
2.45.2
Alejandro Colomar
maintainerRe: [PATCH] statx.2: document STATX_DIO_READ_ALIGN
Hi Christoph,
Quoted 5 lines · Christoph Hellwig
Document the new
STATX_DIO_READ_ALIGNflag and the newstx_dio_read_offset_alignfield guarded by it.Signed-off-by Christoph Hellwig <[email protected]>Reviewed-by "Darrick J. Wong" <[email protected]>
Thanks for the patch! I've applied it.
<https://www.alejandro-colomar.es/src/alx/linux/man-pages/man-pages.git/commit/?h=contrib&id=3eb8ef31cb5295b5eaaaf319796ea6279b7f7002>
A few minor comments:
Please add the CCd people as Cc: in the commit message. I'll do that anyway, so it avoids me pasting them, and will probably make it easier for you to send with git-send-email(1) (or whatever you use).
Quoted 1 line
Subject: Re: [PATCH] statx.2: document
STATX_DIO_READ_ALIGN
I changed commit subjects to use the full path to the manual page. Also please start with uppercase after the ':'.
Also, please use version numbers for patches (v2, v3, ...).
man/man2/statx.2 struct statx { · line 79
Quoted 13 lines
--- man/man2/statx.2 | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)man/man2/statx.2 +1
-0@@ -76,6 +76,9 @@ struct statx { __u32 stx_atomic_write_unit_min; __u32 stx_atomic_write_unit_max; __u32 stx_atomic_write_segments_max; +
I didn't realize this needed a \&. The CI reminded me. I've amended that.
Have a lovely day!
Alex
Quoted 53 lines
man/man2/statx.2 +24
-1+ /* File offset alignment for direct I/O reads */ + __u32 stx_dio_read_offset_align; }; .EE .in@@ -261,7 +264,7 @@ STATX_BTIME Want stx_btime STATX_ALL The same as STATX_BASIC_STATS | STATX_BTIME. It is deprecated and should not be used. STATX_MNT_ID Want stx_mnt_id (since Linux 5.8) -STATX_DIOALIGN Want stx_dio_mem_align and stx_dio_offset_align +STATX_DIOALIGN Want stx_dio_mem_align and stx_dio_offset_align. (since Linux 6.1; support varies by filesystem) STATX_MNT_ID_UNIQUE Want unique stx_mnt_id (since Linux 6.8) STATX_SUBVOL Want stx_subvol@@ -270,6 +273,8 @@ STATX_WRITE_ATOMIC Want stx_atomic_write_unit_min, stx_atomic_write_unit_max, and stx_atomic_write_segments_max. (since Linux 6.11; support varies by filesystem) +STATX_DIO_READ_ALIGN Want stx_dio_read_offset_align. + (since Linux 6.14; support varies by filesystem) .TE .in .P@@ -467,6 +472,25 @@ This will only be nonzero if .I stx_dio_mem_align is nonzero, and vice versa. .TP +.I stx_dio_read_offset_align +The alignment (in bytes) required for file offsets and I/O segment lengths for +direct I/O reads +.RB ( O_DIRECT ) +on this file. +If zero, the limit in +.I stx_dio_offset_align +applies for reads as well. +If non-zero, this value must be smaller than or equal to +.I stx_dio_offset_align +which must be provided by the file system if requested by the application. +The memory alignment in +.I stx_dio_mem_align +is not affected by this value. +.IP +.B STATX_DIO_READ_ALIGN +.RI ( stx_dio_offset_align ) +is supported by xfs on regular files since Linux 6.14. +.TP .I stx_subvol Subvolume number of the current file. .IPSignature · 1 line
2.45.2
Signature · 1 line
<https://www.alejandro-colomar.es/>
Quoted 8 lines · Christoph Hellwig
[I hope that no one gets too annoyed by the rapid resends, but s we're
down to comment an man page tweaks I thought I'd stick to the fast pace]file systems that write out of place usually require different alignment for direct I/O writes than what they can do for reads. This series tries to address this by adding yet another statx field.
[...]
Applied to the vfs-6.14.statx.dio branch of the vfs/vfs.git tree. Patches in the vfs-6.14.statx.dio branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-6.14.statx.dio
[1/5] fs: reformat the statx definition
https://git.kernel.org/vfs/vfs/c/8fc7e23a9bd8 [2/5] fs: add STATX_DIO_READ_ALIGN https://git.kernel.org/vfs/vfs/c/7ed6cbe0f8ca [3/5] xfs: cleanup xfs_vn_getattr https://git.kernel.org/vfs/vfs/c/7e17483c7b15 [4/5] xfs: report the correct read/write dio alignment for reflinked inodes https://git.kernel.org/vfs/vfs/c/7422bbd03021 [5/5] xfs: report larger dio alignment for COW inodes https://git.kernel.org/vfs/vfs/c/468210ec76e1