aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2014-06-10 19:15:23 +0800
committerMichael S. Tsirkin <mst@redhat.com>2014-06-19 18:44:20 +0300
commita35ba7be4b696d4c7b47318fd2022e6c3eca0a63 (patch)
treef206d1f7d758c159e96724fb066c8c6c3d38c57b /backends
parent605d0a945d020e3024aa7faf8a0e8b471371d8ff (diff)
downloadqemu-a35ba7be4b696d4c7b47318fd2022e6c3eca0a63.zip
qemu-a35ba7be4b696d4c7b47318fd2022e6c3eca0a63.tar.gz
qemu-a35ba7be4b696d4c7b47318fd2022e6c3eca0a63.tar.bz2
hostmem: allow preallocation of any memory region
And allow preallocation of file-based memory even without -mem-prealloc. Some care is necessary because -mem-prealloc does not allow disabling preallocation for hostmem-file. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'backends')
-rw-r--r--backends/hostmem-file.c3
-rw-r--r--backends/hostmem.c42
2 files changed, 45 insertions, 0 deletions
diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
index 55d1c62..92659c1 100644
--- a/backends/hostmem-file.c
+++ b/backends/hostmem-file.c
@@ -9,7 +9,9 @@
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*/
+#include "qemu-common.h"
#include "sysemu/hostmem.h"
+#include "sysemu/sysemu.h"
#include "qom/object_interfaces.h"
/* hostmem-file.c */
@@ -46,6 +48,7 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
error_setg(errp, "-mem-path not supported on this host");
#else
if (!memory_region_size(&backend->mr)) {
+ backend->force_prealloc = mem_prealloc;
memory_region_init_ram_from_file(&backend->mr, OBJECT(backend),
object_get_canonical_path(OBJECT(backend)),
backend->size,
diff --git a/backends/hostmem.c b/backends/hostmem.c
index a2550fe..ebef620 100644
--- a/backends/hostmem.c
+++ b/backends/hostmem.c
@@ -105,6 +105,41 @@ static void host_memory_backend_set_dump(Object *obj, bool value, Error **errp)
}
}
+static bool host_memory_backend_get_prealloc(Object *obj, Error **errp)
+{
+ HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+
+ return backend->prealloc || backend->force_prealloc;
+}
+
+static void host_memory_backend_set_prealloc(Object *obj, bool value,
+ Error **errp)
+{
+ HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+
+ if (backend->force_prealloc) {
+ if (value) {
+ error_setg(errp,
+ "remove -mem-prealloc to use the prealloc property");
+ return;
+ }
+ }
+
+ if (!memory_region_size(&backend->mr)) {
+ backend->prealloc = value;
+ return;
+ }
+
+ if (value && !backend->prealloc) {
+ int fd = memory_region_get_fd(&backend->mr);
+ void *ptr = memory_region_get_ram_ptr(&backend->mr);
+ uint64_t sz = memory_region_size(&backend->mr);
+
+ os_mem_prealloc(fd, ptr, sz);
+ backend->prealloc = true;
+ }
+}
+
static void host_memory_backend_init(Object *obj)
{
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
@@ -113,6 +148,7 @@ static void host_memory_backend_init(Object *obj)
"mem-merge", true);
backend->dump = qemu_opt_get_bool(qemu_get_machine_opts(),
"dump-guest-core", true);
+ backend->prealloc = mem_prealloc;
object_property_add_bool(obj, "merge",
host_memory_backend_get_merge,
@@ -120,6 +156,9 @@ static void host_memory_backend_init(Object *obj)
object_property_add_bool(obj, "dump",
host_memory_backend_get_dump,
host_memory_backend_set_dump, NULL);
+ object_property_add_bool(obj, "prealloc",
+ host_memory_backend_get_prealloc,
+ host_memory_backend_set_prealloc, NULL);
object_property_add(obj, "size", "int",
host_memory_backend_get_size,
host_memory_backend_set_size, NULL, NULL, NULL);
@@ -165,6 +204,9 @@ host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
if (!backend->dump) {
qemu_madvise(ptr, sz, QEMU_MADV_DONTDUMP);
}
+ if (backend->prealloc) {
+ os_mem_prealloc(memory_region_get_fd(&backend->mr), ptr, sz);
+ }
}
}