aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/kvm/kvm_main.c
diff options
context:
space:
mode:
authorZhang Xiantao <xiantao.zhang@intel.com>2007-11-20 00:11:38 -0500
committerAvi Kivity <avi@qumranet.com>2008-01-30 10:53:09 -0500
commit3ad82a7e874c5d6c4045090cc01d7794dd9eb21c (patch)
tree94aabdff667daa7de80b61dd7d0233af21a54fa4 /drivers/kvm/kvm_main.c
parent6226686954c4cce3d63ffe1777e60360fcbf0b83 (diff)
KVM: Recalculate mmu pages needed for every memory region change
Instead of incrementally changing the mmu cache size for every memory slot operation, recalculate it from scratch. This is simpler and safer. Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com> Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'drivers/kvm/kvm_main.c')
-rw-r--r--drivers/kvm/kvm_main.c21
1 files changed, 4 insertions, 17 deletions
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 729573b844e5..93ecafbfb1b6 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -333,26 +333,13 @@ int __kvm_set_memory_region(struct kvm *kvm,
333 if (mem->slot >= kvm->nmemslots) 333 if (mem->slot >= kvm->nmemslots)
334 kvm->nmemslots = mem->slot + 1; 334 kvm->nmemslots = mem->slot + 1;
335 335
336 *memslot = new;
337
336 if (!kvm->n_requested_mmu_pages) { 338 if (!kvm->n_requested_mmu_pages) {
337 unsigned int n_pages; 339 unsigned int nr_mmu_pages = kvm_mmu_calculate_mmu_pages(kvm);
338 340 kvm_mmu_change_mmu_pages(kvm, nr_mmu_pages);
339 if (npages) {
340 n_pages = npages * KVM_PERMILLE_MMU_PAGES / 1000;
341 kvm_mmu_change_mmu_pages(kvm, kvm->n_alloc_mmu_pages +
342 n_pages);
343 } else {
344 unsigned int nr_mmu_pages;
345
346 n_pages = old.npages * KVM_PERMILLE_MMU_PAGES / 1000;
347 nr_mmu_pages = kvm->n_alloc_mmu_pages - n_pages;
348 nr_mmu_pages = max(nr_mmu_pages,
349 (unsigned int) KVM_MIN_ALLOC_MMU_PAGES);
350 kvm_mmu_change_mmu_pages(kvm, nr_mmu_pages);
351 }
352 } 341 }
353 342
354 *memslot = new;
355
356 kvm_mmu_slot_remove_write_access(kvm, mem->slot); 343 kvm_mmu_slot_remove_write_access(kvm, mem->slot);
357 kvm_flush_remote_tlbs(kvm); 344 kvm_flush_remote_tlbs(kvm);
358 345