On Tue, Feb 18, 2025 at 5:13 PM Sean Christopherson <seanjc@xxxxxxxxxx> wrote: > > On Tue, Feb 18, 2025, Maxim Levitsky wrote: > > On Tue, 2025-02-04 at 00:40 +0000, James Houghton wrote: > > > By aging sptes locklessly with the TDP MMU and the shadow MMU, neither > > > vCPUs nor reclaim (mmu_notifier_invalidate_range*) will get stuck > > > waiting for aging. This contention reduction improves guest performance > > > and saves a significant amount of Google Cloud's CPU usage, and it has > > > valuable improvements for ChromeOS, as Yu has mentioned previously[1]. > > > > > > Please see v8[8] for some performance results using > > > access_tracking_perf_test patched to use MGLRU. > > > > > > Neither access_tracking_perf_test nor mmu_stress_test trigger any > > > splats (with CONFIG_LOCKDEP=y) with the TDP MMU and with the shadow MMU. > > > > > > Hi, I have a question about this patch series and about the > > access_tracking_perf_test: > > > > Some time ago, I investigated a failure in access_tracking_perf_test which > > shows up in our CI. > > > > The root cause was that 'folio_clear_idle' doesn't clear the idle bit when > > MGLRU is enabled, and overall I got the impression that MGLRU is not > > compatible with idle page tracking. > > > > I thought that this patch series and the 'mm: multi-gen LRU: Have secondary > > MMUs participate in MM_WALK' patch series could address this but the test > > still fails. > > > > > > For the reference the exact problem is: > > > > 1. Idle bits for guest memory under test are set via /sys/kernel/mm/page_idle/bitmap > > > > 2. Guest dirties memory, which leads to A/D bits being set in the secondary mappings. > > > > 3. A NUMA autobalance code write protects the guest memory. KVM in response > > evicts the SPTE mappings with A/D bit set, and while doing so tells mm > > that pages were accessed using 'folio_mark_accessed' (via kvm_set_page_accessed (*) ) > > but due to MLGRU the call doesn't clear the idle bit and thus all the traces > > of the guest access disappear and the kernel thinks that the page is still idle. > > > > I can say that the root cause of this is that folio_mark_accessed doesn't do > > what it supposed to do. > > > > Calling 'folio_clear_idle(folio);' in MLGRU case in folio_mark_accessed() > > will probably fix this but I don't have enough confidence to say if this is > > all that is needed to fix this. If this is the case I can send a patch. > > My understanding is that the behavior is deliberate. Per Yu[1], page_idle/bitmap > effectively isn't supported by MGLRU. > > [1] https://lore.kernel.org/all/CAOUHufZeADNp_y=Ng+acmMMgnTR=ZGFZ7z-m6O47O=CmJauWjw@xxxxxxxxxxxxxx Yu's suggestion was to look at the generation numbers themselves, and that is exactly what my patched access_tracking_perf_test does[2]. :) So I think to make this work with MGLRU, I'll re-post my access_tracking_perf_test patch, but if MGLRU is enabled, always use the MGLRU debugfs instead of using page_idle/bitmap. It needs some cleanup first though. [2]: https://lore.kernel.org/kvm/20241105184333.2305744-12-jthoughton@xxxxxxxxxx/ > > Any ideas on how to fix all this mess? > > The easy answer is to skip the test if MGLRU is in use, or if NUMA balancing is > enabled. In a real-world scenario, if the guest is actually accessing the pages > that get PROT_NONE'd by NUMA balancing, they will be marked accessed when they're > faulted back in. There's a window where page_idle/bitmap could be read between > making the VMA PROT_NONE and re-accessing the page from the guest, but IMO that's > one of the many flaws of NUMA balancing. > > That said, one thing is quite odd. In the failing case, *half* of the guest pages > are still idle. That's quite insane. > > Aha! I wonder if in the failing case, the vCPU gets migrated to a pCPU on a > different node, and that causes NUMA balancing to go crazy and zap pretty much > all of guest memory. If that's what's happening, then a better solution for the > NUMA balancing issue would be to affine the vCPU to a single NUMA node (or hard > pin it to a single pCPU?). +1 to this idea, if this is really what's going on. If NUMA balancing is only migrating a few pages, the 90% threshold in the test should be low enough that we tolerate the few pages that were moved. Or we could just print a warning (instead of fail) if NUMA balancing is enabled.