Re: [PATCH v2] KVM: x86/mmu: Expose number of shadow MMU shadow pages as a stat
From: Yosry Ahmed
Date: Mon Jun 15 2026 - 16:58:42 EST
On Fri, Jun 12, 2026 at 6:37 AM Sean Christopherson <seanjc@xxxxxxxxxx> wrote:
>
> Turn arch.n_used_mmu_pages into a stat, mmu_shadow_pages, as the number of
> live shadow pages is arguably _the_ most critical datapoint when it comes
> to analyzing the shadow MMU. Before the TDP MMU came along, i.e. when the
> shadow MMU was the only MMU, explicitly tracking the number of shadow pages
> wasn't as interesting, because the same information could more or less be
> gleaned from the pages_{1g,2m,4k} stats. But with the TDP MMU, where the
> shadow MMU is only used for nested TDP, it becomes extremely difficult, if
> not impossible, to determine which SPTEs are coming from the TDP MMU, and
> which are coming from the shadow MMU.
>
> E.g. when triaging/debugging shadow MMU performance issues due to "too many
> shadow pages", being able to observe that 99%+ of all shadow pages are
> unsync is critical to being able to deduce that KVM is effectively leaking
> shadow pages.
Why not expose indirect_shadow_pages? IIRC that was also one of the
stats we (mostly you) used while debugging?
I guess for most cases, mmu_shadow_pages will represent either the MMU
pages used to shadow the VM's x86 page tables (with TDP off) or nested
TDP MMU pages (with TDP on and nested used) -- but I do remember some
interesting case about direct mappings in the shadow MMU or sth?
I could be hallucinating this (I was bit by an AI agent).
>
> Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>