[SeaBIOS] [PATCH v1] virtio: extend virtio queue size to 256

Denis Plotnikov posted 1 patch 4 years, 6 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/seabios tags/patchew/20191017140100.8325-1-dplotnikov@virtuozzo.com
src/hw/virtio-ring.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[SeaBIOS] [PATCH v1] virtio: extend virtio queue size to 256
Posted by Denis Plotnikov 4 years, 6 months ago
v1:
  * more verbose commit message [Gerd]

---

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 <dplotnikov@virtuozzo.com>
---
 src/hw/virtio-ring.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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
-- 
2.17.0
_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org