All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/3] KVM: riscv: Reclaim unused G-stage page tables
@ 2026-11-29 14:22 ` Tan Chi
  0 siblings, 0 replies; 13+ messages in thread
From: Tan Chi @ 2026-11-29 14:22 UTC (permalink / raw)
  To: anup
  Cc: atish.patra, pjw, palmer, aou, alex, kvm, kvm-riscv, linux-riscv,
	Tan Chi

The current G-stage unmap implementation retains unused page tables
until the VM is destroyed.

This series introduces a recursive page table walker, similar to the
arm64 stage-2 page table walker, as a basis for reclaiming unused
G-stage page tables.

Different reclamation policies are used depending on the unmap context:

- Memslot removal: reclaim fully covered page tables that are empty
  after unmapping.
- MMU notifier invalidation: reclaim fully covered page tables that
  were already empty before unmapping.
- I/O unmapping: keep the existing behavior, as the current use case
  only unmaps individual IMSIC pages.

A similar selective reclamation approach has been proposed for the
x86 TDP MMU [1].

Testing
=======

Tests were performed on a RISC-V KVM host running under QEMU TCG
with 2 vCPUs and 2 GiB of memory.

Performance
-----------

Each memslot_perf_test subtest was run in three interleaved
baseline/patched pairs with the slot limit set to 32.

The following table shows the mean time per iteration and the
range of individual paired percentage changes.

    Test                  Before       After    Change      Range
    ----------------------------------------------------------------------
    Map                 15.710 s    16.338 s    +4.00%   -2.32% to  +8.47%
    Single-page unmap   11.664 s    12.006 s    +2.93%   -4.16% to  +8.04%
    Chunked unmap       45.990 ms   45.299 ms   -1.50%   -2.37% to  -1.01%
    Move active         15.414 ms   15.186 ms   -1.48%   -6.86% to  +1.50%
    Move inactive       13.599 ms   12.688 ms   -6.70%  -12.57% to  -2.70%
    RW                 169.537 s   172.291 s    +1.62%   -3.76% to  +5.73%

Positive values indicate increased execution time. The RW subtest
completed one iteration per run.

Page table reclamation and the additional TLB synchronization
required before freeing detached page tables introduce overhead
that may affect performance in some workloads.

Memory reclamation
------------------

With one 4 KiB mapping per 2 MiB of GPA space, memslot removal reduced
G-stage page table memory usage from 2084 KiB to 32 KiB for a 1 GiB
memslot, and from 16448 KiB to 32 KiB for an 8 GiB memslot.

For a 1 GiB sparse mapping repeatedly invalidated and accessed again,
the remaining page table memory usage was:

    Hot region      Before       After    Reduction
    ------------------------------------------------
    10%            2084 KiB     240 KiB       88.5%
    50%            2084 KiB    1060 KiB       49.1%
    90%            2084 KiB    1876 KiB       10.0%

Memory usage was measured with additional G-stage page table accounting.

RFC notes
------------------

The mean single-page unmap time increased, although the results
varied across runs. Obtaining consistent performance results under
QEMU TCG has been difficult. I will try to address this issue in
the next revision.

To mitigate the single-page unmap overhead, the current implementation
retains a separate leaf lookup path in kvm_riscv_gstage_unmap_range().
Suggestions on reducing this overhead while sharing the recursive
walker would be appreciated.

Feedback on the reclamation policies and other aspects of the design
is also very welcome.

[1] https://lore.kernel.org/kvm/apVOV56MX4p4anIM@192.168.1.215/

Tan Chi (3):
  KVM: riscv: Introduce a recursive G-stage unmap walker
  KVM: riscv: Reclaim G-stage page tables on memslot removal
  KVM: riscv: Selectively reclaim G-stage page tables on invalidation

 arch/riscv/include/asm/kvm_gstage.h |  14 ++-
 arch/riscv/kvm/gstage.c             | 180 ++++++++++++++++++++++++----
 arch/riscv/kvm/mmu.c                |   8 +-
 3 files changed, 174 insertions(+), 28 deletions(-)


base-commit: bc069e58fa1c1da46f7601840f2079a381370893
-- 
2.53.0


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-11-29 14:37 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 14:22 [RFC PATCH 0/3] KVM: riscv: Reclaim unused G-stage page tables Tan Chi
2026-11-29 14:22 ` Tan Chi
2026-11-29 14:22 ` Tan Chi
2026-11-29 14:22 ` [RFC PATCH 1/3] KVM: riscv: Introduce a recursive G-stage unmap walker Tan Chi
2026-11-29 14:22   ` Tan Chi
2026-11-29 14:22   ` Tan Chi
2026-11-29 14:37   ` sashiko-bot
2026-11-29 14:22 ` [RFC PATCH 2/3] KVM: riscv: Reclaim G-stage page tables on memslot removal Tan Chi
2026-11-29 14:22   ` Tan Chi
2026-11-29 14:22   ` Tan Chi
2026-11-29 14:22 ` [RFC PATCH 3/3] KVM: riscv: Selectively reclaim G-stage page tables on invalidation Tan Chi
2026-11-29 14:22   ` Tan Chi
2026-11-29 14:22   ` Tan Chi

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.