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

From: Lorenzo Stoakes (ARM)

Date: Thu Nov 26 2026 - 12:18:12 EST


On Thu, Nov 26, 2026 at 05:07:21PM +0000, Leonardo Bras wrote:
> On Thu, Nov 26, 2026 at 04:45:35PM +0000, Lorenzo Stoakes (ARM) wrote:
> > The question is would going from 40 to 3 slow things down?
> >
> > At 40 you do 40 __get_free_page() calls on topup for the _first_ fault that hits
> > it, which adds latency to a random s2 fault (not great).
> >
> > (If the fault doesn't in fact use a page table, this is only done once until a
> > page table is next needed).
> >
> > And then as 37 page tables are mapped, those ones don't get allocations at 38
> > you go again...
> >
> > With 3 in the cache you allocate up to 3 for each fault.
> >
> > So in both cases you allocate the same amount of pages but in the 40 case it's
> > all bunched up on one s2 fault with a jump in latency, in the 3 case it's spread
> > out.
> >
> > I'd say 3 is therefore the better choice.
> >
> > Also, as mentioned elsewhere, you end up leaking pages once the S2 page tables
> > are setup until the vCPU is destroyed, as nothing clears down the cache
> > AFAICT. With 40 that's way more than with 3.
> >
> > --
> > Cheers, Lorenzo
>
> Hi Lorenzo,
>
> When I mention cache locality above, I mean the cpu cache. Running the same
> routine 40 times in a row can be faster since all instructions are already
> cached, and most of the data acessed by it could be local as well.
>
> If you run it more often, it could be that something else used the
> cachelines and the cpu has to fetch them again from lower level caches or
> memory.
>
> That being said, that's the only reason batch allocating 40 would be faster
> than 4 in the long run. For capacity=4, the number of
> mmu_memory_cache_alloc_obj() calls can be even smaller than capacity=40,
> since we don't leave unused pages in the kvm_mmu_memory_cache.

Ah right I see what you mean, true that would be warmer, but I suspect that'd be
lost in the noise vs. zeroing each page anyway, and additionally you can argue
that, if you just zeroed a page before the walk uses it, there's locality
advantages on that vs. batched too.

But again I'd be very surprised if there was any impact on that either way,
really.

In any case it seems we agree that a smaller capacity is the way to go :)

--
Cheers, Lorenzo