diff options
author | Igor Mammedov <imammedo@redhat.com> | 2014-12-01 12:29:27 -0500 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2014-12-04 09:29:11 -0500 |
commit | 9c1a5d38780e652275aa55362dbee0d7e827e069 (patch) | |
tree | 0fc252e3948a30b78974e3ba8979d5aa231de22f /virt/kvm | |
parent | 0e60b0799fedc495a5c57dbd669de3c10d72edd2 (diff) |
kvm: optimize GFN to memslot lookup with large slots amount
Current linear search doesn't scale well when
large amount of memslots is used and looked up slot
is not in the beginning memslots array.
Taking in account that memslots don't overlap, it's
possible to switch sorting order of memslots array from
'npages' to 'base_gfn' and use binary search for
memslot lookup by GFN.
As result of switching to binary search lookup times
are reduced with large amount of memslots.
Following is a table of search_memslot() cycles
during WS2008R2 guest boot.
boot, boot + ~10 min
mostly same of using it,
slot lookup randomized lookup
max average average
cycles cycles cycles
13 slots : 1450 28 30
13 slots : 1400 30 40
binary search
117 slots : 13000 30 460
117 slots : 2000 35 180
binary search
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'virt/kvm')
-rw-r--r-- | virt/kvm/kvm_main.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 162817f853ec..759af6596a07 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c | |||
@@ -679,8 +679,14 @@ static void update_memslots(struct kvm_memslots *slots, | |||
679 | struct kvm_memory_slot *mslots = slots->memslots; | 679 | struct kvm_memory_slot *mslots = slots->memslots; |
680 | 680 | ||
681 | WARN_ON(mslots[i].id != id); | 681 | WARN_ON(mslots[i].id != id); |
682 | if (!new->npages) | 682 | if (!new->npages) { |
683 | new->base_gfn = 0; | 683 | new->base_gfn = 0; |
684 | if (mslots[i].npages) | ||
685 | slots->used_slots--; | ||
686 | } else { | ||
687 | if (!mslots[i].npages) | ||
688 | slots->used_slots++; | ||
689 | } | ||
684 | 690 | ||
685 | while (i < KVM_MEM_SLOTS_NUM - 1 && | 691 | while (i < KVM_MEM_SLOTS_NUM - 1 && |
686 | new->base_gfn <= mslots[i + 1].base_gfn) { | 692 | new->base_gfn <= mslots[i + 1].base_gfn) { |