Created attachment 1541220 [details]
Patch to only use optimal_io_size matching physical_sector_size
Description of problem:
Some devices (USB Attached SCSI in particular) report an optimal_io_size which is not a multiple of physical_sector_size.[^1][^2][^3][^4] This causes pvcreate to create physical volumes which are mis-aligned to physical sectors, degrading performance.[^5][^6]
Version-Release number of selected component (if applicable): 2.03.02 and current git master (a0c848d4e)
How reproducible: Always
Steps to Reproduce:
1. pvcreate -v /dev/sdb
2. pvs -o pe_start --units b /dev/sdb
The kernel maintainers have stated that sanity checking this value is the responsibility of user-space.[^7] util-linux only uses the value if it is a multiple of physical_sector_size.[^8] cryptsetup only uses the value if it is a multiple of minimum_io_size.[^9] parted is currently discussing the issue.[^10]
I have attached a patch which adopts the util-linux strategy and does not constrain alignment based on optimal_io_size when it is not a multiple of physical_sector_size.
The testing was a bit complicated and required use of the scsi_debug device directly. I'd appreciate a sanity check before it is applied.
Thanks for considering,