All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Usama Arif" <usama.arif@linux.dev>
Cc: kvmarm@lists.linux.dev, "Oliver Upton" <oupton@kernel.org>,
	"Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH] KVM: arm64: Reduce the stage-2 page cache on 64 KiB hosts
Date: Fri, 27 Nov 2026 14:45:03 +0000	[thread overview]
Message-ID: <sashiko-outbox-237597@kernel.org> (raw)
In-Reply-To: <d2b6e735-a685-4e79-bb39-2fb75ebecd09@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] KVM: arm64: unstripped reply thread and obsolete v1 title in
  commit message
--

commit 77fb1ee741e0e031f8b2fbef9f4459a6c491e152
Author: Usama Arif <usama.arif@linux.dev>

> KVM: arm64: Reduce the stage-2 page cache on 64 KiB hosts
> 
> On 26/11/2026 07:58, Marc Zyngier wrote:
> > On Thu, 26 Nov 2026 14:32:04 +0000,
> > Usama Arif <usama.arif@linux.dev> 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.
> 
> From dad1d43f1c2dcb8ffbc8084ec19467731e8548f4 Mon Sep 17 00:00:00 2001
> From: Usama Arif <usama.arif@linux.dev>
> Date: Fri, 27 Nov 2026 06:07:35 -0800
> Subject: [PATCH] KVM: arm64: Size the stage-2 memcache from
>  kvm_mmu_cache_min_pages()
> 
> When fewer than kvm_mmu_cache_min_pages() pages are left, a stage-2
> fault that may need new tables refills the vCPU's memcache to
> KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE, 40 on arm64. A map allocates at most
> one table per level below the preallocated root, which is
> kvm_mmu_cache_min_pages() and at most 3 pages. Only vCPU destruction
> frees the memcache, so whatever a refill leaves unused stays allocated:
> up to 2.5 MiB per vCPU with 64 KiB pages. On a 64 KiB host running 101
> VMs with 4 vCPUs and 1 GiB each, the memcaches held 986 MiB, against
> 25 MiB of stage-2 tables in use.
> 
> Size the memcache at twice the largest kvm_mmu_cache_min_pages() of the
> VM's stage-2s instead, so that each refill covers at least two
> worst-case maps. With NV, the vCPU's memcache also feeds the shadow
> stage-2s, and a memcache's capacity can't change once used, so record
> the largest value as each stage-2 is initialised. The VM's stage-2 is
> set up at VM creation and the first shadow stage-2s by the first
> KVM_ARM_VCPU_INIT, before any vCPU can fault, and later shadow stage-2s
> have the same size. kvm_phys_addr_ioremap()'s temporary memcache uses
> the same capacity, so arm64 no longer uses the value of
> KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE.
> 
> With a 48-bit IPA, the capacity is 4 pages with 16 KiB and 64 KiB pages
> and 6 with 4 KiB pages; with the default 40-bit IPA, 2 and 4. On the
> host above and on a production host also running 101 VMs with 4 vCPUs
> each, both with 64 KiB pages and 48-bit IPA VMs:
> 
>                      memcaches                saved
>                      before      after
>   host above         986 MiB     81 MiB       905 MiB
>   production host    869 MiB     <= 101 MiB   >= 768 MiB
> 
> A memcache now refills at most once every two tables, as a capacity of
> 4 does with 4 KiB pages and a 48-bit IPA. Measured that way, per fault
> for the median vCPU, one VM at a time:
> 
>                                         40           4
>   2M blocks split under dirty logging   4.9-5.1 us   4.9-5.0 us
>   1G block split, then refaulted        2.7-2.8 us   2.8 us
>   every fault allocating a table        4.0-4.1 us   3.7-4.1 us
> 
> Suggested-by: Marc Zyngier <maz@kernel.org>
> Signed-off-by: Usama Arif <usama.arif@linux.dev>

[Severity: Low]
This isn't a bug, but the commit retains the v1 subject ("KVM: arm64:
Reduce the stage-2 page cache on 64 KiB hosts"), the preceding mailing-list
reply discussion, and the embedded format-patch headers, whereas
kvm_init_stage2_mmu() sizes mmu_page_cache_capacity from 2 *
kvm_mmu_cache_min_pages(mmu) for all host page sizes as described by the
embedded subject ("KVM: arm64: Size the stage-2 memcache from
kvm_mmu_cache_min_pages()").

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/d2b6e735-a685-4e79-bb39-2fb75ebecd09@linux.dev?part=1

  reply	other threads:[~2026-11-27 14:45 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 15:28 [PATCH] KVM: arm64: Reduce the stage-2 page cache on 64 KiB hosts 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-25 21:53         ` sashiko-bot
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-27 13:29               ` Lorenzo Stoakes (ARM)
2026-11-27 14:38                 ` Usama Arif
2026-11-26 12:56 ` Marc Zyngier
2026-11-26 14:32   ` Usama Arif
2026-11-26 15:58     ` Marc Zyngier
2026-11-26 16:52       ` Lorenzo Stoakes (ARM)
2026-11-27 14:28       ` Usama Arif
2026-11-27 14:45         ` sashiko-bot [this message]
2026-11-30 14:21         ` Usama Arif

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=sashiko-outbox-237597@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=usama.arif@linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.