diff options
author | Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com> | 2011-11-24 04:40:57 -0500 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2011-12-27 04:17:40 -0500 |
commit | bf3e05bc1e2781d5d8d3ddb2d8bf2d6ec207e5cb (patch) | |
tree | 7312367143f00ec1c051831f3a4e6dcc7f8acd92 /include/linux/kvm_host.h | |
parent | 28a37544fb0223eb9805d2567b88f7360edec52a (diff) |
KVM: sort memslots by its size and use line search
Sort memslots base on its size and use line search to find it, so that the
larger memslots have better fit
The idea is from Avi
Signed-off-by: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'include/linux/kvm_host.h')
-rw-r--r-- | include/linux/kvm_host.h | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 123925cd3ae8..9efdf5c703a5 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h | |||
@@ -231,8 +231,12 @@ struct kvm_irq_routing_table {}; | |||
231 | #define KVM_MEM_SLOTS_NUM (KVM_MEMORY_SLOTS + KVM_PRIVATE_MEM_SLOTS) | 231 | #define KVM_MEM_SLOTS_NUM (KVM_MEMORY_SLOTS + KVM_PRIVATE_MEM_SLOTS) |
232 | #endif | 232 | #endif |
233 | 233 | ||
234 | /* | ||
235 | * Note: | ||
236 | * memslots are not sorted by id anymore, please use id_to_memslot() | ||
237 | * to get the memslot by its id. | ||
238 | */ | ||
234 | struct kvm_memslots { | 239 | struct kvm_memslots { |
235 | int nmemslots; | ||
236 | u64 generation; | 240 | u64 generation; |
237 | struct kvm_memory_slot memslots[KVM_MEM_SLOTS_NUM]; | 241 | struct kvm_memory_slot memslots[KVM_MEM_SLOTS_NUM]; |
238 | }; | 242 | }; |
@@ -310,7 +314,8 @@ static inline struct kvm_vcpu *kvm_get_vcpu(struct kvm *kvm, int i) | |||
310 | 314 | ||
311 | #define kvm_for_each_memslot(memslot, slots) \ | 315 | #define kvm_for_each_memslot(memslot, slots) \ |
312 | for (memslot = &slots->memslots[0]; \ | 316 | for (memslot = &slots->memslots[0]; \ |
313 | memslot < slots->memslots + (slots)->nmemslots; memslot++) | 317 | memslot < slots->memslots + KVM_MEM_SLOTS_NUM && memslot->npages;\ |
318 | memslot++) | ||
314 | 319 | ||
315 | int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id); | 320 | int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id); |
316 | void kvm_vcpu_uninit(struct kvm_vcpu *vcpu); | 321 | void kvm_vcpu_uninit(struct kvm_vcpu *vcpu); |
@@ -336,7 +341,14 @@ static inline struct kvm_memslots *kvm_memslots(struct kvm *kvm) | |||
336 | static inline struct kvm_memory_slot * | 341 | static inline struct kvm_memory_slot * |
337 | id_to_memslot(struct kvm_memslots *slots, int id) | 342 | id_to_memslot(struct kvm_memslots *slots, int id) |
338 | { | 343 | { |
339 | return &slots->memslots[id]; | 344 | int i; |
345 | |||
346 | for (i = 0; i < KVM_MEM_SLOTS_NUM; i++) | ||
347 | if (slots->memslots[i].id == id) | ||
348 | return &slots->memslots[i]; | ||
349 | |||
350 | WARN_ON(1); | ||
351 | return NULL; | ||
340 | } | 352 | } |
341 | 353 | ||
342 | #define HPA_MSB ((sizeof(hpa_t) * 8) - 1) | 354 | #define HPA_MSB ((sizeof(hpa_t) * 8) - 1) |