From: Sean Christopherson <seanjc@google.com>
To: zhuangel570 <zhuangel570@gmail.com>
Cc: pbonzini@redhat.com, kvm@vger.kernel.org, wanpengli@tencent.com,
alexyonghe@tencent.com, junaids@google.com
Subject: Re: [PATCH 2/2] KVM: x86: introduce cache configurations for previous CR3s
Date: Tue, 5 Nov 2024 17:42:26 -0800 [thread overview]
Message-ID: <ZyrJgh_9q-PoDfL1@google.com> (raw)
In-Reply-To: <CANZk6aSUzdxT-QjCoaSe2BJJnr=W9Gz0WfBV2Lg+SctgZ2DiHQ@mail.gmail.com>
On Wed, Oct 30, 2024, zhuangel570 wrote:
> On Wed, Oct 30, 2024 at 4:38 PM Sean Christopherson <seanjc@google.com> wrote:
> >
> > On Tue, Oct 29, 2024, Yong He wrote:
> > The only potential downside to larger caches I can think of, is that keeping
> > root_count elevated would make it more difficult to reclaim shadow pages from
> > roots that are no longer relevant to the guest. kvm_mmu_zap_oldest_mmu_pages()
> > in particular would refuse to reclaim roots. That shouldn't be problematic for
> > legacy shadow paging, because KVM doesn't recursively zap shadow pages. But for
> > nested TDP, mmu_page_zap_pte() frees the entire tree, in the common case that
> > child SPTEs aren't shared across multiple trees (common in legacy shadow paging,
> > extremely uncommon in nested TDP).
> >
> > And for the nested TDP issue, if it's actually a problem, I would *love* to
> > solve that problem by making KVM's forced reclaim more sophisticated. E.g. one
> > idea would be to kick all vCPUs if the maximum number of pages has been reached,
> > have each vCPU purge old roots from prev_roots, and then reclaim unused roots.
> > It would be a bit more complicated than that, as KVM would need a way to ensure
> > forward progress, e.g. if the shadow pages limit has been reach with a single
> > root. But even then, kvm_mmu_zap_oldest_mmu_pages() could be made a _lot_ smarter.
>
> I not very familiar with TDP on TDP.
> I think you mean force free cached roots in kvm_mmu_zap_oldest_mmu_pages() when
> no mmu pages could be zapped. Such as kick all VCPUs and purge cached roots.
Not just when no MMU pages could be zapped; any time KVM needs to reclaim MMU
pages due to n_max_mmu_pages.
> > TL;DR: what if we simply bump the number of cached roots to ~16?
>
> I set the number to 11 because the PCID in guest kernel is 6 (11+current=12),
> when there are more than 6 processes in guest, the PCID will be reused, then
> cached roots will not easily to hit. The context switch case shows no
> performance gain when process are 7 and 8.
Do you control the guest kernel? If so, it'd be interesting to see what happens
when you bump TLB_NR_DYN_ASIDS in the guest to something higher, and then adjust
KVM to match.
IIRC, Andy arrived at '6' in 10af6235e0d3 ("x86/mm: Implement PCID based optimization:
try to preserve old TLB entries using PCID") because that was the "sweet spot" for
hardware. E.g. using fewer PCIDs wouldn't fully utilize hardware, and using more
PCIDs would oversubscribe the number of ASID tags too much.
For KVM shadow paging, the only meaningful limitation is the number of shadow
pages that KVM allows. E.g. with a sufficiently high n_max_mmu_pages, the guest
could theoretically use hundreds of PCIDs will no ill effects.
prev parent reply other threads:[~2024-11-06 1:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-29 3:13 [PATCH 0/2] Introduce configuration for LRU cache of previous CR3s Yong He
2024-10-29 3:13 ` [PATCH 1/2] KVM: x86: expand the " Yong He
2024-10-29 14:40 ` Sean Christopherson
2024-10-30 12:08 ` zhuangel570
2024-10-29 3:14 ` [PATCH 2/2] KVM: x86: introduce cache configurations for " Yong He
2024-10-29 15:14 ` Sean Christopherson
2024-10-30 12:51 ` zhuangel570
2024-11-06 1:42 ` Sean Christopherson [this message]
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=ZyrJgh_9q-PoDfL1@google.com \
--to=seanjc@google.com \
--cc=alexyonghe@tencent.com \
--cc=junaids@google.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=wanpengli@tencent.com \
--cc=zhuangel570@gmail.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