From: Pekka Enberg <penberg@kernel.org>
To: kvm@vger.kernel.org
Cc: Pekka Enberg <penberg@kernel.org>,
Asias He <asias.hejun@gmail.com>,
Cyrill Gorcunov <gorcunov@gmail.com>, Ingo Molnar <mingo@elte.hu>,
Prasad Joshi <prasadjoshi124@gmail.com>,
Sasha Levin <levinsasha928@gmail.com>
Subject: [PATCH] kvm tools: Scale guest RAM size by CPU count
Date: Sat, 7 May 2011 17:22:28 +0300 [thread overview]
Message-ID: <1304778148-6554-1-git-send-email-penberg@kernel.org> (raw)
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
reply other threads:[~2011-05-07 14:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1304778148-6554-1-git-send-email-penberg@kernel.org \
--to=penberg@kernel.org \
--cc=asias.hejun@gmail.com \
--cc=gorcunov@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=levinsasha928@gmail.com \
--cc=mingo@elte.hu \
--cc=prasadjoshi124@gmail.com \
/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