From patchwork Mon Jun 25 16:55:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 167168 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 4D5311007D1 for ; Tue, 26 Jun 2012 02:55:35 +1000 (EST) Received: from localhost ([::1]:51378 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SjCZZ-00058c-0K for incoming@patchwork.ozlabs.org; Mon, 25 Jun 2012 12:55:33 -0400 Received: from eggs.gnu.org ([208.118.235.92]:41192) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SjCZI-00054Z-QX for qemu-devel@nongnu.org; Mon, 25 Jun 2012 12:55:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SjCZG-0003Zy-Lq for qemu-devel@nongnu.org; Mon, 25 Jun 2012 12:55:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:23719) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SjCZG-0003Zd-EZ for qemu-devel@nongnu.org; Mon, 25 Jun 2012 12:55:14 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q5PGtCe7003135 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 25 Jun 2012 12:55:13 -0400 Received: from localhost (ovpn-113-122.phx2.redhat.com [10.3.113.122]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q5PGtBTt021086; Mon, 25 Jun 2012 12:55:12 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Mon, 25 Jun 2012 13:55:32 -0300 Message-Id: <1340643332-5653-4-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1340643332-5653-1-git-send-email-lcapitulino@redhat.com> References: <1340643332-5653-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: aarcange@redhat.com, avi@redhat.com Subject: [Qemu-devel] [RFC 3/3] memory/qmp: add set-memory-merge command 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 Allow to enable/disable memory merging during run-time. This is implemented by extending the qemu_set_mem_merge() function. To test on HMP: (qemu) set_memory_merge on (qemu) set_memory_merge off Signed-off-by: Luiz Capitulino --- exec.c | 15 +++++++++++++++ hmp-commands.hx | 14 ++++++++++++++ hmp.c | 6 ++++++ hmp.h | 1 + monitor.c | 6 ++++++ osdep.h | 2 ++ qapi-schema.json | 18 ++++++++++++++++++ qmp-commands.hx | 5 +++++ 8 files changed, 67 insertions(+) diff --git a/exec.c b/exec.c index e29b27f..1fa82b4 100644 --- a/exec.c +++ b/exec.c @@ -2504,6 +2504,21 @@ void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev) void qemu_set_mem_merge(bool value) { + const RAMBlock *block; + + if (ram_list.merge_memory == value) { + /* do nothing */ + return; + } + + /* XXX: report errors? */ + QLIST_FOREACH(block, &ram_list.blocks, next) { + if (block->flags & RAM_MERGEABLE) { + qemu_madvise(block->host, block->length, + value ? QEMU_MADV_MERGEABLE : QEMU_MADV_UNMERGEABLE); + } + } + ram_list.merge_memory = value; } diff --git a/hmp-commands.hx b/hmp-commands.hx index f5d9d91..6ab3852 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -366,6 +366,20 @@ Wakeup guest from suspend. ETEXI { + .name = "set_memory_merge", + .args_type = "status:b", + .params = "status", + .help = "enable/disable memory merge support", + .mhandler.cmd = hmp_set_memory_merge, + }, + +STEXI +@item set_memory_merge +@findex set_memory_merge +Enable/disable memory merge support +ETEXI + + { .name = "gdbserver", .args_type = "device:s?", .params = "[device]", diff --git a/hmp.c b/hmp.c index b9cec1d..063cb3e 100644 --- a/hmp.c +++ b/hmp.c @@ -1000,3 +1000,9 @@ void hmp_netdev_del(Monitor *mon, const QDict *qdict) qmp_netdev_del(id, &err); hmp_handle_error(mon, &err); } + +void hmp_set_memory_merge(Monitor *mon, const QDict *qdict) +{ + bool enable = qdict_get_bool(qdict, "status"); + qmp_set_memory_merge(enable, NULL); +} diff --git a/hmp.h b/hmp.h index 79d138d..d884733 100644 --- a/hmp.h +++ b/hmp.h @@ -64,5 +64,6 @@ void hmp_device_del(Monitor *mon, const QDict *qdict); void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict); void hmp_netdev_add(Monitor *mon, const QDict *qdict); void hmp_netdev_del(Monitor *mon, const QDict *qdict); +void hmp_set_memory_merge(Monitor *mon, const QDict *qdict); #endif diff --git a/monitor.c b/monitor.c index f6107ba..c7f9015 100644 --- a/monitor.c +++ b/monitor.c @@ -4813,3 +4813,9 @@ int monitor_read_block_device_key(Monitor *mon, const char *device, return monitor_read_bdrv_key_start(mon, bs, completion_cb, opaque); } + +/* FIXME: move to qmp.c, although including memory.h doesn't work there */ +void qmp_set_memory_merge(bool enable, Error **errp) +{ + memory_global_set_merge(enable); +} diff --git a/osdep.h b/osdep.h index 3ea4af0..f5563c2 100644 --- a/osdep.h +++ b/osdep.h @@ -97,8 +97,10 @@ void qemu_vfree(void *ptr); #endif #ifdef MADV_MERGEABLE #define QEMU_MADV_MERGEABLE MADV_MERGEABLE +#define QEMU_MADV_UNMERGEABLE MADV_UNMERGEABLE #else #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID +#define QEMU_MADV_UNMERGEABLE QEMU_MADV_INVALID #endif #elif defined(CONFIG_POSIX_MADVISE) diff --git a/qapi-schema.json b/qapi-schema.json index 3b6e346..0b99bc0 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1862,3 +1862,21 @@ # Since: 0.14.0 ## { 'command': 'netdev_del', 'data': {'id': 'str'} } + +## +# @set-memory-merge: +# +# Enable or disable memory merge support. On Linux systems, this enables +# or disables KSM support. +# +# @enable: true (enables memory merging) or false (disables memory merging) +# +# Returns: Nothing on success +# +# Note: this command never fails. The only possible reason for a failure +# is when the host doesn't support memory merging, but that's not reported +# by this command, it will just return success. +# +# Since: 1.2.0 +## +{ 'command': 'set-memory-merge', 'data': { 'enable': 'bool' } } diff --git a/qmp-commands.hx b/qmp-commands.hx index 2e1a38e..74530b9 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -2209,3 +2209,8 @@ EQMP .args_type = "implements:s?,abstract:b?", .mhandler.cmd_new = qmp_marshal_input_qom_list_types, }, + { + .name = "set-memory-merge", + .args_type = "enable:b", + .mhandler.cmd_new = qmp_marshal_input_set_memory_merge, + },