public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kvm tools: Scale guest RAM size by CPU count
@ 2011-05-07 14:22 Pekka Enberg
  0 siblings, 0 replies; only message in thread
From: Pekka Enberg @ 2011-05-07 14:22 UTC (permalink / raw)
  To: kvm
  Cc: Pekka Enberg, Asias He, Cyrill Gorcunov, Ingo Molnar,
	Prasad Joshi, Sasha Levin

This patch increases default RAM size to 256 for one CPU and introduces RAM
size linear scaling based on CPUs as suggested by Ingo Molnar:

     64MB*(nr_cpus + 3)

     ------------------
       1 CPUs:   256 MB
       2 CPUs:   320 MB
       3 CPUs:   384 MB
       4 CPUs:   448 MB
       5 CPUs:   512 MB
       6 CPUs:   576 MB
       7 CPUs:   640 MB
       8 CPUs:   704 MB
       9 CPUs:   768 MB
      10 CPUs:   832 MB
      11 CPUs:   896 MB
      12 CPUs:   960 MB
      13 CPUs:  1024 MB
      14 CPUs:  1088 MB
      15 CPUs:  1152 MB
      16 CPUs:  1216 MB

Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Prasad Joshi <prasadjoshi124@gmail.com>
Cc: Sasha Levin <levinsasha928@gmail.com>
Suggested-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
---
 tools/kvm/kvm-run.c |   26 +++++++++++++++++++++++++-
 1 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c
index 2ff126d..2504ab0 100644
--- a/tools/kvm/kvm-run.c
+++ b/tools/kvm/kvm-run.c
@@ -46,7 +46,7 @@ static struct kvm *kvm;
 static struct kvm_cpu *kvm_cpus[KVM_NR_CPUS];
 static __thread struct kvm_cpu *current_kvm_cpu;
 
-static u64 ram_size = MIN_RAM_SIZE_MB;
+static u64 ram_size;
 static u8  image_count;
 static const char *kernel_cmdline;
 static const char *kernel_filename;
@@ -213,6 +213,27 @@ static void kernel_usage_with_options(void)
 	fprintf(stderr, "\nPlease see 'kvm run --help' for more options.\n\n");
 }
 
+static u64 get_ram_size(int nr_cpus)
+{
+	long available;
+	long page_size;
+	long nr_pages;
+	long ram_size;
+
+	ram_size	= 64 * (nr_cpus + 3);
+
+	nr_pages	= sysconf(_SC_PHYS_PAGES);
+
+	page_size	= sysconf(_SC_PAGE_SIZE);
+
+	available	= (nr_pages * page_size) >> MB_SHIFT;
+
+	if (ram_size > available)
+		ram_size	= available;
+
+	return ram_size;
+}
+
 static const char *find_kernel(void)
 {
 	const char **k;
@@ -330,6 +351,9 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 	if (nrcpus < 1 || nrcpus > KVM_NR_CPUS)
 		die("Number of CPUs %d is out of [1;%d] range", nrcpus, KVM_NR_CPUS);
 
+	if (!ram_size)
+		ram_size	= get_ram_size(nrcpus);
+
 	if (ram_size < MIN_RAM_SIZE_MB)
 		die("Not enough memory specified: %lluMB (min %lluMB)", ram_size, MIN_RAM_SIZE_MB);
 
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2011-05-07 14:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-07 14:22 [PATCH] kvm tools: Scale guest RAM size by CPU count Pekka Enberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox