summaryrefslogtreecommitdiffstats
path: root/backends/hostmem-ram.c
diff options
context:
space:
mode:
authorDavid Hildenbrand2021-05-10 13:43:23 +0200
committerPaolo Bonzini2021-06-15 20:27:38 +0200
commit9181fb7043edcf096e0ae426cc3fb6f669c7fcb5 (patch)
tree1226c5d44716b24affb421fcd750c5594f0c7c3a /backends/hostmem-ram.c
parentutil/mmap-alloc: Support RAM_NORESERVE via MAP_NORESERVE under Linux (diff)
downloadqemu-9181fb7043edcf096e0ae426cc3fb6f669c7fcb5.tar.gz
qemu-9181fb7043edcf096e0ae426cc3fb6f669c7fcb5.tar.xz
qemu-9181fb7043edcf096e0ae426cc3fb6f669c7fcb5.zip
hostmem: Wire up RAM_NORESERVE via "reserve" property
Let's provide a way to control the use of RAM_NORESERVE via memory backends using the "reserve" property which defaults to true (old behavior). Only Linux currently supports clearing the flag (and support is checked at runtime, depending on the setting of "/proc/sys/vm/overcommit_memory"). Windows and other POSIX systems will bail out with "reserve=false". The target use case is virtio-mem, which dynamically exposes memory inside a large, sparse memory area to the VM. This essentially allows avoiding to set "/proc/sys/vm/overcommit_memory == 0") when using virtio-mem and also supporting hugetlbfs in the future. As really only Linux implements RAM_NORESERVE right now, let's expose the property only with CONFIG_LINUX. Setting the property to "false" will then only fail in corner cases -- for example on very old kernels or when memory overcommit was completely disabled by the admin. Reviewed-by: Peter Xu <peterx@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Acked-by: Eduardo Habkost <ehabkost@redhat.com> for memory backend and machine core Cc: Markus Armbruster <armbru@redhat.com> Cc: Eric Blake <eblake@redhat.com> Cc: Igor Mammedov <imammedo@redhat.com> Signed-off-by: David Hildenbrand <david@redhat.com> Message-Id: <20210510114328.21835-11-david@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'backends/hostmem-ram.c')
-rw-r--r--backends/hostmem-ram.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c
index 741e701062..b8e55cdbd0 100644
--- a/backends/hostmem-ram.c
+++ b/backends/hostmem-ram.c
@@ -29,6 +29,7 @@ ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
name = host_memory_backend_get_name(backend);
ram_flags = backend->share ? RAM_SHARED : 0;
+ ram_flags |= backend->reserve ? 0 : RAM_NORESERVE;
memory_region_init_ram_flags_nomigrate(&backend->mr, OBJECT(backend), name,
backend->size, ram_flags, errp);
g_free(name);