]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Warn if guest RAM size exceeds host RAM size
authorPekka Enberg <penberg@kernel.org>
Sat, 7 May 2011 19:07:15 +0000 (22:07 +0300)
committerPekka Enberg <penberg@kernel.org>
Sat, 7 May 2011 19:07:15 +0000 (22:07 +0300)
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

index b9cdec27fd4b93cca689ca0455a5be4687725910..764a2427d330e4c4076803ac2d1fa8957c966fe6 100644 (file)
@@ -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)