From 1413f9e070b19bed33a4552f3e7adb53cf7daf73 Mon Sep 17 00:00:00 2001 From: Jie Fu Date: Fri, 28 May 2021 13:51:37 +0000 Subject: [PATCH] 8241423: NUMA APIs fail to work in dockers due to dependent syscalls are disabled by default Reviewed-by: dholmes, pliden --- src/hotspot/os/linux/os_linux.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp index 551accf97f4..e3a7e28f774 100644 --- a/src/hotspot/os/linux/os_linux.cpp +++ b/src/hotspot/os/linux/os_linux.cpp @@ -2961,8 +2961,24 @@ void* os::Linux::libnuma_v2_dlsym(void* handle, const char* name) { return dlvsym(handle, name, "libnuma_1.2"); } +// Check numa dependent syscalls +static bool numa_syscall_check() { + // NUMA APIs depend on several syscalls. E.g., get_mempolicy is required for numa_get_membind and + // numa_get_interleave_mask. But these dependent syscalls can be unsupported for various reasons. + // Especially in dockers, get_mempolicy is not allowed with the default configuration. So it's necessary + // to check whether the syscalls are available. Currently, only get_mempolicy is checked since checking + // others like mbind would cause unexpected side effects. + int dummy = 0; + if (syscall(SYS_get_mempolicy, &dummy, NULL, 0, (void*)&dummy, 3) == -1) { + return false; + } + + return true; +} + bool os::Linux::libnuma_init() { - if (sched_getcpu() != -1) { // Requires sched_getcpu() support + // Requires sched_getcpu() and numa dependent syscalls support + if ((sched_getcpu() != -1) && numa_syscall_check()) { void *handle = dlopen("libnuma.so.1", RTLD_LAZY); if (handle != NULL) { set_numa_node_to_cpus(CAST_TO_FN_PTR(numa_node_to_cpus_func_t,