[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 084/103] hostmem: add merge and dump properties
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 084/103] hostmem: add merge and dump properties |
Date: |
Tue, 17 Jun 2014 20:41:25 +0300 |
From: Paolo Bonzini <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
Signed-off-by: Hu Tao <address@hidden>
Acked-by: Michael S. Tsirkin <address@hidden>
---
include/qemu/osdep.h | 10 ++++++
include/sysemu/hostmem.h | 1 +
backends/hostmem.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 94 insertions(+), 1 deletion(-)
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 9c1a119..820c5d0 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -116,6 +116,16 @@ void qemu_anon_ram_free(void *ptr, size_t size);
#else
#define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
#endif
+#ifdef MADV_UNMERGEABLE
+#define QEMU_MADV_UNMERGEABLE MADV_UNMERGEABLE
+#else
+#define QEMU_MADV_UNMERGEABLE QEMU_MADV_INVALID
+#endif
+#ifdef MADV_DODUMP
+#define QEMU_MADV_DODUMP MADV_DODUMP
+#else
+#define QEMU_MADV_DODUMP QEMU_MADV_INVALID
+#endif
#ifdef MADV_DONTDUMP
#define QEMU_MADV_DONTDUMP MADV_DONTDUMP
#else
diff --git a/include/sysemu/hostmem.h b/include/sysemu/hostmem.h
index 923f672..ede5ec9 100644
--- a/include/sysemu/hostmem.h
+++ b/include/sysemu/hostmem.h
@@ -52,6 +52,7 @@ struct HostMemoryBackend {
/* protected */
uint64_t size;
+ bool merge, dump;
MemoryRegion mr;
};
diff --git a/backends/hostmem.c b/backends/hostmem.c
index 1738774..a2550fe 100644
--- a/backends/hostmem.c
+++ b/backends/hostmem.c
@@ -53,8 +53,73 @@ out:
error_propagate(errp, local_err);
}
+static bool host_memory_backend_get_merge(Object *obj, Error **errp)
+{
+ HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+
+ return backend->merge;
+}
+
+static void host_memory_backend_set_merge(Object *obj, bool value, Error
**errp)
+{
+ HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+
+ if (!memory_region_size(&backend->mr)) {
+ backend->merge = value;
+ return;
+ }
+
+ if (value != backend->merge) {
+ void *ptr = memory_region_get_ram_ptr(&backend->mr);
+ uint64_t sz = memory_region_size(&backend->mr);
+
+ qemu_madvise(ptr, sz,
+ value ? QEMU_MADV_MERGEABLE : QEMU_MADV_UNMERGEABLE);
+ backend->merge = value;
+ }
+}
+
+static bool host_memory_backend_get_dump(Object *obj, Error **errp)
+{
+ HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+
+ return backend->dump;
+}
+
+static void host_memory_backend_set_dump(Object *obj, bool value, Error **errp)
+{
+ HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+
+ if (!memory_region_size(&backend->mr)) {
+ backend->dump = value;
+ return;
+ }
+
+ if (value != backend->dump) {
+ void *ptr = memory_region_get_ram_ptr(&backend->mr);
+ uint64_t sz = memory_region_size(&backend->mr);
+
+ qemu_madvise(ptr, sz,
+ value ? QEMU_MADV_DODUMP : QEMU_MADV_DONTDUMP);
+ backend->dump = value;
+ }
+}
+
static void host_memory_backend_init(Object *obj)
{
+ HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+
+ backend->merge = qemu_opt_get_bool(qemu_get_machine_opts(),
+ "mem-merge", true);
+ backend->dump = qemu_opt_get_bool(qemu_get_machine_opts(),
+ "dump-guest-core", true);
+
+ object_property_add_bool(obj, "merge",
+ host_memory_backend_get_merge,
+ host_memory_backend_set_merge, NULL);
+ object_property_add_bool(obj, "dump",
+ host_memory_backend_get_dump,
+ host_memory_backend_set_dump, NULL);
object_property_add(obj, "size", "int",
host_memory_backend_get_size,
host_memory_backend_set_size, NULL, NULL, NULL);
@@ -80,9 +145,26 @@ host_memory_backend_memory_complete(UserCreatable *uc,
Error **errp)
{
HostMemoryBackend *backend = MEMORY_BACKEND(uc);
HostMemoryBackendClass *bc = MEMORY_BACKEND_GET_CLASS(uc);
+ Error *local_err = NULL;
+ void *ptr;
+ uint64_t sz;
if (bc->alloc) {
- bc->alloc(backend, errp);
+ bc->alloc(backend, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+
+ ptr = memory_region_get_ram_ptr(&backend->mr);
+ sz = memory_region_size(&backend->mr);
+
+ if (backend->merge) {
+ qemu_madvise(ptr, sz, QEMU_MADV_MERGEABLE);
+ }
+ if (!backend->dump) {
+ qemu_madvise(ptr, sz, QEMU_MADV_DONTDUMP);
+ }
}
}
--
MST
- [Qemu-devel] [PULL 075/103] qom: introduce object_property_get_enum and object_property_get_uint16List, (continued)
- [Qemu-devel] [PULL 075/103] qom: introduce object_property_get_enum and object_property_get_uint16List, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 076/103] numa: add -numa node,memdev= option, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 078/103] memory: add error propagation to file-based RAM allocation, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 079/103] vl: redo -object parsing, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 080/103] pc: pass MachineState to pc_memory_init, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 081/103] backend:hostmem: replace hostmemory with host_memory, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 082/103] hostmem: separate allocation from UserCreatable complete method, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 083/103] hostmem: add file-based HostMemoryBackend, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 077/103] memory: move mem_path handling to memory_region_allocate_system_memory, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 084/103] hostmem: add merge and dump properties,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 085/103] hostmem: allow preallocation of any memory region, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 089/103] hmp: add info memdev, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 090/103] tests: fix memory leak in test of string input visitor, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 091/103] qapi: make string input visitor parse int list, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 092/103] qapi: make string output visitor parse int list, Michael S. Tsirkin, 2014/06/17