qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] memory: add -dont-dump-guest option to reduce core


From: Jason Baron
Subject: [Qemu-devel] [PATCH] memory: add -dont-dump-guest option to reduce core dump size
Date: Fri, 4 May 2012 17:23:51 -0400

Add a command line parameter to not dump guest memory in the core dump, the
command line is: -dont-dump-guest. This brought the core dump down from
383MB to 13 MB on a 1GB guest.

Signed-off-by: Jason Baron <address@hidden>
---
 exec.c          |   13 +++++++++++++
 osdep.h         |    7 +++++++
 qemu-options.hx |    5 +++++
 sysemu.h        |    1 +
 vl.c            |    4 ++++
 5 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/exec.c b/exec.c
index 0607c9b..f9d2b93 100644
--- a/exec.c
+++ b/exec.c
@@ -35,6 +35,7 @@
 #include "qemu-timer.h"
 #include "memory.h"
 #include "exec-memory.h"
+#include "sysemu.h"
 #if defined(CONFIG_USER_ONLY)
 #include <qemu.h>
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
@@ -2605,6 +2606,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void 
*host,
                                    MemoryRegion *mr)
 {
     RAMBlock *new_block;
+    int ret;
 
     size = TARGET_PAGE_ALIGN(size);
     new_block = g_malloc0(sizeof(*new_block));
@@ -2659,6 +2661,17 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void 
*host,
     memset(ram_list.phys_dirty + (new_block->offset >> TARGET_PAGE_BITS),
            0xff, size >> TARGET_PAGE_BITS);
 
+
+    /* Use MADV_DONTDUMP, if user doesn't want the guest memory in the core */
+    if (dont_dump_guest) {
+        ret = qemu_madvise(new_block->host, size, QEMU_MADV_DONTDUMP);
+        if (ret) {
+            perror("qemu_madvise");
+            fprintf(stderr, "madvise doesn't support MADV_DONTDUMP, "
+                            "but -dont-dump-guest-core specified\n");
+        }
+    }
+
     if (kvm_enabled())
         kvm_setup_guest_memory(new_block->host, size);
 
diff --git a/osdep.h b/osdep.h
index 9db8766..db275f2 100644
--- a/osdep.h
+++ b/osdep.h
@@ -100,6 +100,11 @@ void qemu_vfree(void *ptr);
 #else
 #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
 #endif
+#ifdef MADV_DONTDUMP
+#define QEMU_MADV_DONTDUMP MADV_DONTDUMP
+#else
+#define QEMU_MADV_DONTDUMP QEMU_MADV_INVALID
+#endif
 
 #elif defined(CONFIG_POSIX_MADVISE)
 
@@ -107,6 +112,7 @@ void qemu_vfree(void *ptr);
 #define QEMU_MADV_DONTNEED  POSIX_MADV_DONTNEED
 #define QEMU_MADV_DONTFORK  QEMU_MADV_INVALID
 #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
+#define QEMU_MADV_DONTDUMP QEMU_MADV_INVALID
 
 #else /* no-op */
 
@@ -114,6 +120,7 @@ void qemu_vfree(void *ptr);
 #define QEMU_MADV_DONTNEED  QEMU_MADV_INVALID
 #define QEMU_MADV_DONTFORK  QEMU_MADV_INVALID
 #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
+#define QEMU_MADV_DONTDUMP QEMU_MADV_INVALID
 
 #endif
 
diff --git a/qemu-options.hx b/qemu-options.hx
index a169792..ae12cc6 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2724,6 +2724,11 @@ DEF("qtest-log", HAS_ARG, QEMU_OPTION_qtest_log,
     "-qtest-log LOG  specify tracing options\n",
     QEMU_ARCH_ALL)
 
+DEF("dont-dump-guest", 0, QEMU_OPTION_dont_dump_guest,
+    "-dont-dump-guest\n"
+    "                do not dump guest core\n",
+    QEMU_ARCH_ALL)
+
 HXCOMM This is the last statement. Insert new options before this line!
 STEXI
 @end table
diff --git a/sysemu.h b/sysemu.h
index bc2c788..f738f34 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -131,6 +131,7 @@ extern uint8_t *boot_splash_filedata;
 extern int boot_splash_filedata_size;
 extern uint8_t qemu_extra_params_fw[2];
 extern QEMUClock *rtc_clock;
+extern int dont_dump_guest;
 
 #define MAX_NODES 64
 extern int nb_numa_nodes;
diff --git a/vl.c b/vl.c
index ae91a8a..6259c21 100644
--- a/vl.c
+++ b/vl.c
@@ -232,6 +232,7 @@ int boot_menu;
 uint8_t *boot_splash_filedata;
 int boot_splash_filedata_size;
 uint8_t qemu_extra_params_fw[2];
+int dont_dump_guest;
 
 typedef struct FWBootEntry FWBootEntry;
 
@@ -3191,6 +3192,9 @@ int main(int argc, char **argv, char **envp)
             case QEMU_OPTION_qtest_log:
                 qtest_log = optarg;
                 break;
+            case QEMU_OPTION_dont_dump_guest:
+                dont_dump_guest = 1;
+                break;
             default:
                 os_parse_cmd_args(popt->index, optarg);
             }
-- 
1.7.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]