58 lines
2.0 KiB
Diff
58 lines
2.0 KiB
Diff
|
|
From b6c45f5ea5d1a379ac0a507cf59345c573b27cc8 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Chuan Zheng <zhengchuan@huawei.com>
|
||
|
|
Date: Wed, 9 Feb 2022 14:21:39 +0800
|
||
|
|
Subject: [PATCH] oslib-posix: optimise vm startup time for 1G hugepage
|
||
|
|
|
||
|
|
It takes quit a long time to clear 1G-hugepage, which makes glibc
|
||
|
|
pthread_create quit slow.
|
||
|
|
Create touch_pages threads in advance, and then handle the touch_pages
|
||
|
|
callback. Only read lock is held here.
|
||
|
|
---
|
||
|
|
util/oslib-posix.c | 9 ++++++++-
|
||
|
|
1 file changed, 8 insertions(+), 1 deletion(-)
|
||
|
|
|
||
|
|
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
|
||
|
|
index e86fd64e09..9ca3fee2b8 100644
|
||
|
|
--- a/util/oslib-posix.c
|
||
|
|
+++ b/util/oslib-posix.c
|
||
|
|
@@ -88,6 +88,8 @@ static QemuMutex sigbus_mutex;
|
||
|
|
static QemuMutex page_mutex;
|
||
|
|
static QemuCond page_cond;
|
||
|
|
|
||
|
|
+static int started_num_threads;
|
||
|
|
+
|
||
|
|
int qemu_get_thread_id(void)
|
||
|
|
{
|
||
|
|
#if defined(__linux__)
|
||
|
|
@@ -344,6 +346,10 @@ static void *do_touch_pages(void *arg)
|
||
|
|
}
|
||
|
|
qemu_mutex_unlock(&page_mutex);
|
||
|
|
|
||
|
|
+ while (started_num_threads != memset_args->context.num_threads) {
|
||
|
|
+ smp_mb();
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
/* unblock SIGBUS */
|
||
|
|
sigemptyset(&set);
|
||
|
|
sigaddset(&set, SIGBUS);
|
||
|
|
@@ -448,7 +454,7 @@ static int touch_all_pages(char *area, size_t hpagesize, size_t numpages,
|
||
|
|
context.threads = g_new0(MemsetThread, context.num_threads);
|
||
|
|
numpages_per_thread = numpages / context.num_threads;
|
||
|
|
leftover = numpages % context.num_threads;
|
||
|
|
- for (i = 0; i < context.num_threads; i++) {
|
||
|
|
+ for (i = 0, started_num_threads = 0; i < context.num_threads; i++) {
|
||
|
|
context.threads[i].addr = addr;
|
||
|
|
context.threads[i].numpages = numpages_per_thread + (i < leftover);
|
||
|
|
context.threads[i].hpagesize = hpagesize;
|
||
|
|
@@ -464,6 +470,7 @@ static int touch_all_pages(char *area, size_t hpagesize, size_t numpages,
|
||
|
|
QEMU_THREAD_JOINABLE);
|
||
|
|
}
|
||
|
|
addr += context.threads[i].numpages * hpagesize;
|
||
|
|
+ started_num_threads++;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!use_madv_populate_write) {
|
||
|
|
--
|
||
|
|
2.27.0
|
||
|
|
|