System information
Storage vendors can also supply I/O hints about the preferred minimum unit for random I/O
(mi ni mum_i o _si ze) and streaming I/O (o pti mal _i o _si ze) of a device. For example,
mi ni mum_i o _si ze and o pti mal _i o _si ze may correspond to a RAID device's chunk size and
stripe size respectively.
23.2. Userspace Access
Always take care to use properly aligned and sized I/O. This is especially important for Direct I/O
access. Direct I/O should be aligned on a l og i cal _bl o ck_si ze boundary, and in multiples of
the l o g i cal _bl o ck_si ze.
With native 4K devices (i.e. l o g ical _bl o ck_si ze is 4K) it is now critical that applications perform
direct I/O in multiples of the device's l o gi cal _bl o ck_si ze. This means that applications will fail
with native 4k devices that perform 512-byte aligned I/O rather than 4k-aligned I/O.
To avoid this, an application should consult the I/O parameters of a device to ensure it is using the
proper I/O alignment and size. As mentioned earlier, I/O parameters are exposed through the both
sysfs and block device i o ctl interfaces.
For more details, refer to man l i bbl ki d . This man page is provided by the l i bbl ki d -d evel
package.
sysfs Interface
/sys/block/disk/alignment_offset
/sys/block/disk/partition/alignment_offset
/sys/block/disk/queue/physical_block_size
/sys/block/disk/queue/logical_block_size
/sys/block/disk/queue/minimum_io_size
/sys/block/disk/queue/optimal_io_size
The kernel will still export these sysfs attributes for "legacy" devices that do not provide I/O
parameters information, for example:
Examp le 23.1. sysfs in t erf ace
alignment_offset: 0
physical_block_size: 512
logical_block_size: 512
minimum_io_size: 512
optimal_io_size: 0
Block Device ioctls
BLKALIG NO FF: al i gnment_o ffset
BLKP BSZG ET : physi cal _bl o ck_si ze
sysfs Int erface
159