From: Avi Kivity <avi@qumranet.com>
To: kvm-devel@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org, Avi Kivity <avi@qumranet.com>
Subject: [PATCH 05/18] KVM: Use slab caches to allocate mmu data structures
Date: Thu, 26 Apr 2007 12:22:05 +0300 [thread overview]
Message-ID: <11775793381079-git-send-email-avi@qumranet.com> (raw)
In-Reply-To: <11775793382353-git-send-email-avi@qumranet.com>
Better leak detection, statistics, memory use, speed -- goodness all
around.
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
drivers/kvm/kvm.h | 3 +++
drivers/kvm/kvm_main.c | 7 +++++++
drivers/kvm/mmu.c | 39 +++++++++++++++++++++++++++++++++++----
3 files changed, 45 insertions(+), 4 deletions(-)
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index fceeb84..b9c318a 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -433,6 +433,9 @@ extern struct kvm_arch_ops *kvm_arch_ops;
int kvm_init_arch(struct kvm_arch_ops *ops, struct module *module);
void kvm_exit_arch(void);
+int kvm_mmu_module_init(void);
+void kvm_mmu_module_exit(void);
+
void kvm_mmu_destroy(struct kvm_vcpu *vcpu);
int kvm_mmu_create(struct kvm_vcpu *vcpu);
int kvm_mmu_setup(struct kvm_vcpu *vcpu);
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 0b30631..ab4dbd7 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -3063,6 +3063,10 @@ static __init int kvm_init(void)
static struct page *bad_page;
int r;
+ r = kvm_mmu_module_init();
+ if (r)
+ goto out4;
+
r = register_filesystem(&kvm_fs_type);
if (r)
goto out3;
@@ -3091,6 +3095,8 @@ out:
out2:
unregister_filesystem(&kvm_fs_type);
out3:
+ kvm_mmu_module_exit();
+out4:
return r;
}
@@ -3100,6 +3106,7 @@ static __exit void kvm_exit(void)
__free_page(pfn_to_page(bad_page_address >> PAGE_SHIFT));
mntput(kvmfs_mnt);
unregister_filesystem(&kvm_fs_type);
+ kvm_mmu_module_exit();
}
module_init(kvm_init)
diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index 9ff7480..a368ea8 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -159,6 +159,9 @@ struct kvm_rmap_desc {
struct kvm_rmap_desc *more;
};
+static struct kmem_cache *pte_chain_cache;
+static struct kmem_cache *rmap_desc_cache;
+
static int is_write_protection(struct kvm_vcpu *vcpu)
{
return vcpu->cr0 & CR0_WP_MASK;
@@ -196,14 +199,14 @@ static int is_rmap_pte(u64 pte)
}
static int mmu_topup_memory_cache(struct kvm_mmu_memory_cache *cache,
- size_t objsize, int min)
+ struct kmem_cache *base_cache, int min)
{
void *obj;
if (cache->nobjs >= min)
return 0;
while (cache->nobjs < ARRAY_SIZE(cache->objects)) {
- obj = kzalloc(objsize, GFP_NOWAIT);
+ obj = kmem_cache_zalloc(base_cache, GFP_NOWAIT);
if (!obj)
return -ENOMEM;
cache->objects[cache->nobjs++] = obj;
@@ -222,11 +225,11 @@ static int mmu_topup_memory_caches(struct kvm_vcpu *vcpu)
int r;
r = mmu_topup_memory_cache(&vcpu->mmu_pte_chain_cache,
- sizeof(struct kvm_pte_chain), 4);
+ pte_chain_cache, 4);
if (r)
goto out;
r = mmu_topup_memory_cache(&vcpu->mmu_rmap_desc_cache,
- sizeof(struct kvm_rmap_desc), 1);
+ rmap_desc_cache, 1);
out:
return r;
}
@@ -1333,6 +1336,34 @@ void kvm_mmu_zap_all(struct kvm_vcpu *vcpu)
init_kvm_mmu(vcpu);
}
+void kvm_mmu_module_exit(void)
+{
+ if (pte_chain_cache)
+ kmem_cache_destroy(pte_chain_cache);
+ if (rmap_desc_cache)
+ kmem_cache_destroy(rmap_desc_cache);
+}
+
+int kvm_mmu_module_init(void)
+{
+ pte_chain_cache = kmem_cache_create("kvm_pte_chain",
+ sizeof(struct kvm_pte_chain),
+ 0, 0, NULL, NULL);
+ if (!pte_chain_cache)
+ goto nomem;
+ rmap_desc_cache = kmem_cache_create("kvm_rmap_desc",
+ sizeof(struct kvm_rmap_desc),
+ 0, 0, NULL, NULL);
+ if (!rmap_desc_cache)
+ goto nomem;
+
+ return 0;
+
+nomem:
+ kvm_mmu_module_exit();
+ return -ENOMEM;
+}
+
#ifdef AUDIT
static const char *audit_msg;
--
1.5.0.6
next prev parent reply other threads:[~2007-04-26 9:27 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-26 9:22 [PATCH 00/18] KVM updates for 2.6.22 Avi Kivity
2007-04-26 9:22 ` [PATCH 01/18] KVM: Use kernel-standard types Avi Kivity
2007-04-26 9:22 ` [PATCH 02/18] KVM: Fix overflow bug in overflow detection code Avi Kivity
2007-04-26 9:22 ` [PATCH 03/18] KVM: Initialize cr0 to indicate an fpu is present Avi Kivity
2007-04-26 9:22 ` [PATCH 04/18] KVM: Handle partial pae pdptr Avi Kivity
2007-04-26 9:22 ` Avi Kivity [this message]
2007-04-26 9:22 ` [PATCH 06/18] KVM: Retry sleeping allocation if atomic allocation fails Avi Kivity
2007-04-26 9:22 ` [PATCH 07/18] KVM: SVM: Report hardware exit reason to userspace instead of dmesg Avi Kivity
2007-04-26 9:22 ` [PATCH 08/18] KVM: Handle guest page faults when emulating mmio Avi Kivity
2007-04-26 9:22 ` [PATCH 09/18] KVM: VMX: Reduce unnecessary saving of host msrs Avi Kivity
2007-04-26 9:22 ` [PATCH 10/18] KVM: VMX: Don't switch 64-bit msrs for 32-bit guests Avi Kivity
2007-04-26 9:22 ` [PATCH 11/18] KVM: Fold drivers/kvm/kvm_vmx.h into drivers/kvm/vmx.c Avi Kivity
2007-04-26 9:22 ` [PATCH 12/18] KVM: VMX: Only save/restore MSR_K6_STAR if necessary Avi Kivity
2007-04-26 9:22 ` [PATCH 13/18] KVM: MMU: Avoid heavy ASSERT at non debug mode Avi Kivity
2007-04-26 9:22 ` [PATCH 14/18] KVM: VMX: Avoid unnecessary vcpu_load()/vcpu_put() cycles Avi Kivity
2007-04-26 9:22 ` [PATCH 15/18] KVM: Per-vcpu statistics Avi Kivity
2007-04-26 9:22 ` [PATCH 16/18] KVM: Allow passing 64-bit values to the emulated read/write API Avi Kivity
2007-04-26 9:22 ` [PATCH 17/18] KVM: Lazy FPU support for SVM Avi Kivity
2007-04-26 9:22 ` [PATCH 18/18] KVM: Don't complain about cpu erratum AA15 Avi Kivity
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=11775793381079-git-send-email-avi@qumranet.com \
--to=avi@qumranet.com \
--cc=kvm-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox