From: David Hildenbrand <david@redhat.com>
To: qemu-devel@nongnu.org
Cc: "David Hildenbrand" <david@redhat.com>,
"Michal Privoznik" <mprivozn@redhat.com>,
"Igor Mammedov" <imammedo@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
"Eric Blake" <eblake@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Stefan Weil" <sw@weilnetz.de>
Subject: [PATCH v2 6/7] hostmem: Allow for specifying a ThreadContext for preallocation
Date: Mon, 10 Oct 2022 11:11:16 +0200 [thread overview]
Message-ID: <20221010091117.88603-7-david@redhat.com> (raw)
In-Reply-To: <20221010091117.88603-1-david@redhat.com>
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>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
backends/hostmem.c | 12 +++++++++---
include/sysemu/hostmem.h | 2 ++
qapi/qom.json | 4 ++++
3 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/backends/hostmem.c b/backends/hostmem.c
index 76f0394490..8640294c10 100644
--- a/backends/hostmem.c
+++ b/backends/hostmem.c
@@ -232,8 +232,8 @@ static void host_memory_backend_set_prealloc(Object *obj, bool value,
void *ptr = memory_region_get_ram_ptr(&backend->mr);
uint64_t sz = memory_region_size(&backend->mr);
- qemu_prealloc_mem(fd, ptr, sz, backend->prealloc_threads, NULL,
- &local_err);
+ qemu_prealloc_mem(fd, ptr, sz, backend->prealloc_threads,
+ backend->prealloc_context, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return;
@@ -385,7 +385,8 @@ host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
*/
if (backend->prealloc) {
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) {
goto out;
}
@@ -493,6 +494,11 @@ host_memory_backend_class_init(ObjectClass *oc, void *data)
NULL, NULL);
object_class_property_set_description(oc, "prealloc-threads",
"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",
host_memory_backend_get_size,
host_memory_backend_set_size,
diff --git a/include/sysemu/hostmem.h b/include/sysemu/hostmem.h
index 9ff5c16963..39326f1d4f 100644
--- a/include/sysemu/hostmem.h
+++ b/include/sysemu/hostmem.h
@@ -18,6 +18,7 @@
#include "qom/object.h"
#include "exec/memory.h"
#include "qemu/bitmap.h"
+#include "qemu/thread-context.h"
#define TYPE_MEMORY_BACKEND "memory-backend"
OBJECT_DECLARE_TYPE(HostMemoryBackend, HostMemoryBackendClass,
@@ -66,6 +67,7 @@ struct HostMemoryBackend {
bool merge, dump, use_canonical_path;
bool prealloc, is_mapped, share, reserve;
uint32_t prealloc_threads;
+ ThreadContext *prealloc_context;
DECLARE_BITMAP(host_nodes, MAX_NODES + 1);
HostMemPolicy policy;
diff --git a/qapi/qom.json b/qapi/qom.json
index cb6f700c0c..efa74f9799 100644
--- a/qapi/qom.json
+++ b/qapi/qom.json
@@ -578,6 +578,9 @@
#
# @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
# (default: false)
#
@@ -608,6 +611,7 @@
'*policy': 'HostMemPolicy',
'*prealloc': 'bool',
'*prealloc-threads': 'uint32',
+ '*prealloc-context': 'str',
'*share': 'bool',
'*reserve': 'bool',
'size': 'size',
--
2.37.3
next prev parent reply other threads:[~2022-10-10 9:14 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-10 9:11 [PATCH v2 0/7] hostmem: NUMA-aware memory preallocation using ThreadContext David Hildenbrand
2022-10-10 9:11 ` [PATCH v2 1/7] util: Cleanup and rename os_mem_prealloc() David Hildenbrand
2022-10-10 9:11 ` [PATCH v2 2/7] util: Introduce qemu_thread_set_affinity() and qemu_thread_get_affinity() David Hildenbrand
2022-10-10 9:11 ` [PATCH v2 3/7] util: Introduce ThreadContext user-creatable object David Hildenbrand
2022-10-11 5:47 ` Markus Armbruster
2022-10-11 7:53 ` David Hildenbrand
2022-10-12 8:02 ` Markus Armbruster
2022-10-12 8:19 ` David Hildenbrand
2022-10-12 10:23 ` Markus Armbruster
2022-10-12 12:27 ` David Hildenbrand
2022-10-10 9:11 ` [PATCH v2 4/7] util: Add write-only "node-affinity" property for ThreadContext David Hildenbrand
2022-10-11 6:03 ` Markus Armbruster
2022-10-11 7:34 ` David Hildenbrand
2022-10-12 8:03 ` Markus Armbruster
2022-10-12 8:26 ` David Hildenbrand
2022-10-10 9:11 ` [PATCH v2 5/7] util: Make qemu_prealloc_mem() optionally consume a ThreadContext David Hildenbrand
2022-10-10 9:11 ` David Hildenbrand [this message]
2022-10-10 9:11 ` [PATCH v2 7/7] vl: Allow ThreadContext objects to be created before the sandbox option David Hildenbrand
2022-10-10 10:40 ` [PATCH v2 0/7] hostmem: NUMA-aware memory preallocation using ThreadContext Dr. David Alan Gilbert
2022-10-10 11:18 ` David Hildenbrand
2022-10-11 9:02 ` Dr. David Alan Gilbert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221010091117.88603-7-david@redhat.com \
--to=david@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=eduardo@habkost.net \
--cc=imammedo@redhat.com \
--cc=mprivozn@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=sw@weilnetz.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.