diff options
Diffstat (limited to 'backends')
-rw-r--r-- | backends/hostmem-file.c | 3 | ||||
-rw-r--r-- | backends/hostmem.c | 42 |
2 files changed, 45 insertions, 0 deletions
diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index 55d1c62ddd..92659c119d 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 a2550fe7e3..ebef6206a8 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); + } } } |