hostmem: Allow for specifying a ThreadContext for preallocation
Let's allow for specifying a thread context via the "prealloc-context" property. When set, preallcoation threads will be crated via the thread context -- inheriting the same CPU affinity as the thread context. Pinning preallcoation threads to CPUs can heavily increase performance in NUMA setups, because, preallocation from a CPU close to the target NUMA node(s) is faster then preallocation from a CPU further remote, simply because of memory bandwidth for initializing memory with zeroes. This is especially relevant for very large VMs backed by huge/gigantic pages, whereby preallocation is mandatory. Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Message-Id: <20221014134720.168738-7-david@redhat.com> Signed-off-by: David Hildenbrand <david@redhat.com>
This commit is contained in:
parent
e04a34e55c
commit
e681645862
@ -232,8 +232,8 @@ static void host_memory_backend_set_prealloc(Object *obj, bool value,
|
|||||||
void *ptr = memory_region_get_ram_ptr(&backend->mr);
|
void *ptr = memory_region_get_ram_ptr(&backend->mr);
|
||||||
uint64_t sz = memory_region_size(&backend->mr);
|
uint64_t sz = memory_region_size(&backend->mr);
|
||||||
|
|
||||||
qemu_prealloc_mem(fd, ptr, sz, backend->prealloc_threads, NULL,
|
qemu_prealloc_mem(fd, ptr, sz, backend->prealloc_threads,
|
||||||
&local_err);
|
backend->prealloc_context, &local_err);
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
error_propagate(errp, local_err);
|
error_propagate(errp, local_err);
|
||||||
return;
|
return;
|
||||||
@ -385,7 +385,8 @@ host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
|
|||||||
*/
|
*/
|
||||||
if (backend->prealloc) {
|
if (backend->prealloc) {
|
||||||
qemu_prealloc_mem(memory_region_get_fd(&backend->mr), ptr, sz,
|
qemu_prealloc_mem(memory_region_get_fd(&backend->mr), ptr, sz,
|
||||||
backend->prealloc_threads, NULL, &local_err);
|
backend->prealloc_threads,
|
||||||
|
backend->prealloc_context, &local_err);
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -493,6 +494,11 @@ host_memory_backend_class_init(ObjectClass *oc, void *data)
|
|||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
object_class_property_set_description(oc, "prealloc-threads",
|
object_class_property_set_description(oc, "prealloc-threads",
|
||||||
"Number of CPU threads to use for prealloc");
|
"Number of CPU threads to use for prealloc");
|
||||||
|
object_class_property_add_link(oc, "prealloc-context",
|
||||||
|
TYPE_THREAD_CONTEXT, offsetof(HostMemoryBackend, prealloc_context),
|
||||||
|
object_property_allow_set_link, OBJ_PROP_LINK_STRONG);
|
||||||
|
object_class_property_set_description(oc, "prealloc-context",
|
||||||
|
"Context to use for creating CPU threads for preallocation");
|
||||||
object_class_property_add(oc, "size", "int",
|
object_class_property_add(oc, "size", "int",
|
||||||
host_memory_backend_get_size,
|
host_memory_backend_get_size,
|
||||||
host_memory_backend_set_size,
|
host_memory_backend_set_size,
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "qom/object.h"
|
#include "qom/object.h"
|
||||||
#include "exec/memory.h"
|
#include "exec/memory.h"
|
||||||
#include "qemu/bitmap.h"
|
#include "qemu/bitmap.h"
|
||||||
|
#include "qemu/thread-context.h"
|
||||||
|
|
||||||
#define TYPE_MEMORY_BACKEND "memory-backend"
|
#define TYPE_MEMORY_BACKEND "memory-backend"
|
||||||
OBJECT_DECLARE_TYPE(HostMemoryBackend, HostMemoryBackendClass,
|
OBJECT_DECLARE_TYPE(HostMemoryBackend, HostMemoryBackendClass,
|
||||||
@ -66,6 +67,7 @@ struct HostMemoryBackend {
|
|||||||
bool merge, dump, use_canonical_path;
|
bool merge, dump, use_canonical_path;
|
||||||
bool prealloc, is_mapped, share, reserve;
|
bool prealloc, is_mapped, share, reserve;
|
||||||
uint32_t prealloc_threads;
|
uint32_t prealloc_threads;
|
||||||
|
ThreadContext *prealloc_context;
|
||||||
DECLARE_BITMAP(host_nodes, MAX_NODES + 1);
|
DECLARE_BITMAP(host_nodes, MAX_NODES + 1);
|
||||||
HostMemPolicy policy;
|
HostMemPolicy policy;
|
||||||
|
|
||||||
|
@ -578,6 +578,9 @@
|
|||||||
#
|
#
|
||||||
# @prealloc-threads: number of CPU threads to use for prealloc (default: 1)
|
# @prealloc-threads: number of CPU threads to use for prealloc (default: 1)
|
||||||
#
|
#
|
||||||
|
# @prealloc-context: thread context to use for creation of preallocation threads
|
||||||
|
# (default: none) (since 7.2)
|
||||||
|
#
|
||||||
# @share: if false, the memory is private to QEMU; if true, it is shared
|
# @share: if false, the memory is private to QEMU; if true, it is shared
|
||||||
# (default: false)
|
# (default: false)
|
||||||
#
|
#
|
||||||
@ -608,6 +611,7 @@
|
|||||||
'*policy': 'HostMemPolicy',
|
'*policy': 'HostMemPolicy',
|
||||||
'*prealloc': 'bool',
|
'*prealloc': 'bool',
|
||||||
'*prealloc-threads': 'uint32',
|
'*prealloc-threads': 'uint32',
|
||||||
|
'*prealloc-context': 'str',
|
||||||
'*share': 'bool',
|
'*share': 'bool',
|
||||||
'*reserve': 'bool',
|
'*reserve': 'bool',
|
||||||
'size': 'size',
|
'size': 'size',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user