From: Marc Zyngier <maz@kernel.org>
To: Usama Arif <usama.arif@linux.dev>
Cc: oupton@kernel.org, fuad.tabba@linux.dev, joey.gouly@arm.com,
seiden@linux.ibm.com, suzuki.poulose@arm.com,
yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org,
mark.rutland@arm.com, kvmarm@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, riel@surriel.com,
shakeel.butt@linux.dev, kernel-team@meta.com, rkeilty@meta.com,
atish.patra@linux.dev, dgreid@meta.com
Subject: Re: [PATCH] KVM: arm64: Reduce the stage-2 page cache on 64 KiB hosts
Date: Thu, 26 Nov 2026 12:56:12 +0000 [thread overview]
Message-ID: <86wlpzycnn.wl-maz@kernel.org> (raw)
In-Reply-To: <20261124152842.2634495-1-usama.arif@linux.dev>
On Tue, 24 Nov 2026 15:28:42 +0000,
Usama Arif <usama.arif@linux.dev> wrote:
>
> When a stage-2 fault may need new page tables, KVM first tops up the
> vCPU's page cache: if it holds fewer pages than the fault might need, it
> is refilled to KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE, which arm64 sets to
> 40. Unused pages stay in the cache until the vCPU is destroyed.
>
> With 64 KiB pages, that is 2.5 MiB per vCPU, and most of it is never
> used. Stage-2 has at most three levels and the root is preallocated, so
> a fault needs at most two new table pages (kvm_mmu_cache_min_pages()).
> As every last-level table covers 512 MiB, an 8 GiB guest needs just 17
> table pages to map all of its memory, while its four vCPU caches get
> filled with 160.
>
> On a production host with 64 KiB pages running 101 VMs with four vCPUs
> each, the caches were still 86% full. The memory used:
>
> before after
> per-vCPU capacity 2.5 MB 512 KB
> all 404 vCPUs 869 MB <= 202 MB
>
> Let's lower the capacity to 8 with 64 KiB pages, In the production
> usecase above, it frees at least 667 MB. That still covers the two-page
> minimum and leaves room for several table allocations per refill. 4 KB
> and 16 KB pages keep 40.
I'll glance over the use of 64kB pages, because that's definitely a
niche configuration that hardly anyone uses. But the scale of the
numbers strike me a bit: 808GB worth of guest memory, and you're
complaining about 869MB? That's roughly 0.1% of the total, and the
savings you're gaining are even less... I know memory is expensive,
but you'd save a lot more than that by using a realistic page size.
Just saying...
I also question the assumption you are making that the guest is
strictly using IPA contiguous memory, and that therefore a very small
set of pages are all you need to map a guest. Guests with multiple,
disjoint memslots are (sadly) extremely common, specially in these
days of tiered memory and other random horrors.
>
> The temporary cache in kvm_phys_addr_ioremap() uses the same capacity,
> but it is topped up before every page it maps, so 8 is sufficient there
> as well. The pKVM hypervisor memcache and the eager split cache don't
> use this capacity.
>
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
> ---
> arch/arm64/include/asm/kvm_types.h | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/arch/arm64/include/asm/kvm_types.h b/arch/arm64/include/asm/kvm_types.h
> index 9a126b9e2d7c99..28568da9ea4a7b 100644
> --- a/arch/arm64/include/asm/kvm_types.h
> +++ b/arch/arm64/include/asm/kvm_types.h
> @@ -2,7 +2,12 @@
> #ifndef _ASM_ARM64_KVM_TYPES_H
> #define _ASM_ARM64_KVM_TYPES_H
>
> +/* Must cover kvm_mmu_cache_min_pages(), at most 2 with 64 KiB pages. */
> +#ifdef CONFIG_ARM64_64K_PAGES
> +#define KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE 8
> +#else
> #define KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE 40
> +#endif
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.
Thanks,
M.
--
Without deviation from the norm, progress is not possible.
next prev parent reply other threads:[~2026-11-26 12:56 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 15:28 Usama Arif
2026-11-25 17:14 ` Leonardo Bras
2026-11-25 17:55 ` Usama Arif
2026-11-25 18:25 ` Leonardo Bras
2026-11-25 21:42 ` Usama Arif
2026-11-26 8:06 ` Wei-Lin Chang
2026-11-26 15:19 ` Leonardo Bras
2026-11-26 15:34 ` Wei-Lin Chang
2026-11-26 15:55 ` Leonardo Bras
2026-11-26 16:45 ` Lorenzo Stoakes (ARM)
2026-11-26 17:07 ` Leonardo Bras
2026-11-26 17:18 ` Lorenzo Stoakes (ARM)
2026-11-26 17:44 ` Leonardo Bras
2026-11-26 16:30 ` Lorenzo Stoakes (ARM)
2026-11-26 16:53 ` Lorenzo Stoakes (ARM)
2026-11-26 18:25 ` Leonardo Bras
2026-11-26 12:56 ` Marc Zyngier [this message]
2026-11-26 14:32 ` Usama Arif
2026-11-26 15:58 ` Marc Zyngier
2026-11-26 16:52 ` Lorenzo Stoakes (ARM)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86wlpzycnn.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=atish.patra@linux.dev \
--cc=catalin.marinas@arm.com \
--cc=dgreid@meta.com \
--cc=fuad.tabba@linux.dev \
--cc=joey.gouly@arm.com \
--cc=kernel-team@meta.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=oupton@kernel.org \
--cc=riel@surriel.com \
--cc=rkeilty@meta.com \
--cc=seiden@linux.ibm.com \
--cc=shakeel.butt@linux.dev \
--cc=suzuki.poulose@arm.com \
--cc=usama.arif@linux.dev \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®