From a40c9f1c19f36b438c760244c69a0d356a8b3cea Mon Sep 17 00:00:00 2001 From: Jie Fu Date: Wed, 26 May 2021 20:34:49 +0800 Subject: [PATCH 1/2] 8241423: NUMA APIs fail to work in dockers due to dependent syscalls are disabled by default --- src/hotspot/os/linux/os_linux.cpp | 18 +++++++++++++++++- src/hotspot/os/linux/os_linux.hpp | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp index 551accf97f438..6e2db864646b6 100644 --- a/src/hotspot/os/linux/os_linux.cpp +++ b/src/hotspot/os/linux/os_linux.cpp @@ -2962,7 +2962,8 @@ void* os::Linux::libnuma_v2_dlsym(void* handle, const char* name) { } 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, @@ -4477,6 +4478,21 @@ void os::Linux::numa_init() { } } +// Check numa dependent syscalls +bool os::Linux::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; +} + // this is called _after_ the global arguments have been parsed jint os::init_2(void) { diff --git a/src/hotspot/os/linux/os_linux.hpp b/src/hotspot/os/linux/os_linux.hpp index e32996302e62f..8759bd4dae042 100644 --- a/src/hotspot/os/linux/os_linux.hpp +++ b/src/hotspot/os/linux/os_linux.hpp @@ -180,6 +180,7 @@ class Linux { private: static void numa_init(); + static bool numa_syscall_check(); static void expand_stack_to(address bottom); typedef int (*sched_getcpu_func_t)(void); From ea84a3214a74179c70bf44dab6da4ad9eaab6b06 Mon Sep 17 00:00:00 2001 From: Jie Fu Date: Wed, 26 May 2021 22:23:36 +0800 Subject: [PATCH 2/2] Remove os::Linux namespace for numa_syscall_check() --- src/hotspot/os/linux/os_linux.cpp | 30 +++++++++++++++--------------- src/hotspot/os/linux/os_linux.hpp | 1 - 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp index 6e2db864646b6..e3a7e28f77497 100644 --- a/src/hotspot/os/linux/os_linux.cpp +++ b/src/hotspot/os/linux/os_linux.cpp @@ -2961,6 +2961,21 @@ 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() { // Requires sched_getcpu() and numa dependent syscalls support if ((sched_getcpu() != -1) && numa_syscall_check()) { @@ -4478,21 +4493,6 @@ void os::Linux::numa_init() { } } -// Check numa dependent syscalls -bool os::Linux::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; -} - // this is called _after_ the global arguments have been parsed jint os::init_2(void) { diff --git a/src/hotspot/os/linux/os_linux.hpp b/src/hotspot/os/linux/os_linux.hpp index 8759bd4dae042..e32996302e62f 100644 --- a/src/hotspot/os/linux/os_linux.hpp +++ b/src/hotspot/os/linux/os_linux.hpp @@ -180,7 +180,6 @@ class Linux { private: static void numa_init(); - static bool numa_syscall_check(); static void expand_stack_to(address bottom); typedef int (*sched_getcpu_func_t)(void);