Skip to content

RFC Support for Hyper-V's HvExtCallGetBootZeroedMemory()

Florian Schmidt qemu-devel 2 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 RFC Latest2 patches 0 repliesNew
  2. v1 RFC2 patches 12 repliesSuperseded

Changes in v2 from the cover letter

- added hv-ext-query-caps option, tracking hv-boot-zeroed-mem (and future extended hypercall options) via kvm_hyperv_properties[]
- added tracking for guest pages touched by QEMU

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2Add HvExtCallQueryCapabilitiesdocs/system/i386/hyperv.rst hw/hyperv/hyperv.c include/hw/hyperv/hyperv-proto.h +7 more+65 -00 replies
2/2Add HvExtCallGetBootZeroedMemorydocs/system/i386/hyperv.rst hw/hyperv/hyperv.c include/hw/hyperv/hyperv-proto.h +9 more+244 -20 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [RFC PATCH v2 0/2] Support for Hyper-V's HvExtCallGetBootZeroedMemory()

This patch series implements two new Hyper-V hypercalls. The primary goal is to support "zeroed memory" enlightenments via HvExtCallGetBootZeroedMemory(). To do so, we also need to implement HvExtCallQueryCapabilities(). While HvExtCallQueryCapabilities() uses another bit in EBX on CPUID leaf 0x40000003, it then allows the guest to query for further "extended" hypercalls via the return value of that call.

HvExtCallGetBootZeroedMemory() allows a Windows guest to enquire which areas of memory that were provided by the hypervisor are already zeroed out, meaning that there's no need for the guest to do so again. This has obvious performance benefits.

To get a rough idea of the performance benefit, looking at a 4-core, 64GB Windows 11 guest, we can see that an otherwise idle guest takes a bit less than 90 seconds to finish zeroing and settle down from the time the qemu process is started. If we look at CPU usage for each vCPU task 90 seconds after starting, we get:
1559 498
1294 343
1451 314
4015 2729
Conversely, after enabling HvExtCallGetBootZeroedMemory(), CPU usage is reduced:
1583 458
1441 361
1279 312
1337 264
These are taken from the respective /proc/<pid>/task/<tid>/stat entries, denoting user and system time per "CPU X/KVM" task, in ticks. We can clearly see which to which vCPU fell the tasks of zeroing.

It also has the benefit of not touching all pages at boot. This can be useful if, for example, the VM is started with a balloon target already set to overcommit memory on the host. In this case, we don't risk memory usage spikes on the host if the VM touches all memory before the balloon can catch up.

Note that as discussed, a full solution should not only take into account memory that QEMU touched, but also memory that the guest itself touched. This will require a new KVM ioctl. This patch series currently does not implement that part, but it should be relatively straightforward to add that to the get_boot_zeroed_memory hypercall handler once it exists.

RFC v2
- added hv-ext-query-caps option, tracking hv-boot-zeroed-mem (and future extended hypercall options) via kvm_hyperv_properties[]
- added tracking for guest pages touched by QEMU

Florian Schmidt (2):
Add HvExtCallQueryCapabilities
Add HvExtCallGetBootZeroedMemory

 docs/system/i386/hyperv.rst      |  14 +++
 hw/hyperv/hyperv.c               | 149 +++++++++++++++++++++++++++++++
 include/hw/hyperv/hyperv-proto.h |  12 +++
 include/hw/hyperv/hyperv.h       |  12 +++
 include/system/physmem.h         |   8 ++
 system/memory.c                  |   7 +-
 system/physmem.c                 |  52 +++++++++++
 target/i386/cpu.c                |   4 +
 target/i386/cpu.h                |   2 +
 target/i386/kvm/hyperv-proto.h   |   6 ++
 target/i386/kvm/hyperv.c         |  14 +++
 target/i386/kvm/kvm.c            |  29 ++++++
 target/i386/kvm/kvm_i386.h       |   2 +
 13 files changed, 309 insertions(+), 2 deletions(-)
Signature · 1 line
2.47.3