]> git.ipfire.org Git - thirdparty/linux.git/commit
RISC-V: KVM: Avoid redundant page-table allocations in ioremap topup
authorFangyu Yu <fangyu.yu@linux.alibaba.com>
Wed, 10 Jun 2026 09:39:22 +0000 (17:39 +0800)
committerAnup Patel <anup@brainfault.org>
Mon, 13 Jul 2026 07:52:45 +0000 (13:22 +0530)
commit936190fcfcf66695348127992249051467de7072
tree45605cbf33bf3ffb5b6120c5c6a6427f4c0d283d
parenta13c140cc289c0b7b3770bce5b3ad42ab35074aa
RISC-V: KVM: Avoid redundant page-table allocations in ioremap topup

kvm_riscv_mmu_ioremap() currently tops up its on-stack page-table
cache via kvm_mmu_topup_memory_cache(), which allocates up to
KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE (32) objects per topup.

ioremap only consumes non-leaf page-table pages, at most
pgd_levels - 1 (1 to 4) per call, and for contiguous mappings
within the same huge page the non-leaf pages are allocated once
and reused by subsequent pages. Topping up to 32 objects therefore
triggers many unnecessary GFP_KERNEL_ACCOUNT allocations on every
call, all of which are freed when the function returns. In hot
paths (such as vCPU migration), this creates avoidable allocator
churn and wastes CPU cycles.

Use __kvm_mmu_topup_memory_cache() with a capacity of pgd_levels so
the on-stack cache is sized to the maximum demand of a single
mapping. This removes the redundant allocations and reduces per-call
overhead without changing behavior.

Reviewed-by: Anup Patel <anup@brainfault.org>
Signed-off-by: Fangyu Yu <fangyu.yu@linux.alibaba.com>
Link: https://lore.kernel.org/r/20260610093922.51617-1-fangyu.yu@linux.alibaba.com
Signed-off-by: Anup Patel <anup@brainfault.org>
arch/riscv/kvm/mmu.c