Skip to content

Commit

Permalink
kvm: update_memslots: drop not needed check for the same slot
Browse files Browse the repository at this point in the history
UP/DOWN shift loops will shift array in needed
direction and stop at place where new slot should
be placed regardless of old slot size.

Signed-off-by: Igor Mammedov <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
Igor Mammedov authored and bonzini committed Dec 4, 2014
1 parent 5a38b6e commit 7f379cf
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,20 +679,17 @@ static void update_memslots(struct kvm_memslots *slots,
struct kvm_memory_slot *mslots = slots->memslots;

WARN_ON(mslots[i].id != id);
if (new->npages < mslots[i].npages) {
while (i < KVM_MEM_SLOTS_NUM - 1 &&
new->npages < mslots[i + 1].npages) {
mslots[i] = mslots[i + 1];
slots->id_to_index[mslots[i].id] = i;
i++;
}
} else {
while (i > 0 &&
new->npages > mslots[i - 1].npages) {
mslots[i] = mslots[i - 1];
slots->id_to_index[mslots[i].id] = i;
i--;
}
while (i < KVM_MEM_SLOTS_NUM - 1 &&
new->npages < mslots[i + 1].npages) {
mslots[i] = mslots[i + 1];
slots->id_to_index[mslots[i].id] = i;
i++;
}
while (i > 0 &&
new->npages > mslots[i - 1].npages) {
mslots[i] = mslots[i - 1];
slots->id_to_index[mslots[i].id] = i;
i--;
}

mslots[i] = *new;
Expand Down

0 comments on commit 7f379cf

Please sign in to comment.