diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2014-11-14 04:22:07 -0500 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2014-11-14 09:40:17 -0500 |
commit | 8593176c677226ead5b4effbd667dd19d5cba5ea (patch) | |
tree | 0aa19b0576aa4a4b2de33293e73a842a8ec70b9a /virt | |
parent | 063584d44377ebde5ebc6e99cedc1bc6561939d7 (diff) |
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: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'virt')
-rw-r--r-- | virt/kvm/kvm_main.c | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index c0c2202e6c4f..eae07f97ecf7 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c | |||
@@ -677,31 +677,31 @@ static int kvm_create_dirty_bitmap(struct kvm_memory_slot *memslot) | |||
677 | static void insert_memslot(struct kvm_memslots *slots, | 677 | static void insert_memslot(struct kvm_memslots *slots, |
678 | struct kvm_memory_slot *new) | 678 | struct kvm_memory_slot *new) |
679 | { | 679 | { |
680 | int i = slots->id_to_index[new->id]; | 680 | int id = new->id; |
681 | struct kvm_memory_slot *old = id_to_memslot(slots, new->id); | 681 | int i = slots->id_to_index[id]; |
682 | struct kvm_memory_slot *mslots = slots->memslots; | 682 | struct kvm_memory_slot *mslots = slots->memslots; |
683 | 683 | ||
684 | if (new->npages == old->npages) { | 684 | WARN_ON(mslots[i].id != id); |
685 | *old = *new; | 685 | if (new->npages != mslots[i].npages) { |
686 | return; | 686 | if (new->npages < mslots[i].npages) { |
687 | } | 687 | while (i < KVM_MEM_SLOTS_NUM - 1 && |
688 | 688 | new->npages < mslots[i + 1].npages) { | |
689 | while (1) { | 689 | mslots[i] = mslots[i + 1]; |
690 | if (i < (KVM_MEM_SLOTS_NUM - 1) && | 690 | slots->id_to_index[mslots[i].id] = i; |
691 | new->npages < mslots[i + 1].npages) { | 691 | i++; |
692 | mslots[i] = mslots[i + 1]; | 692 | } |
693 | i++; | ||
694 | } else if (i > 0 && new->npages > mslots[i - 1].npages) { | ||
695 | mslots[i] = mslots[i - 1]; | ||
696 | i--; | ||
697 | } else { | 693 | } else { |
698 | mslots[i] = *new; | 694 | while (i > 0 && |
699 | break; | 695 | new->npages > mslots[i - 1].npages) { |
696 | mslots[i] = mslots[i - 1]; | ||
697 | slots->id_to_index[mslots[i].id] = i; | ||
698 | i--; | ||
699 | } | ||
700 | } | 700 | } |
701 | } | 701 | } |
702 | 702 | ||
703 | for (i = 0; i < KVM_MEM_SLOTS_NUM; i++) | 703 | mslots[i] = *new; |
704 | slots->id_to_index[slots->memslots[i].id] = i; | 704 | slots->id_to_index[mslots[i].id] = i; |
705 | } | 705 | } |
706 | 706 | ||
707 | static void update_memslots(struct kvm_memslots *slots, | 707 | static void update_memslots(struct kvm_memslots *slots, |