From 50093b4b229b47860c967038e2dc094263e6c9db Mon Sep 17 00:00:00 2001 From: Denis Plotnikov Date: Thu, 17 Oct 2019 17:01:00 +0300 Subject: virtio: extend virtio queue size to 256 The goal of the patch is to work around a performance bug in guest linux kernels. Old linux kernels has a performance flaw in virtio block device access: on some frequent disk access patterns, e.g. 1M read, the kernel produces more block requests than needed. This happens because of virtio seg_max parameter set to 126 (virtqueue_size - 2) which limits the maximum block request to 516096 (126 * 4096_PAGE_SIZE) bytes. Setting seg_max > 126 fixes the issue, however, not all linux kernels allow that without increasing virtio virtqueue size. The old kernels have a restriction: virtqueue_size >= seg_max. In case of the restriction violation the old kernels crash. The restriction is relaxed in the recent linux kernels (ver >= 4.13) with: commit 44ed8089e991a60d614abe0ee4b9057a28b364e4 Author: Richard W.M. Jones Date: Thu Aug 10 17:56:51 2017 +0100 scsi: virtio: Reduce BUG if total_sg > virtqueue size to WARN. and the recent linux kernels don't crash if total_sg > virtqueue size allowing to set seg_max to the needed value without virtqueue size increasing. To fix the performance flaw in the old linux kernels, it's needed to increse seg_max to 254, and comply the restriction by setting virtqueue_size to 256. This is achievable if seabios can support virtqueue size > 128 which this patch actually does. Windows kernels don't have virtqueue_size >= seg_max restriction and isn't affected with this kind of the performance bug. Signed-off-by: Denis Plotnikov Signed-off-by: Gerd Hoffmann --- src/hw/virtio-ring.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/hw/virtio-ring.h b/src/hw/virtio-ring.h index 8604a01..dccc50d 100644 --- a/src/hw/virtio-ring.h +++ b/src/hw/virtio-ring.h @@ -20,7 +20,7 @@ #define VIRTIO_F_VERSION_1 32 #define VIRTIO_F_IOMMU_PLATFORM 33 -#define MAX_QUEUE_NUM (128) +#define MAX_QUEUE_NUM (256) #define VRING_DESC_F_NEXT 1 #define VRING_DESC_F_WRITE 2 -- cgit v1.1