mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] KVM: Allocate small memslot metadata with kvzalloc()
@ 2026-11-05  0:01 Fred Griffoul
  2026-11-05  0:01 ` [PATCH v2 1/2] KVM: Add helpers to allocate memslot metadata Fred Griffoul
  2026-11-05  0:01 ` [PATCH v2 2/2] KVM: Use kvzalloc() for memslot metadata that fits in a slab bucket Fred Griffoul
  0 siblings, 2 replies; 3+ messages in thread
From: Fred Griffoul @ 2026-11-05  0:01 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini
  Cc: Mushahid Hussain, nh-open-source, kvm, linux-kernel

From: Fred Griffoul <fgriffo@amazon.co.uk>

__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@gmail.com/

[1] https://lore.kernel.org/all/20260815142218.85067-1-hmushi@amazon.co.uk/
[2] https://lore.kernel.org/all/arr1VgGZmgUmY4hc@google.com/

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-05  0:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-05  0:01 [PATCH v2 0/2] KVM: Allocate small memslot metadata with kvzalloc() Fred Griffoul
2026-11-05  0:01 ` [PATCH v2 1/2] KVM: Add helpers to allocate memslot metadata Fred Griffoul
2026-11-05  0:01 ` [PATCH v2 2/2] KVM: Use kvzalloc() for memslot metadata that fits in a slab bucket Fred Griffoul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®