mbox series

[RFC,V2,0/3] Add NUMA mempolicy support for KVM guest_memfd

Message ID 20240919094438.10987-1-shivankg@amd.com (mailing list archive)
Headers show
Series Add NUMA mempolicy support for KVM guest_memfd | expand

Message

Shivank Garg Sept. 19, 2024, 9:44 a.m. UTC
The current implementation of KVM guest-memfd does not honor the settings
provided by VMM. While mbind() can be used for NUMA policy support in
userspace applications, it is not functional for guest-memfd as the memory
is not mapped to userspace.

This patch-series adds support to specify NUMA memory policy for guests
with private guest-memfd memory backend. KVM guest-memfd support for
memory backend is already available in QEMU RAMBlock. However, the NUMA
support was missing. This cause memory allocation from guest to randomly
allocate on host NUMA nodes even when passing policy and host-nodes in the
QEMU command. It ensures that VMM provided NUMA policy is adhered.

This feature is particularly useful for SEV-SNP guests as they require
guest_memfd memory backend for allocations. Workloads with high memory-
locality are likely to benefit with this change.

Users can provide a policy mode such as default, bind, interleave, or
preferred along with a list of node IDs from the host machine.

To try this patch-series, build the custom QEMU with NUMA supported KVM
guest-memfd:
QEMU tree- https://github.com/AMDESE/qemu/tree/NUMA_guest_memfd
For instance, to run a SEV-SNP guest bound to NUMA Node 0 of the host,
the corresponding QEMU command would be:

$ qemu-system-x86_64 \
   -enable-kvm \
  ...
   -machine memory-encryption=sev0,vmport=off \
   -object sev-snp-guest,id=sev0,cbitpos=51,reduced-phys-bits=1 \
   -numa node,nodeid=0,memdev=ram0,cpus=0-15 \
   -object memory-backend-memfd,id=ram0,policy=bind,host-nodes=0,size=1024M,share=true,prealloc=false


v2:
- Add fixes suggested by Matthew Wilcox

v1: https://lore.kernel.org/linux-mm/20240916165743.201087-1-shivankg@amd.com

Shivansh Dhiman (3):
  KVM: guest_memfd: Extend creation API to support NUMA mempolicy
  mm: Add mempolicy support to the filemap layer
  KVM: guest_memfd: Enforce NUMA mempolicy if available

 Documentation/virt/kvm/api.rst | 13 ++++++++-
 include/linux/mempolicy.h      |  4 +++
 include/linux/pagemap.h        | 40 ++++++++++++++++++++++++++
 include/uapi/linux/kvm.h       |  5 +++-
 mm/filemap.c                   | 30 ++++++++++++++++----
 mm/mempolicy.c                 | 52 ++++++++++++++++++++++++++++++++++
 tools/include/uapi/linux/kvm.h |  5 +++-
 virt/kvm/guest_memfd.c         | 28 ++++++++++++++----
 virt/kvm/kvm_mm.h              |  3 ++
 9 files changed, 167 insertions(+), 13 deletions(-)