[PATCH 0/7] mshv: Reduce memory consumption for unpinned regions
From: Stanislav Kinsburskii
Date: Wed Apr 01 2026 - 18:19:05 EST
This series reduces memory consumption for unpinned regions by avoiding
PFN array allocation. A 1GB unpinned region currently wastes 2MB for an
unused PFN array that HMM-managed regions don't need.
The first three patches are preparatory refactoring. Patch 1 consolidates
region creation and mapping logic, reducing API surface by 4 functions.
Patch 2 introduces a typedef for PFN handler callbacks to simplify
function signatures. Patch 3 renames mshv_mem_region to mshv_region to
align with existing function naming conventions.
Patch 4 optimizes unmap and no-access remap operations by eliminating
redundant PFN iteration when all frames are guaranteed to be mapped.
This uses large page flags for aligned chunks and removes unnecessary
helper functions.
Patches 5-6 decouple PFN processing from the region->pfns storage.
Patch 5 threads the pfns pointer explicitly through the processing
chain. Patch 6 removes offset-based indexing by having callers pass
pre-offset pointers.
Patch 7 converts the pfns array from a flexible array member to a
conditional pointer, allocated only for pinned regions that need it
for share/unshare/evict operations. This eliminates the memory waste
for unpinned regions and allows using kzalloc instead of vzalloc.
---
Stanislav Kinsburskii (7):
mshv: Consolidate region creation and mapping
mshv: Improve code readability with handler function typedef
mshv: Rename mshv_mem_region to mshv_region
mshv: Optimize memory region mapping operations
mshv: Pass pfns array explicitly through processing chain
mshv: Simplify pfn array handling in region processing
mshv: Allocate pfns array only for pinned regions
drivers/hv/mshv_regions.c | 345 +++++++++++++++++++++++++------------------
drivers/hv/mshv_root.h | 26 ++-
drivers/hv/mshv_root_main.c | 79 ++++------
3 files changed, 248 insertions(+), 202 deletions(-)