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(-)

-- 
2.47.3


Reply via email to