Re: [PATCH v3 1/8] statx: add direct I/O alignment information

From: Avi Kivity
Date: Sun Jun 26 2022 - 06:20:36 EST



On 26/06/2022 10.44, Christoph Hellwig wrote:
On Sun, Jun 19, 2022 at 02:30:47PM +0300, Avi Kivity wrote:
* stx_dio_offset_align: the alignment (in bytes) required for file
offsets and I/O segment lengths for DIO, or 0 if DIO is not supported
on the file. This will only be nonzero if stx_dio_mem_align is
nonzero, and vice versa.

If you consider AIO, this is actually three alignments:

1. offset alignment for reads (sector size in XFS)

2. offset alignment for overwrites (sector size in XFS since ed1128c2d0c87e,
block size earlier)

3. offset alignment for appending writes (block size)


This is critical for linux-aio since violation of these alignments will
stall the io_submit system call. Perhaps io_uring handles it better by
bouncing to a workqueue, but there is a significant performance and latency
penalty for that.
I think you are mixing things up here.


Yes.


We actually have two limits that
matter:

a) the hard limit, which if violated will return an error.
This has been sector size for all common file systems for years,
but can be bigger than that with fscrypt in the game (which
triggered this series)
b) an optimal write size, which can be done asynchronous and
without exclusive locking.
This is what your cases 2) and 3) above refer to.

Exposting this additional optimal performance size might be a good idea
in addition to what is proposed here, even if matters a little less
with io_uring. But I'm not sure I'd additional split it into append
vs overwrite vs hole filling but just round up to the maximum of those.


Rounding up will penalize database workloads, with and without io_uring. Database commit logs are characterized by frequent small writes. Telling the database to round up to 4k vs 512 bytes means large write amplification. The disk probably won't care (or maybe it will - it will also have to generate more erase blocks), but the database will run out of commitlog space much sooner and will have to compensate in expensive ways.


Of course, people that care can continue to use internal filesystem knowledge, and maybe there are few enough of those that the API can choose to ignore them.