* [Qemu-devel] [PATCH v5] add -machine mem-merge=on|off option
@ 2012-09-05 19:50 Luiz Capitulino
2012-09-17 18:25 ` Anthony Liguori
0 siblings, 1 reply; 2+ messages in thread
From: Luiz Capitulino @ 2012-09-05 19:50 UTC (permalink / raw)
To: aliguori; +Cc: qemu-devel
It allows to disable memory merge support (KSM on Linux), which is
enabled by default otherwise.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
v5
- rebase on top of current master
exec.c | 19 ++++++++++++++++---
qemu-config.c | 4 ++++
qemu-options.hx | 7 ++++++-
3 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/exec.c b/exec.c
index 5834766..c0fbd5b 100644
--- a/exec.c
+++ b/exec.c
@@ -2525,6 +2525,19 @@ void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev)
}
}
+static int memory_try_enable_merging(void *addr, size_t len)
+{
+ QemuOpts *opts;
+
+ opts = qemu_opts_find(qemu_find_opts("machine"), 0);
+ if (opts && !qemu_opt_get_bool(opts, "mem-merge", true)) {
+ /* disabled by the user */
+ return 0;
+ }
+
+ return qemu_madvise(addr, len, QEMU_MADV_MERGEABLE);
+}
+
ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
MemoryRegion *mr)
{
@@ -2544,7 +2557,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
new_block->host = file_ram_alloc(new_block, size, mem_path);
if (!new_block->host) {
new_block->host = qemu_vmalloc(size);
- qemu_madvise(new_block->host, size, QEMU_MADV_MERGEABLE);
+ memory_try_enable_merging(new_block->host, size);
}
#else
fprintf(stderr, "-mem-path option unsupported\n");
@@ -2559,7 +2572,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
} else {
new_block->host = qemu_vmalloc(size);
}
- qemu_madvise(new_block->host, size, QEMU_MADV_MERGEABLE);
+ memory_try_enable_merging(new_block->host, size);
}
}
new_block->length = size;
@@ -2689,7 +2702,7 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length)
length, addr);
exit(1);
}
- qemu_madvise(vaddr, length, QEMU_MADV_MERGEABLE);
+ memory_try_enable_merging(vaddr, length);
qemu_ram_setup_dump(vaddr, length);
}
return;
diff --git a/qemu-config.c b/qemu-config.c
index c05ffbc..75763d3 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -612,6 +612,10 @@ static QemuOptsList qemu_machine_opts = {
.name = "dump-guest-core",
.type = QEMU_OPT_BOOL,
.help = "Include guest memory in a core dump",
+ }, {
+ .name = "mem-merge",
+ .type = QEMU_OPT_BOOL,
+ .help = "enable/disable memory merge support",
},
{ /* End of list */ }
},
diff --git a/qemu-options.hx b/qemu-options.hx
index 3c411c4..90328d0 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -38,7 +38,8 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \
" supported accelerators are kvm, xen, tcg (default: tcg)\n"
" kernel_irqchip=on|off controls accelerated irqchip support\n"
" kvm_shadow_mem=size of KVM shadow MMU\n"
- " dump-guest-core=on|off include guest memory in a core dump (default=on)\n",
+ " dump-guest-core=on|off include guest memory in a core dump (default=on)\n"
+ " mem-merge=on|off controls memory merge support (default: on)\n",
QEMU_ARCH_ALL)
STEXI
@item -machine [type=]@var{name}[,prop=@var{value}[,...]]
@@ -57,6 +58,10 @@ Enables in-kernel irqchip support for the chosen accelerator when available.
Defines the size of the KVM shadow MMU.
@item dump-guest-core=on|off
Include guest memory in a core dump. The default is on.
+@item mem-merge=on|off
+Enables or disables memory merge support. This feature, when supported by
+the host, de-duplicates identical memory pages among VMs instances
+(enabled by default).
@end table
ETEXI
--
1.7.11.2.249.g31c7954.dirty
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH v5] add -machine mem-merge=on|off option
2012-09-05 19:50 [Qemu-devel] [PATCH v5] add -machine mem-merge=on|off option Luiz Capitulino
@ 2012-09-17 18:25 ` Anthony Liguori
0 siblings, 0 replies; 2+ messages in thread
From: Anthony Liguori @ 2012-09-17 18:25 UTC (permalink / raw)
To: Luiz Capitulino; +Cc: qemu-devel
Luiz Capitulino <lcapitulino@redhat.com> writes:
> It allows to disable memory merge support (KSM on Linux), which is
> enabled by default otherwise.
>
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Applied. Thanks.
Regards,
Anthony Liguori
> ---
>
> v5
>
> - rebase on top of current master
>
> exec.c | 19 ++++++++++++++++---
> qemu-config.c | 4 ++++
> qemu-options.hx | 7 ++++++-
> 3 files changed, 26 insertions(+), 4 deletions(-)
>
> diff --git a/exec.c b/exec.c
> index 5834766..c0fbd5b 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -2525,6 +2525,19 @@ void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev)
> }
> }
>
> +static int memory_try_enable_merging(void *addr, size_t len)
> +{
> + QemuOpts *opts;
> +
> + opts = qemu_opts_find(qemu_find_opts("machine"), 0);
> + if (opts && !qemu_opt_get_bool(opts, "mem-merge", true)) {
> + /* disabled by the user */
> + return 0;
> + }
> +
> + return qemu_madvise(addr, len, QEMU_MADV_MERGEABLE);
> +}
> +
> ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
> MemoryRegion *mr)
> {
> @@ -2544,7 +2557,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
> new_block->host = file_ram_alloc(new_block, size, mem_path);
> if (!new_block->host) {
> new_block->host = qemu_vmalloc(size);
> - qemu_madvise(new_block->host, size, QEMU_MADV_MERGEABLE);
> + memory_try_enable_merging(new_block->host, size);
> }
> #else
> fprintf(stderr, "-mem-path option unsupported\n");
> @@ -2559,7 +2572,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
> } else {
> new_block->host = qemu_vmalloc(size);
> }
> - qemu_madvise(new_block->host, size, QEMU_MADV_MERGEABLE);
> + memory_try_enable_merging(new_block->host, size);
> }
> }
> new_block->length = size;
> @@ -2689,7 +2702,7 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length)
> length, addr);
> exit(1);
> }
> - qemu_madvise(vaddr, length, QEMU_MADV_MERGEABLE);
> + memory_try_enable_merging(vaddr, length);
> qemu_ram_setup_dump(vaddr, length);
> }
> return;
> diff --git a/qemu-config.c b/qemu-config.c
> index c05ffbc..75763d3 100644
> --- a/qemu-config.c
> +++ b/qemu-config.c
> @@ -612,6 +612,10 @@ static QemuOptsList qemu_machine_opts = {
> .name = "dump-guest-core",
> .type = QEMU_OPT_BOOL,
> .help = "Include guest memory in a core dump",
> + }, {
> + .name = "mem-merge",
> + .type = QEMU_OPT_BOOL,
> + .help = "enable/disable memory merge support",
> },
> { /* End of list */ }
> },
> diff --git a/qemu-options.hx b/qemu-options.hx
> index 3c411c4..90328d0 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -38,7 +38,8 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \
> " supported accelerators are kvm, xen, tcg (default: tcg)\n"
> " kernel_irqchip=on|off controls accelerated irqchip support\n"
> " kvm_shadow_mem=size of KVM shadow MMU\n"
> - " dump-guest-core=on|off include guest memory in a core dump (default=on)\n",
> + " dump-guest-core=on|off include guest memory in a core dump (default=on)\n"
> + " mem-merge=on|off controls memory merge support (default: on)\n",
> QEMU_ARCH_ALL)
> STEXI
> @item -machine [type=]@var{name}[,prop=@var{value}[,...]]
> @@ -57,6 +58,10 @@ Enables in-kernel irqchip support for the chosen accelerator when available.
> Defines the size of the KVM shadow MMU.
> @item dump-guest-core=on|off
> Include guest memory in a core dump. The default is on.
> +@item mem-merge=on|off
> +Enables or disables memory merge support. This feature, when supported by
> +the host, de-duplicates identical memory pages among VMs instances
> +(enabled by default).
> @end table
> ETEXI
>
> --
> 1.7.11.2.249.g31c7954.dirty
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-09-17 18:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-05 19:50 [Qemu-devel] [PATCH v5] add -machine mem-merge=on|off option Luiz Capitulino
2012-09-17 18:25 ` Anthony Liguori
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).