Re: [PATCH] KVM: arm64: Reduce the stage-2 page cache on 64 KiB hosts

From: Usama Arif

Date: Fri Nov 27 2026 - 09:32:58 EST




On 26/11/2026 07:58, Marc Zyngier wrote:
> On Thu, 26 Nov 2026 14:32:04 +0000,
> Usama Arif <usama.arif@xxxxxxxxx> wrote:
>
> [nonsense deleted]
>
>>> Now, to the patch itself: I see no reason to special-case this. If
>>> kvm_mmu_cache_min_pages() is an indication of what is needed, then
>>> this macro should be driven by it, or the whole allocator take it into
>>> account. And then you adjust it by whatever fudge factor seems
>>> appropriate.
>>>
>>
>> Completely agree! [1] does that: no page-size special case, and
>> a capacity of KVM_PGTABLE_LAST_LEVEL - KVM_PGTABLE_FIRST_LEVEL for every
>> page size. It can't track kvm_mmu_cache_min_pages()
>> at runtime: the vCPU's cache is shared by the canonical and NV shadow
>> MMUs, and its capacity must stay fixed. So it has to cover the largest
>> minimum, which stage-2 caps at 3, and 4 is that plus one page of fudge.
>
> Of course it can. That's not exactly rock science to add, rather than
> relying on another set of bad heuristics.

You're right, it can. __kvm_mmu_topup_memory_cache() fixes a cache's
capacity at its first refill, but nothing requires that to be a
compile-time constant. Does something like the patch below work for
you? Each VM records twice the largest kvm_mmu_cache_min_pages() of its
stage-2s as they are initialised, and every top-up passes that to
__kvm_mmu_topup_memory_cache(), as the eager-split cache already does.


> And this must cover more
> than a single mapping per top-up, because that has a ripple effect on
> the speed at which we can split large blocks (funnily enough, people
> care about that stuff).
>
> M.
>

With twice the minimum, each refill covers at least two worst-case
maps. I asked a LLM to comeup with a way to time for block splitting and pagefaults
and I found it reasonable, I have attached the results in the commit message.

Does a factor of 2 sound reasonable to everyone?

If this looks ok, happy to send as v2.