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 <dplotnikov@virtuozzo.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Denis Plotnikov 2019-10-17 17:01:00 +03:00 committed by Gerd Hoffmann
parent 43f5df79da
commit 50093b4b22
1 changed files with 1 additions and 1 deletions

View File

@ -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