@@ -225,6 +225,7 @@ struct kvm_memslots {
int nmemslots;
int used_slots;
u64 generation;
+ struct kvm_memory_slot *slot_cache;
struct kvm_memory_slot memslots[KVM_MEM_SLOTS_NUM];
struct kvm_memory_slot *slots_sort[KVM_MEM_SLOTS_NUM];
};
@@ -643,15 +643,21 @@ static struct kvm_memory_slot *search_memslots(struct kvm_memslots *slots,
gfn_t gfn)
{
int start = 0, end = slots->used_slots, idx;
- struct kvm_memory_slot *memslot;
+ struct kvm_memory_slot *memslot = slots->slot_cache;
+
+ if (memslot && gfn >= memslot->base_gfn &&
+ gfn < memslot->base_gfn + memslot->npages)
+ return memslot;
while (start < end) {
idx = (start + end) / 2;
memslot = slots->slots_sort[idx];
if (gfn >= memslot->base_gfn &&
- gfn < memslot->base_gfn + memslot->npages)
+ gfn < memslot->base_gfn + memslot->npages) {
+ slots->slot_cache = memslot;
return memslot;
+ }
if (memslot->base_gfn < gfn)
start = idx + 1;
@@ -684,6 +690,7 @@ void memslots_updated(struct kvm_memslots *slots, int slot_id)
if (slot_id >= slots->nmemslots)
slots->nmemslots = slot_id + 1;
slots->generation++;
+ slots->slot_cache = NULL;
sort_memslots(slots);
}