diff options
author | Eduardo Habkost <ehabkost@redhat.com> | 2017-08-24 16:23:15 -0300 |
---|---|---|
committer | Eduardo Habkost <ehabkost@redhat.com> | 2017-09-19 09:09:23 -0300 |
commit | 11ae6ed8affdd131e735bac39b21e7d3cde66f7b (patch) | |
tree | 8d566e05954e76f90df30bf1d1f3ee38de7509bb /backends | |
parent | 0f81d3353029d26c6f8731a65d8052c532b1ced6 (diff) |
hostmem-file: Add "discard-data" option
The new option can be used to indicate that the file contents can
be destroyed and don't need to be flushed to disk when QEMU exits
or when the memory backend object is removed.
Internally, it will trigger a madvise(MADV_REMOVE) call when the
memory backend is removed.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Message-Id: <20170824192315.5897-4-ehabkost@redhat.com>
[ehabkost: fixup: improved documentation]
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
Tested-by: Zack Cornelius <zack.cornelius@kove.net>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Diffstat (limited to 'backends')
-rw-r--r-- | backends/hostmem-file.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index fc4ef46d11..e44c319915 100644 --- a/backends/hostmem-file.c +++ b/backends/hostmem-file.c @@ -32,6 +32,7 @@ struct HostMemoryBackendFile { HostMemoryBackend parent_obj; bool share; + bool discard_data; char *mem_path; }; @@ -103,16 +104,44 @@ static void file_memory_backend_set_share(Object *o, bool value, Error **errp) fb->share = value; } +static bool file_memory_backend_get_discard_data(Object *o, Error **errp) +{ + return MEMORY_BACKEND_FILE(o)->discard_data; +} + +static void file_memory_backend_set_discard_data(Object *o, bool value, + Error **errp) +{ + MEMORY_BACKEND_FILE(o)->discard_data = value; +} + +static void file_backend_unparent(Object *obj) +{ + HostMemoryBackend *backend = MEMORY_BACKEND(obj); + HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(obj); + + if (host_memory_backend_mr_inited(backend) && fb->discard_data) { + void *ptr = memory_region_get_ram_ptr(&backend->mr); + uint64_t sz = memory_region_size(&backend->mr); + + qemu_madvise(ptr, sz, QEMU_MADV_REMOVE); + } +} + static void file_backend_class_init(ObjectClass *oc, void *data) { HostMemoryBackendClass *bc = MEMORY_BACKEND_CLASS(oc); bc->alloc = file_backend_memory_alloc; + oc->unparent = file_backend_unparent; object_class_property_add_bool(oc, "share", file_memory_backend_get_share, file_memory_backend_set_share, &error_abort); + object_class_property_add_bool(oc, "discard-data", + file_memory_backend_get_discard_data, file_memory_backend_set_discard_data, + &error_abort); object_class_property_add_str(oc, "mem-path", get_mem_path, set_mem_path, &error_abort); |