Re: [PATCH] KVM: Use kvcalloc() to allocate lpage_info arrays and dirty bitmaps

From: Sean Christopherson

Date: Mon Sep 28 2026 - 19:17:10 EST


On Sat, Aug 15, 2026, Mushahid Hussain wrote:
> __vcalloc() makes every allocation at least a page, so a single page
> memslot consumes 8 KiB of vmalloc for 8 bytes of lpage_info and
> another 4 KiB for a 16 byte dirty bitmap when dirty logging is
> enabled. This overhead scales with the number of slots and VMs on a
> host, adding up to memory pressure when guest address spaces are
> fragmented into small slots.

If memslots are fragmented that badly, then the rmaps are also going to be
extremely wasteful.

> The rmap and gfn_write_track arrays keep __vcalloc() and vfree():
> the 4K rmap and gfn_write_track are per-page arrays, 8 and 2 bytes
> per 4 KiB page, which legitimately cross INT_MAX below the 8 TiB
> slot ceiling; the smaller higher-level rmaps share the 4K rmap's
> allocation loop; and none of them allocate under the TDP MMU,

Until nested virtualization gets used, and then KVM pays the overhead cost for
every memslot.

Rather than flip-flop because of a semi-arbitrary limit that has nothing to do
with KVM, I think we should provide dedicated KVM APIs for allocating memslot
metadata, and pick a pivot that makes sense for KVM. Or just pivot on INT_MAX
to route to kv() vs. v() to play nice with the "not crazy" rule.

> where the waste above was observed.