virtio-blk physical block size

Message ID
State New
Headers show

Commit Message

Avi Kivity Dec. 28, 2009, 4:09 p.m.
This patch adds a physical block size attribute to virtio disks,
corresponding to /sys/devices/.../physical_block_size.  It is defined as
the request alignment which will not trigger RMW cycles.  This can be
important for modern disks which use 4K physical sectors (though they
still support 512 logical sectors), and for file-backed disk images (which
have both the underlying filesystem block size and their own allocation
granularity to consider).

Installers use this to align partitions to physical block boundaries.

Note the spec already defined blk_size as the performance rather than
minimum alignment.  However the driver interpreted this as the logical
block size, so I updated the spec to match the driver assuming the driver
predates the spec and that this is an error.

Signed-off-by: Avi Kivity <>


--- virtio-spec-0.8.3.lyx.orig	2009-12-28 17:42:40.000000000 +0200
+++ virtio-spec-0.8.3.lyx	2009-12-28 18:05:17.000000000 +0200
@@ -4131,6 +4131,19 @@ 
 \begin_layout Description
+VIRTIO_BLK_F_PHYS_BLK_SIZE(7) Physical block size of disk (writes aligned
+ to this will not trigger read-modify-write cycles) is in 
+\begin_inset Quotes erd
+\begin_inset Quotes erd
+\begin_layout Description
 \begin_inset space ~
@@ -4214,6 +4227,11 @@ 
 \begin_layout Plain Layout
+    u32 phys_blk_size;
+\begin_layout Plain Layout
@@ -4241,9 +4259,9 @@ 
 \begin_layout Enumerate
 If the VIRTIO_BLK_F_BLK_SIZE feature is negotiated, the blk_size field can
- be read to determine the optimal sector size for the driver to use.
+ be read to determine the sector size for the driver to use.
  This does not effect the units used in the protocol (always 512 bytes),
- but awareness of the correct value can effect performance.
+ but requests must be aligned to this size.
 \begin_layout Enumerate
@@ -4257,6 +4275,13 @@ 
  No requests should be submitted which go beyond this limit.
+\begin_layout Enumerate
+If the VIRTIO_BLK_F_PHYS_BLK_SIZE feature is negotiated, the phys_blk_size
+ field should be read to determine the hardware block size.
+ Smaller writes are liable to require read-modify-write cycles on behalf
+ of the underlying hardware, however they are still supported.
 \begin_layout Section*
 Device Operation