Re: [PATCH v3 0/8] Lazily allocate memslot rmaps

From: David Hildenbrand
Date: Fri May 07 2021 - 03:40:31 EST


On 06.05.21 20:42, Ben Gardon wrote:
This series enables KVM to save memory when using the TDP MMU by waiting
to allocate memslot rmaps until they are needed. To do this, KVM tracks
whether or not a shadow root has been allocated. In order to get away
with not allocating the rmaps, KVM must also be sure to skip operations
which iterate over the rmaps. If the TDP MMU is in use and we have not
allocated a shadow root, these operations would essentially be op-ops
anyway. Skipping the rmap operations has a secondary benefit of avoiding
acquiring the MMU lock in write mode in many cases, substantially
reducing MMU lock contention.

This series was tested on an Intel Skylake machine. With the TDP MMU off
and on, this introduced no new failures on kvm-unit-tests or KVM selftests.


Happy to see this change pop up, I remember discussing this with Paolo recently.

Another step to reduce the rmap overhead could be looking into using a dynamic datastructure to manage the rmap, instead of allocating a fixed-sized array. That could also significantly reduce memory overhead in some setups and give us more flexibility, for example, for resizing or splitting slots atomically.

--
Thanks,

David / dhildenb