diff options
author | Zhang Xiantao <xiantao.zhang@intel.com> | 2007-11-20 00:11:38 -0500 |
---|---|---|
committer | Avi Kivity <avi@qumranet.com> | 2008-01-30 10:53:09 -0500 |
commit | 3ad82a7e874c5d6c4045090cc01d7794dd9eb21c (patch) | |
tree | 94aabdff667daa7de80b61dd7d0233af21a54fa4 /drivers/kvm/mmu.c | |
parent | 6226686954c4cce3d63ffe1777e60360fcbf0b83 (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/mmu.c')
-rw-r--r-- | drivers/kvm/mmu.c | 19 |
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: | |||
1535 | return -ENOMEM; | 1535 | return -ENOMEM; |
1536 | } | 1536 | } |
1537 | 1537 | ||
1538 | /* | ||
1539 | * Caculate mmu pages needed for kvm. | ||
1540 | */ | ||
1541 | unsigned int kvm_mmu_calculate_mmu_pages(struct kvm *kvm) | ||
1542 | { | ||
1543 | int i; | ||
1544 | unsigned int nr_mmu_pages; | ||
1545 | unsigned int nr_pages = 0; | ||
1546 | |||
1547 | for (i = 0; i < kvm->nmemslots; i++) | ||
1548 | nr_pages += kvm->memslots[i].npages; | ||
1549 | |||
1550 | nr_mmu_pages = nr_pages * KVM_PERMILLE_MMU_PAGES / 1000; | ||
1551 | nr_mmu_pages = max(nr_mmu_pages, | ||
1552 | (unsigned int) KVM_MIN_ALLOC_MMU_PAGES); | ||
1553 | |||
1554 | return nr_mmu_pages; | ||
1555 | } | ||
1556 | |||
1538 | #ifdef AUDIT | 1557 | #ifdef AUDIT |
1539 | 1558 | ||
1540 | static const char *audit_msg; | 1559 | static const char *audit_msg; |