summaryrefslogtreecommitdiffstats
path: root/drivers/kvm/mmu.c
diff options
context:
space:
mode:
authorZhang Xiantao2007-11-20 06:11:38 +0100
committerAvi Kivity2008-01-30 16:53:09 +0100
commit3ad82a7e874c5d6c4045090cc01d7794dd9eb21c (patch)
tree94aabdff667daa7de80b61dd7d0233af21a54fa4 /drivers/kvm/mmu.c
parentKVM: x86 emulator: prefetch up to 15 bytes of the instruction executed (diff)
downloadkernel-qcow2-linux-3ad82a7e874c5d6c4045090cc01d7794dd9eb21c.tar.gz
kernel-qcow2-linux-3ad82a7e874c5d6c4045090cc01d7794dd9eb21c.tar.xz
kernel-qcow2-linux-3ad82a7e874c5d6c4045090cc01d7794dd9eb21c.zip
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/mmu.c')
-rw-r--r--drivers/kvm/mmu.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index 4624f3789b9a..101cd5377a89 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -1535,6 +1535,25 @@ nomem:
return -ENOMEM;
}
+/*
+ * Caculate mmu pages needed for kvm.
+ */
+unsigned int kvm_mmu_calculate_mmu_pages(struct kvm *kvm)
+{
+ int i;
+ unsigned int nr_mmu_pages;
+ unsigned int nr_pages = 0;
+
+ for (i = 0; i < kvm->nmemslots; i++)
+ nr_pages += kvm->memslots[i].npages;
+
+ nr_mmu_pages = nr_pages * KVM_PERMILLE_MMU_PAGES / 1000;
+ nr_mmu_pages = max(nr_mmu_pages,
+ (unsigned int) KVM_MIN_ALLOC_MMU_PAGES);
+
+ return nr_mmu_pages;
+}
+
#ifdef AUDIT
static const char *audit_msg;