From patchwork Fri May 4 21:23:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Baron X-Patchwork-Id: 156995 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 71034B70CD for ; Sat, 5 May 2012 07:24:08 +1000 (EST) Received: from localhost ([::1]:55831 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SQPyu-00076c-Tu for incoming@patchwork.ozlabs.org; Fri, 04 May 2012 17:24:04 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48331) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SQPyn-00076U-4p for qemu-devel@nongnu.org; Fri, 04 May 2012 17:23:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SQPyk-0001AM-Sf for qemu-devel@nongnu.org; Fri, 04 May 2012 17:23:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54016) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SQPyk-00018h-KR for qemu-devel@nongnu.org; Fri, 04 May 2012 17:23:54 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q44LNqX7024318 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 4 May 2012 17:23:52 -0400 Received: from redhat.com (dhcp-185-114.bos.redhat.com [10.16.185.114]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q44LNp9x029061; Fri, 4 May 2012 17:23:51 -0400 Date: Fri, 4 May 2012 17:23:51 -0400 From: Jason Baron Message-Id: <201205042123.q44LNp9x029061@int-mx01.intmail.prod.int.phx2.redhat.com> To: avi@redhat.com X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH] memory: add -dont-dump-guest option to reduce core dump size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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 #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); }