Skip to content

Commit 26287be

Browse files
committed
initialize hwloc topology only before first fork, not always
1 parent f3dfe30 commit 26287be

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/libumf.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ static umf_ctl_node_t CTL_NODE(umf)[] = {CTL_CHILD(provider), CTL_CHILD(pool),
4040

4141
void initialize_global_ctl(void) { CTL_REGISTER_MODULE(NULL, umf); }
4242

43+
// Benchmarks may fork multiple times and topology init is slow.
44+
// Init topology before fork (if not already) so children don't repeat it.
45+
// TODO: This is a hack. Better solution is needed.
46+
static void atfork_prepare(void) { umfGetTopologyReduced(); }
47+
4348
umf_result_t umfInit(void) {
4449
utils_init_once(&initMutexOnce, initialize_init_mutex);
4550

@@ -74,11 +79,11 @@ umf_result_t umfInit(void) {
7479
if (TRACKER) {
7580
LOG_DEBUG("UMF library initialized");
7681
}
77-
#if !defined(UMF_NO_HWLOC)
78-
// some benchmarks uses multiple forks, and topology initialization is very slow
79-
// so if we initialize topology before the first fork, we can get significant performance gain.
80-
umfGetTopologyReduced();
82+
83+
#if !defined(_WIN32) && !defined(UMF_NO_HWLOC)
84+
pthread_atfork(atfork_prepare, NULL, NULL);
8185
#endif
86+
8287
return UMF_RESULT_SUCCESS;
8388
}
8489

0 commit comments

Comments
 (0)