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
431431 */
432432 struct kvm_memslots {
433433 u64 generation;
434− struct kvm_memory_slot memslots[KVM_MEM_SLOTS_NUM];
435434 /* The mapping table from slot id to the index in memslots[]. */
436435 short id_to_index[KVM_MEM_SLOTS_NUM];
437436 atomic_t lru_slot;
438437 int used_slots;
438+ struct kvm_memory_slot memslots[];
439439 };
440440
441441 struct kvm {