diff --git a/hotspot/src/os/linux/vm/os_linux.cpp b/hotspot/src/os/linux/vm/os_linux.cpp index 4cd90ba91b0..032db9f12cb 100644 --- a/hotspot/src/os/linux/vm/os_linux.cpp +++ b/hotspot/src/os/linux/vm/os_linux.cpp @@ -62,6 +62,7 @@ #include "services/attachListener.hpp" #include "services/memTracker.hpp" #include "services/runtimeService.hpp" +#include "utilities/align.hpp" #include "utilities/decoder.hpp" #include "utilities/defaultStream.hpp" #include "utilities/events.hpp" @@ -901,6 +902,16 @@ bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) { } stack_size = MAX2(stack_size, os::Linux::min_stack_allowed); + + // Add an additional page to the stack size to reduce its chances of getting large page aligned + // so that the stack does not get backed by a transparent huge page. + size_t default_large_page_size = os::large_page_size(); + if (default_large_page_size != 0 && + stack_size >= default_large_page_size && + is_aligned(stack_size, default_large_page_size)) { + stack_size += os::vm_page_size(); + } + pthread_attr_setstacksize(&attr, stack_size); } else { // let pthread_create() pick the default value. @@ -3619,6 +3630,10 @@ bool os::Linux::setup_large_page_type(size_t page_size) { } void os::large_page_init() { + // Always initialize the default large page size even if large pages are not being used. + size_t large_page_size = Linux::setup_large_page_size(); + + // Handle the case where we do not want to use huge pages if (!UseLargePages && !UseTransparentHugePages && !UseHugeTLBFS && @@ -3636,7 +3651,6 @@ void os::large_page_init() { return; } - size_t large_page_size = Linux::setup_large_page_size(); UseLargePages = Linux::setup_large_page_type(large_page_size); set_coredump_filter(); diff --git a/hotspot/src/os_cpu/linux_aarch64/vm/globals_linux_aarch64.hpp b/hotspot/src/os_cpu/linux_aarch64/vm/globals_linux_aarch64.hpp index 2733b472789..d60e59d7967 100644 --- a/hotspot/src/os_cpu/linux_aarch64/vm/globals_linux_aarch64.hpp +++ b/hotspot/src/os_cpu/linux_aarch64/vm/globals_linux_aarch64.hpp @@ -29,10 +29,18 @@ // (see globals.hpp) define_pd_global(bool, DontYieldALot, false); -define_pd_global(intx, ThreadStackSize, 2048); // 0 => use system default -define_pd_global(intx, VMThreadStackSize, 2048); -define_pd_global(intx, CompilerThreadStackSize, 0); +// Set default stack sizes < 2MB so as to prevent stacks from getting +// large-page aligned and backed by THPs on systems where 2MB is the +// default huge page size. For non-JavaThreads, glibc may add an additional +// guard page to the total stack size, so to keep the default sizes same +// for all the following flags, we set them to 2 pages less than 2MB. On +// systems where 2MB is the default large page size, 4KB is most commonly +// the regular page size. +define_pd_global(intx, ThreadStackSize, 2040); // 0 => use system default +define_pd_global(intx, VMThreadStackSize, 2040); + +define_pd_global(intx, CompilerThreadStackSize, 2040); define_pd_global(uintx,JVMInvokeMethodSlack, 8192);