History

KVM: Dynamically size memslot array based on number of used slots

Now that the memslot logic doesn't assume memslots are always non-NULL, dynamically size the array of memslots instead of unconditionally allocating memory for the maximum number of memslots. Note, because a to-be-deleted memslot must first be invalidated, the array size cannot be immediately reduced when deleting a memslot. However, consecutive deletions will realize the memory savings, i.e. a second deletion will trim the entry.

Sean Christopherson committed 6 years ago

Commit 36947251 parent 0577d1a2 files · +29 −4Browse files

Showing the changes to include/linux (1 of 2 files). Show all

Unified · Split

include/linux/kvm_host.h+1−1
@@ -431,11 +431,11 @@ static inline int kvm_arch_vcpu_memslots_id(struct kvm_vcpu *vcpu) · 430 unmodified lines
431 */431 */
432struct kvm_memslots {432struct kvm_memslots {
433 u64 generation;433 u64 generation;
434 struct kvm_memory_slot memslots[KVM_MEM_SLOTS_NUM];
435 /* The mapping table from slot id to the index in memslots[]. */434 /* The mapping table from slot id to the index in memslots[]. */
436 short id_to_index[KVM_MEM_SLOTS_NUM];435 short id_to_index[KVM_MEM_SLOTS_NUM];
437 atomic_t lru_slot;436 atomic_t lru_slot;
438 int used_slots;437 int used_slots;
438 struct kvm_memory_slot memslots[];
439};439};
440 440
441struct kvm {441struct kvm {