79c4324644
Change-Id: I2d302dda68298877c65c99147f5bf22186a59aac
57 lines
2.0 KiB
Diff
57 lines
2.0 KiB
Diff
From e5fc3a755c9ba9f18bc0416c60f745912cb5b104 Mon Sep 17 00:00:00 2001
|
|
From: Chuan Zheng <zhengchuan@huawei.com>
|
|
Date: Wed, 9 Feb 2022 14:21:39 +0800
|
|
Subject: [PATCH 15/15] 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 | 8 +++++++-
|
|
1 file changed, 7 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
|
|
index e8bdb02e1d..18a38b9464 100644
|
|
--- a/util/oslib-posix.c
|
|
+++ b/util/oslib-posix.c
|
|
@@ -84,6 +84,7 @@ typedef struct MemsetThread MemsetThread;
|
|
|
|
static MemsetThread *memset_thread;
|
|
static int memset_num_threads;
|
|
+static int started_num_threads;
|
|
static bool memset_thread_failed;
|
|
|
|
static QemuMutex page_mutex;
|
|
@@ -464,6 +465,10 @@ static void *do_touch_pages(void *arg)
|
|
}
|
|
qemu_mutex_unlock(&page_mutex);
|
|
|
|
+ while (started_num_threads != memset_num_threads) {
|
|
+ smp_mb();
|
|
+ }
|
|
+
|
|
/* unblock SIGBUS */
|
|
sigemptyset(&set);
|
|
sigaddset(&set, SIGBUS);
|
|
@@ -529,7 +534,7 @@ static bool touch_all_pages(char *area, size_t hpagesize, size_t numpages,
|
|
memset_thread = g_new0(MemsetThread, memset_num_threads);
|
|
numpages_per_thread = numpages / memset_num_threads;
|
|
leftover = numpages % memset_num_threads;
|
|
- for (i = 0; i < memset_num_threads; i++) {
|
|
+ for (i = 0, started_num_threads = 0; i < memset_num_threads; i++) {
|
|
memset_thread[i].addr = addr;
|
|
memset_thread[i].numpages = numpages_per_thread + (i < leftover);
|
|
memset_thread[i].hpagesize = hpagesize;
|
|
@@ -537,6 +542,7 @@ static bool touch_all_pages(char *area, size_t hpagesize, size_t numpages,
|
|
do_touch_pages, &memset_thread[i],
|
|
QEMU_THREAD_JOINABLE);
|
|
addr += memset_thread[i].numpages * hpagesize;
|
|
+ started_num_threads++;
|
|
}
|
|
|
|
qemu_mutex_lock(&page_mutex);
|
|
--
|
|
2.27.0
|
|
|