[PATCH v2 0/2] KVM: Allocate small memslot metadata with kvzalloc()
From: Fred Griffoul
Date: Wed Nov 04 2026 - 19:23:37 EST
From: Fred Griffoul <fgriffo@xxxxxxxxxxxx>
__vcalloc() makes every memslot metadata allocation at least one page,
so small memslots waste most of their lpage_info and dirty bitmap, and
memslots below 512 GiB waste most of a page on their 1 GiB lpage_info.
Mushahid's patch [1] switched those arrays to kvcalloc(), and Sean
suggested dedicated helpers for memslot metadata with a pivot that makes
sense for KVM instead [2].
Patch 1 adds the helpers and routes the dirty bitmap, rmaps, lpage_info
and write-tracking arrays through them, with no functional change.
Patch 2 makes the helpers use kvzalloc() up to KMALLOC_MAX_CACHE_SIZE,
where kmalloc() never uses more memory than vmalloc(), and keeps
__vcalloc() above.
I ran the memslot and dirty logging selftests with the TDP MMU and with
kvm.tdp_mmu=0, plus a check that one-page memslots no longer take a
vmalloc area each and that a 1 TiB memslot still gets its rmaps from
vmalloc.
Fred
Changes in v2:
- Split the helpers and the allocator change into two patches
- Pivot on KMALLOC_MAX_CACHE_SIZE instead of INT_MAX
v1: https://lore.kernel.org/kvm/20261103234734.45413-1-griffoul@xxxxxxxxx/
[1] https://lore.kernel.org/all/20260815142218.85067-1-hmushi@xxxxxxxxxxxx/
[2] https://lore.kernel.org/all/arr1VgGZmgUmY4hc@xxxxxxxxxx/
Fred Griffoul (2):
KVM: Add helpers to allocate memslot metadata
KVM: Use kvzalloc() for memslot metadata that fits in a slab bucket
arch/x86/kvm/mmu/page_track.c | 6 +++---
arch/x86/kvm/x86.c | 10 +++++-----
include/linux/kvm_host.h | 2 ++
virt/kvm/kvm_main.c | 22 ++++++++++++++++++++--
4 files changed, 30 insertions(+), 10 deletions(-)
base-commit: d21eef2084a9af87ac2a783bc7c2b175ba114e4e
--
2.47.3