Commit 8593176c authored by Paolo Bonzini's avatar Paolo Bonzini

kvm: memslots: track id_to_index changes during the insertion sort

This completes the optimization from the previous patch, by
removing the KVM_MEM_SLOTS_NUM-iteration loop from insert_memslot.
Reviewed-by: default avatarIgor Mammedov <imammedo@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 063584d4
...@@ -677,31 +677,31 @@ static int kvm_create_dirty_bitmap(struct kvm_memory_slot *memslot) ...@@ -677,31 +677,31 @@ static int kvm_create_dirty_bitmap(struct kvm_memory_slot *memslot)
static void insert_memslot(struct kvm_memslots *slots, static void insert_memslot(struct kvm_memslots *slots,
struct kvm_memory_slot *new) struct kvm_memory_slot *new)
{ {
int i = slots->id_to_index[new->id]; int id = new->id;
struct kvm_memory_slot *old = id_to_memslot(slots, new->id); int i = slots->id_to_index[id];
struct kvm_memory_slot *mslots = slots->memslots; struct kvm_memory_slot *mslots = slots->memslots;
if (new->npages == old->npages) { WARN_ON(mslots[i].id != id);
*old = *new; if (new->npages != mslots[i].npages) {
return; if (new->npages < mslots[i].npages) {
} while (i < KVM_MEM_SLOTS_NUM - 1 &&
while (1) {
if (i < (KVM_MEM_SLOTS_NUM - 1) &&
new->npages < mslots[i + 1].npages) { new->npages < mslots[i + 1].npages) {
mslots[i] = mslots[i + 1]; mslots[i] = mslots[i + 1];
slots->id_to_index[mslots[i].id] = i;
i++; i++;
} else if (i > 0 && new->npages > mslots[i - 1].npages) { }
} else {
while (i > 0 &&
new->npages > mslots[i - 1].npages) {
mslots[i] = mslots[i - 1]; mslots[i] = mslots[i - 1];
slots->id_to_index[mslots[i].id] = i;
i--; i--;
} else { }
mslots[i] = *new;
break;
} }
} }
for (i = 0; i < KVM_MEM_SLOTS_NUM; i++) mslots[i] = *new;
slots->id_to_index[slots->memslots[i].id] = i; slots->id_to_index[mslots[i].id] = i;
} }
static void update_memslots(struct kvm_memslots *slots, static void update_memslots(struct kvm_memslots *slots,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment