mirror of
https://github.com/xemu-project/xemu.git
synced 2024-12-11 05:23:58 +00:00
9181fb7043
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>
84 lines
2.1 KiB
C
84 lines
2.1 KiB
C
/*
|
|
* QEMU Host Memory Backend
|
|
*
|
|
* Copyright (C) 2013-2014 Red Hat Inc
|
|
*
|
|
* Authors:
|
|
* Igor Mammedov <imammedo@redhat.com>
|
|
*
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
* See the COPYING file in the top-level directory.
|
|
*/
|
|
|
|
#ifndef SYSEMU_HOSTMEM_H
|
|
#define SYSEMU_HOSTMEM_H
|
|
|
|
#include "sysemu/numa.h"
|
|
#include "qapi/qapi-types-machine.h"
|
|
#include "qom/object.h"
|
|
#include "exec/memory.h"
|
|
#include "qemu/bitmap.h"
|
|
|
|
#define TYPE_MEMORY_BACKEND "memory-backend"
|
|
OBJECT_DECLARE_TYPE(HostMemoryBackend, HostMemoryBackendClass,
|
|
MEMORY_BACKEND)
|
|
|
|
/* hostmem-ram.c */
|
|
/**
|
|
* @TYPE_MEMORY_BACKEND_RAM:
|
|
* name of backend that uses mmap on the anonymous RAM
|
|
*/
|
|
|
|
#define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram"
|
|
|
|
/* hostmem-file.c */
|
|
/**
|
|
* @TYPE_MEMORY_BACKEND_FILE:
|
|
* name of backend that uses mmap on a file descriptor
|
|
*/
|
|
#define TYPE_MEMORY_BACKEND_FILE "memory-backend-file"
|
|
|
|
|
|
/**
|
|
* HostMemoryBackendClass:
|
|
* @parent_class: opaque parent class container
|
|
*/
|
|
struct HostMemoryBackendClass {
|
|
ObjectClass parent_class;
|
|
|
|
void (*alloc)(HostMemoryBackend *backend, Error **errp);
|
|
};
|
|
|
|
/**
|
|
* @HostMemoryBackend
|
|
*
|
|
* @parent: opaque parent object container
|
|
* @size: amount of memory backend provides
|
|
* @mr: MemoryRegion representing host memory belonging to backend
|
|
* @prealloc_threads: number of threads to be used for preallocatining RAM
|
|
*/
|
|
struct HostMemoryBackend {
|
|
/* private */
|
|
Object parent;
|
|
|
|
/* protected */
|
|
uint64_t size;
|
|
bool merge, dump, use_canonical_path;
|
|
bool prealloc, is_mapped, share, reserve;
|
|
uint32_t prealloc_threads;
|
|
DECLARE_BITMAP(host_nodes, MAX_NODES + 1);
|
|
HostMemPolicy policy;
|
|
|
|
MemoryRegion mr;
|
|
};
|
|
|
|
bool host_memory_backend_mr_inited(HostMemoryBackend *backend);
|
|
MemoryRegion *host_memory_backend_get_memory(HostMemoryBackend *backend);
|
|
|
|
void host_memory_backend_set_mapped(HostMemoryBackend *backend, bool mapped);
|
|
bool host_memory_backend_is_mapped(HostMemoryBackend *backend);
|
|
size_t host_memory_backend_pagesize(HostMemoryBackend *memdev);
|
|
char *host_memory_backend_get_name(HostMemoryBackend *backend);
|
|
|
|
#endif
|