* [PATCH 1/2] kvm tools: Don't use all of host RAM for guests by default
@ 2011-05-07 19:09 Pekka Enberg
2011-05-07 19:09 ` [PATCH 2/2] kvm tools: Warn if guest RAM size exceeds host RAM size Pekka Enberg
0 siblings, 1 reply; 2+ messages in thread
From: Pekka Enberg @ 2011-05-07 19:09 UTC (permalink / raw)
To: kvm
Cc: Pekka Enberg, Asias He, Cyrill Gorcunov, Ingo Molnar,
Prasad Joshi, Sasha Levin
This patch fixes the default guest RAM size maximum to 80% of the host RAM to
avoid swapping the host to death.
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 | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c
index ec1e462..b9cdec2 100644
--- a/tools/kvm/kvm-run.c
+++ b/tools/kvm/kvm-run.c
@@ -213,6 +213,12 @@ static void kernel_usage_with_options(void)
fprintf(stderr, "\nPlease see 'kvm run --help' for more options.\n\n");
}
+/*
+ * If user didn't specify how much memory it wants to allocate for the guest,
+ * avoid filling the whole host RAM.
+ */
+#define RAM_SIZE_RATIO 0.8
+
static u64 get_ram_size(int nr_cpus)
{
long available;
@@ -226,7 +232,7 @@ static u64 get_ram_size(int nr_cpus)
page_size = sysconf(_SC_PAGE_SIZE);
- available = (nr_pages * page_size) >> MB_SHIFT;
+ available = ((nr_pages * page_size) >> MB_SHIFT) * RAM_SIZE_RATIO;
if (ram_size > available)
ram_size = available;
--
1.7.0.4
^ permalink raw reply related [flat|nested] 2+ messages in thread* [PATCH 2/2] kvm tools: Warn if guest RAM size exceeds host RAM size
2011-05-07 19:09 [PATCH 1/2] kvm tools: Don't use all of host RAM for guests by default Pekka Enberg
@ 2011-05-07 19:09 ` Pekka Enberg
0 siblings, 0 replies; 2+ messages in thread
From: Pekka Enberg @ 2011-05-07 19:09 UTC (permalink / raw)
To: kvm
Cc: Pekka Enberg, Asias He, Cyrill Gorcunov, Ingo Molnar,
Prasad Joshi, Sasha Levin
Guest memory size that's larger than host physical RAM can cause swap deaths on
the host so warn the user about it.
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 | 23 ++++++++++++++++-------
1 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c
index b9cdec2..764a242 100644
--- a/tools/kvm/kvm-run.c
+++ b/tools/kvm/kvm-run.c
@@ -213,6 +213,18 @@ static void kernel_usage_with_options(void)
fprintf(stderr, "\nPlease see 'kvm run --help' for more options.\n\n");
}
+static u64 host_ram_size(void)
+{
+ long page_size;
+ long nr_pages;
+
+ nr_pages = sysconf(_SC_PHYS_PAGES);
+
+ page_size = sysconf(_SC_PAGE_SIZE);
+
+ return (nr_pages * page_size) >> MB_SHIFT;
+}
+
/*
* If user didn't specify how much memory it wants to allocate for the guest,
* avoid filling the whole host RAM.
@@ -222,17 +234,11 @@ static void kernel_usage_with_options(void)
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) * RAM_SIZE_RATIO;
+ available = host_ram_size() * RAM_SIZE_RATIO;
if (ram_size > available)
ram_size = available;
@@ -364,6 +370,9 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
if (ram_size < MIN_RAM_SIZE_MB)
die("Not enough memory specified: %lluMB (min %lluMB)", ram_size, MIN_RAM_SIZE_MB);
+ if (ram_size > host_ram_size())
+ warning("Guest memory size %lluMB exceeds host physical RAM size %lluMB", ram_size, host_ram_size());
+
ram_size <<= MB_SHIFT;
if (!kvm_dev)
--
1.7.0.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-05-07 19:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-07 19:09 [PATCH 1/2] kvm tools: Don't use all of host RAM for guests by default Pekka Enberg
2011-05-07 19:09 ` [PATCH 2/2] kvm tools: Warn if guest RAM size exceeds host RAM size Pekka Enberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).