public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Rusty Russell <rusty-8n+1lVoiYb80n/F98K4Iww@public.gmane.org>
To: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
Cc: kvm-devel <kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Subject: [PATCH 1/2] Use kmem cache for allocating vcpus
Date: Mon, 30 Jul 2007 21:12:19 +1000	[thread overview]
Message-ID: <1185793939.6131.38.camel@localhost.localdomain> (raw)
In-Reply-To: <46ADBCBC.9050207-atKUWr5tajBWk0Htik3J/w@public.gmane.org>

Avi wants the allocations of vcpus centralized again.  The easiest way
is to add a "size" arg to kvm_init_arch, and expose the thus-prepared
cache to the modules.

Signed-off-by: Rusty Russell <rusty-8n+1lVoiYb80n/F98K4Iww@public.gmane.org>

diff -r 650abbc45974 drivers/kvm/kvm.h
--- a/drivers/kvm/kvm.h	Mon Jul 30 20:49:49 2007 +1000
+++ b/drivers/kvm/kvm.h	Mon Jul 30 21:01:41 2007 +1000
@@ -140,6 +140,7 @@ struct kvm_mmu_page {
 };
 
 struct kvm_vcpu;
+extern struct kmem_cache *kvm_vcpu_cache;
 
 /*
  * x86 supports 3 paging modes (4-level 64-bit, 3-level 64-bit, and 2-level
@@ -481,7 +482,8 @@ int kvm_vcpu_init(struct kvm_vcpu *vcpu,
 int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id);
 void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
 
-int kvm_init_arch(struct kvm_arch_ops *ops, struct module *module);
+int kvm_init_arch(struct kvm_arch_ops *ops, unsigned int vcpu_size,
+		  struct module *module);
 void kvm_exit_arch(void);
 
 int kvm_mmu_module_init(void);
diff -r 650abbc45974 drivers/kvm/kvm_main.c
--- a/drivers/kvm/kvm_main.c	Mon Jul 30 20:49:49 2007 +1000
+++ b/drivers/kvm/kvm_main.c	Mon Jul 30 21:05:13 2007 +1000
@@ -53,6 +53,8 @@ static cpumask_t cpus_hardware_enabled;
 static cpumask_t cpus_hardware_enabled;
 
 struct kvm_arch_ops *kvm_arch_ops;
+struct kmem_cache *kvm_vcpu_cache;
+EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
 
 #define STAT_OFFSET(x) offsetof(struct kvm_vcpu, stat.x)
 
@@ -3142,7 +3144,8 @@ static struct sys_device kvm_sysdev = {
 
 hpa_t bad_page_address;
 
-int kvm_init_arch(struct kvm_arch_ops *ops, struct module *module)
+int kvm_init_arch(struct kvm_arch_ops *ops, unsigned int vcpu_size,
+		  struct module *module)
 {
 	int r;
 
@@ -3180,6 +3183,14 @@ int kvm_init_arch(struct kvm_arch_ops *o
 	if (r)
 		goto out_free_3;
 
+	/* A kmem cache lets us meet the alignment requirements of fx_save. */
+	kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size,
+					   __alignof__(struct kvm_vcpu), 0, 0);
+	if (!kvm_vcpu_cache) {
+		r = -ENOMEM;
+		goto out_free_4;
+	}
+
 	kvm_chardev_ops.owner = module;
 
 	r = misc_register(&kvm_dev);
@@ -3191,6 +3202,8 @@ int kvm_init_arch(struct kvm_arch_ops *o
 	return r;
 
 out_free:
+	kmem_cache_destroy(kvm_vcpu_cache);
+out_free_4:
 	sysdev_unregister(&kvm_sysdev);
 out_free_3:
 	sysdev_class_unregister(&kvm_sysdev_class);
@@ -3208,6 +3221,7 @@ void kvm_exit_arch(void)
 void kvm_exit_arch(void)
 {
 	misc_deregister(&kvm_dev);
+	kmem_cache_destroy(kvm_vcpu_cache);
 	sysdev_unregister(&kvm_sysdev);
 	sysdev_class_unregister(&kvm_sysdev_class);
 	unregister_reboot_notifier(&kvm_reboot_notifier);
diff -r 650abbc45974 drivers/kvm/svm.c
--- a/drivers/kvm/svm.c	Mon Jul 30 20:49:49 2007 +1000
+++ b/drivers/kvm/svm.c	Mon Jul 30 21:00:05 2007 +1000
@@ -559,7 +559,7 @@ static struct kvm_vcpu *svm_create_vcpu(
 	struct page *page;
 	int err;
 
-	svm = kzalloc(sizeof *svm, GFP_KERNEL);
+	svm = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL);
 	if (!svm) {
 		err = -ENOMEM;
 		goto out;
@@ -1832,7 +1832,8 @@ static struct kvm_arch_ops svm_arch_ops 
 
 static int __init svm_init(void)
 {
-	return kvm_init_arch(&svm_arch_ops, THIS_MODULE);
+	return kvm_init_arch(&svm_arch_ops, sizeof(struct vcpu_svm),
+			      THIS_MODULE);
 }
 
 static void __exit svm_exit(void)
diff -r 650abbc45974 drivers/kvm/vmx.c
--- a/drivers/kvm/vmx.c	Mon Jul 30 20:49:49 2007 +1000
+++ b/drivers/kvm/vmx.c	Mon Jul 30 21:08:52 2007 +1000
@@ -2295,7 +2295,7 @@ static struct kvm_vcpu *vmx_create_vcpu(
 static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
 {
 	int err;
-	struct vcpu_vmx *vmx = kzalloc(sizeof(*vmx), GFP_KERNEL);
+	struct vcpu_vmx *vmx = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL);
 
 	if (!vmx)
 		return ERR_PTR(-ENOMEM);
@@ -2417,7 +2417,7 @@ static int __init vmx_init(void)
 	memset(iova, 0xff, PAGE_SIZE);
 	kunmap(vmx_io_bitmap_b);
 
-	r = kvm_init_arch(&vmx_arch_ops, THIS_MODULE);
+	r = kvm_init_arch(&vmx_arch_ops, sizeof(struct vcpu_vmx), THIS_MODULE);
 	if (r)
 		goto out1;
 



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/

  parent reply	other threads:[~2007-07-30 11:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-30  6:31 [PATCH 1/4] vmx: pass vcpu_vmx internally Rusty Russell
     [not found] ` <1185777103.12151.147.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-07-30  6:32   ` [PATCH 2/4] svm: pass vcpu_svm internally Rusty Russell
     [not found]     ` <1185777179.12151.149.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-07-30  6:36       ` [PATCH 3/4] House svm.c's pop_irq and push_irq helpers into generic header Rusty Russell
     [not found]         ` <1185777368.12151.152.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-07-30  6:39           ` [PATCH 4/4] Use kmem cache for allocating vcpus, simplify FPU ops Rusty Russell
     [not found]             ` <1185777542.12151.156.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-07-30  9:12               ` Avi Kivity
     [not found]                 ` <46ADAB67.5070805-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-07-30 10:04                   ` Rusty Russell
     [not found]                     ` <1185789882.6131.30.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-07-30 10:26                       ` Avi Kivity
     [not found]                         ` <46ADBCBC.9050207-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-07-30 11:12                           ` Rusty Russell [this message]
     [not found]                             ` <1185793939.6131.38.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-07-30 11:13                               ` [PATCH 2/2] Use alignment properties of vcpu to " Rusty Russell
     [not found]                                 ` <1185794023.6131.41.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-07-30 13:09                                   ` Avi Kivity
2007-07-30  6:39           ` [PATCH 3/4] House svm.c's pop_irq and push_irq helpers into generic header Rusty Russell
2007-07-30  9:03       ` [PATCH 2/4] svm: pass vcpu_svm internally Avi Kivity
     [not found]         ` <46ADA971.9030406-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-07-30 10:07           ` [PATCH 1/2] svm de-containization Rusty Russell
     [not found]             ` <1185790028.6131.32.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-07-30 10:08               ` [PATCH 2/2] svm internal function name cleanup Rusty Russell
2007-07-30 10:22               ` [PATCH 1/2] svm de-containization Avi Kivity
2007-07-30  9:02   ` [PATCH 1/4] vmx: pass vcpu_vmx internally 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=1185793939.6131.38.camel@localhost.localdomain \
    --to=rusty-8n+1lvoiyb80n/f98k4iww@public.gmane.org \
    --cc=avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.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