[PATCH v1 5/5] KVM: riscv: Age G-stage PTEs locklessly

Anup Patel anup at brainfault.org
Tue Nov 24 21:50:14 PST 2026


On Mon, Sep 21, 2026 at 4:44 PM SeungJu Cheon <suunj1331 at gmail.com> wrote:
>
> Aging G-stage PTEs currently runs with mmu_lock held for write, taken
> by the common MMU notifier code. When MGLRU or kswapd ages a large
> range, every vCPU taking a G-stage fault blocks on the lock, and the
> dirty-logging read-side fast path blocks behind aging as well.
>
> The preceding patches prepare G-stage page-table walks for lockless
> aging by using consistent PTE snapshots, preserving concurrent
> Accessed-bit updates, and deferring page-table frees with RCU.
>
> Select KVM_MMU_LOCKLESS_AGING so the common code no longer takes
> mmu_lock for aging, and protect the G-stage walk with an RCU read-side
> critical section.
>
> Read the root inside the RCU read-side critical section and check the
> resulting snapshot instead of checking kvm->arch.pgd separately before
> initializing the G-stage context. This ensures that the root used by
> the walk remains protected until the walk completes.
>
> On QEMU TCG with 4 vCPUs, running dirty_log_perf_test -v 3 -b 256M -i 3
> with MGLRU aging of the VM's cgroup forced every 100ms (86 passes):
>
>                               before      after
>   mmu_lock write wait, total  44.4 s      0.15 s
>   mmu_lock write contentions  1,002,092   30,092
>   mmu_lock read contentions   351,937     0
>   guest dirty-memory time     18.6 s      16.7 s
>
> Before, 93% of write-lock waiters were kvm_mmu_notifier_clear_young().
> With no aging, no meaningful difference was observed between the two
> kernels.
>
> Signed-off-by: SeungJu Cheon <suunj1331 at gmail.com>

LGTM.

Reviewed-by: Anup Patel <anup at brainfault.org>

Regards,
Anup



More information about the linux-riscv mailing list