[PATCH Libvirt v2 1/3] conf: Add 'virtio_discard' and 'virtio_write_zeroes' attributes

Peter Krempa pkrempa at redhat.com
Tue Jul 18 13:31:00 UTC 2023


On Sun, Jul 16, 2023 at 22:36:21 +0800, ~hyman wrote:
> From: Hyman Huang(黄勇) <yong.huang at smartx.com>
> 
> Add 'virtio_discard' and 'virtio_write_zeroes' attribute to control
> whether discard and write-zeroes requests are handled by the
> virtio-blk device.
> 
> To distinguish the attributes in block drive layer, use the 'virtio'
> prefix to indicate that these attributes are specific for virtio-blk.
> 
> Signed-off-by: Hyman Huang(黄勇) <yong.huang at smartx.com>
> ---
>  docs/formatdomain.rst             |  8 ++++++++
>  src/conf/domain_conf.c            | 16 ++++++++++++++++
>  src/conf/domain_conf.h            |  2 ++
>  src/conf/schemas/domaincommon.rng | 10 ++++++++++
>  src/conf/storage_source_conf.c    |  2 ++
>  src/conf/storage_source_conf.h    |  2 ++
>  src/qemu/qemu_domain.c            |  2 ++
>  src/qemu/qemu_driver.c            |  4 +++-
>  src/vz/vz_utils.c                 | 12 ++++++++++++
>  9 files changed, 57 insertions(+), 1 deletion(-)
> 
> diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst
> index 4af0b82569..7be12ff08e 100644
> --- a/docs/formatdomain.rst
> +++ b/docs/formatdomain.rst
> @@ -3259,6 +3259,14 @@ paravirtualized driver is specified via the ``disk`` element.
>        value can be either "unmap" (allow the discard request to be passed) or
>        "ignore" (ignore the discard request). :since:`Since 1.0.6 (QEMU and KVM
>        only)`
> +   -  The optional ``virtio_discard`` and ``virtio_write_zeroes`` are attributes
> +      that control whether discard and write-zeroes requests are handled by the
> +      virtio-blk device. The feature is based on DISCARD and WRITE_ZEROES
> +      commands introduced in virtio-blk protocol to improve performance when
> +      using SSD backend. The value can be either 'on' or 'off'. Note that
> +      ``discard`` and ``write_zeroes`` implementations in the block drive layer
> +      are parts of the feature logically and should be turned on when enabling
> +      the feature. :since:`Since 9.6.0 (QEMU and KVM only)`

Based on current released qemu both 'discard' and 'write-zeroes' feature
of the 'virtio-blk' device is enabled by default:

 $ qemu-system-x86_64 -device virtio-blk-pci,? | grep discard
   discard=<bool>         - on/off (default: true)
   discard_granularity=<size> -  (default: 4294967295)
   max-discard-sectors=<uint32> -  (default: 4194303)
   report-discard-granularity=<bool> -  (default: true)
 $ qemu-system-x86_64 -device virtio-blk-pci,? | grep write-zeroes
   max-write-zeroes-sectors=<uint32> -  (default: 4194303)
   write-zeroes=<bool>    - on/off (default: true)

Do you need a way to disable this feature? Based on the description the
default seems to be sane and actually what you'd want users to set.

The feature was introduced to qemu by:

commit 5c81161f804144b146607f890e84613a4cbad95c
Author: Stefano Garzarella <sgarzare at redhat.com>
Date:   Thu Feb 21 11:33:07 2019 +0100

    virtio-blk: add "discard" and "write-zeroes" properties

    In order to avoid migration issues, we enable DISCARD and
    WRITE_ZEROES features only for machine type >= 4.0

    As discussed with Michael S. Tsirkin and Stefan Hajnoczi on the
    list [1], DISCARD operation should not have security implications
    (eg. page cache attacks), so we can enable it by default.

The default was always enabled for all new machine types, so you should
only ever need to update your machine type.


More information about the libvir-list mailing list