From 615223f0c9378f27dd2d47f004b656c37d33bbd3 Mon Sep 17 00:00:00 2001 From: "tabata.daishi" Date: Fri, 13 Mar 2026 10:47:59 +0900 Subject: [PATCH 1/4] initial commit --- src/hotspot/os/linux/hugepages.cpp | 36 +++++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/hotspot/os/linux/hugepages.cpp b/src/hotspot/os/linux/hugepages.cpp index 7bb8d6e6f52..a966739d064 100644 --- a/src/hotspot/os/linux/hugepages.cpp +++ b/src/hotspot/os/linux/hugepages.cpp @@ -111,20 +111,22 @@ static os::PageSizes scan_hugepages() { os::PageSizes pagesizes; - DIR *dir = opendir(sys_hugepages); - - struct dirent *entry; - size_t pagesize; - while ((entry = readdir(dir)) != NULL) { - if (entry->d_type == DT_DIR && - sscanf(entry->d_name, "hugepages-%zukB", &pagesize) == 1) { - // The kernel is using kB, hotspot uses bytes - // Add each found Large Page Size to page_sizes - pagesize *= K; - pagesizes.add(pagesize); + DIR* dir = opendir(sys_hugepages); + + if (dir != NULL) { + struct dirent *entry; + size_t pagesize; + while ((entry = readdir(dir)) != NULL) { + if (entry->d_type == DT_DIR && + sscanf(entry->d_name, "hugepages-%zukB", &pagesize) == 1) { + // The kernel is using kB, hotspot uses bytes + // Add each found Large Page Size to page_sizes + pagesize *= K; + pagesizes.add(pagesize); + } } + closedir(dir); } - closedir(dir); return pagesizes; } @@ -142,11 +144,13 @@ void StaticHugePageSupport::print_on(outputStream* os) { } void StaticHugePageSupport::scan_os() { - _pagesizes = scan_hugepages(); _default_hugepage_size = scan_default_hugepagesize(); - assert(_pagesizes.contains(_default_hugepage_size), - "Unexpected configuration: default pagesize (" SIZE_FORMAT ") " - "has no associated directory in /sys/kernel/mm/hugepages..", _default_hugepage_size); + if (_default_hugepage_size > 0) { + _pagesizes = scan_hugepages(); + assert(_pagesizes.contains(_default_hugepage_size), + "Unexpected configuration: default pagesize (" SIZE_FORMAT ") " + "has no associated directory in /sys/kernel/mm/hugepages..", _default_hugepage_size); + } _initialized = true; LogTarget(Info, pagesize) lt; if (lt.is_enabled()) { From 522c30454092096aeeabca69a7721110ccc28fd2 Mon Sep 17 00:00:00 2001 From: "tabata.daishi" Date: Fri, 13 Mar 2026 10:53:05 +0900 Subject: [PATCH 2/4] rerun GHA From f3015fbcd2a001e9d8eeada2109983736825ee4f Mon Sep 17 00:00:00 2001 From: "tabata.daishi" Date: Tue, 12 May 2026 11:52:55 +0900 Subject: [PATCH 3/4] initial commit --- src/hotspot/os/linux/hugepages.cpp | 17 +++++++++++++---- src/hotspot/os/linux/hugepages.hpp | 7 ++++++- ...etection.java => TestHugePageDetection.java} | 4 ++-- 3 files changed, 21 insertions(+), 7 deletions(-) rename test/hotspot/jtreg/runtime/os/{HugePageDetection.java => TestHugePageDetection.java} (97%) diff --git a/src/hotspot/os/linux/hugepages.cpp b/src/hotspot/os/linux/hugepages.cpp index a966739d064..6109415f585 100644 --- a/src/hotspot/os/linux/hugepages.cpp +++ b/src/hotspot/os/linux/hugepages.cpp @@ -36,7 +36,7 @@ #include StaticHugePageSupport::StaticHugePageSupport() : - _initialized(false), _pagesizes(), _default_hugepage_size(SIZE_MAX) {} + _initialized(false), _pagesizes(), _default_hugepage_size(SIZE_MAX), _inconsistent(false) {} os::PageSizes StaticHugePageSupport::pagesizes() const { assert(_initialized, "Not initialized"); @@ -141,15 +141,24 @@ void StaticHugePageSupport::print_on(outputStream* os) { } else { os->print_cr(" unknown."); } + if (_inconsistent) { + os->print_cr(" Support inconsistent. JVM will not use static hugepages."); + } } void StaticHugePageSupport::scan_os() { _default_hugepage_size = scan_default_hugepagesize(); if (_default_hugepage_size > 0) { _pagesizes = scan_hugepages(); - assert(_pagesizes.contains(_default_hugepage_size), - "Unexpected configuration: default pagesize (" SIZE_FORMAT ") " - "has no associated directory in /sys/kernel/mm/hugepages..", _default_hugepage_size); + // See https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt: /proc/meminfo should match + // /sys/kernel/mm/hugepages/hugepages-xxxx. However, we may run on a broken kernel (e.g. on WSL) + // that only exposes /proc/meminfo but not /sys/kernel/mm/hugepages. In that case, we are not + // sure about the state of hugepage support by the kernel, so we won't use static hugepages. + if (!_pagesizes.contains(_default_hugepage_size)) { + log_info(pagesize)("Unexpected configuration: default pagesize (" SIZE_FORMAT ") " + "has no associated directory in /sys/kernel/mm/hugepages..", _default_hugepage_size); + _inconsistent = true; + } } _initialized = true; LogTarget(Info, pagesize) lt; diff --git a/src/hotspot/os/linux/hugepages.hpp b/src/hotspot/os/linux/hugepages.hpp index 65c5999aa43..8d3e1f4b9ce 100644 --- a/src/hotspot/os/linux/hugepages.hpp +++ b/src/hotspot/os/linux/hugepages.hpp @@ -52,6 +52,9 @@ class StaticHugePageSupport { // - is the size one gets when using mmap(MAP_HUGETLB) when omitting size specifiers like MAP_HUGE_SHIFT) size_t _default_hugepage_size; + // If true, the kernel support for hugepages is inconsistent + bool _inconsistent; + public: StaticHugePageSupport(); @@ -60,6 +63,8 @@ class StaticHugePageSupport { os::PageSizes pagesizes() const; size_t default_hugepage_size() const; void print_on(outputStream* os); + + bool inconsistent() const { return _inconsistent; } }; enum THPMode { THPMode_always, THPMode_never, THPMode_madvise }; @@ -98,7 +103,7 @@ class HugePages : public AllStatic { static const THPSupport& thp_info() { return _thp_support; } static size_t default_static_hugepage_size() { return _static_hugepage_support.default_hugepage_size(); } - static bool supports_static_hugepages() { return default_static_hugepage_size() > 0; } + static bool supports_static_hugepages() { return default_static_hugepage_size() > 0 && !_static_hugepage_support.inconsistent(); } static THPMode thp_mode() { return _thp_support.mode(); } static bool supports_thp() { return thp_mode() == THPMode_madvise || thp_mode() == THPMode_always; } static size_t thp_pagesize() { return _thp_support.pagesize(); } diff --git a/test/hotspot/jtreg/runtime/os/HugePageDetection.java b/test/hotspot/jtreg/runtime/os/TestHugePageDetection.java similarity index 97% rename from test/hotspot/jtreg/runtime/os/HugePageDetection.java rename to test/hotspot/jtreg/runtime/os/TestHugePageDetection.java index 40d67198c5f..2dac98000f5 100644 --- a/test/hotspot/jtreg/runtime/os/HugePageDetection.java +++ b/test/hotspot/jtreg/runtime/os/TestHugePageDetection.java @@ -29,14 +29,14 @@ * @requires os.family == "linux" * @modules java.base/jdk.internal.misc * java.management - * @run driver HugePageDetection + * @run driver TestHugePageDetection */ import java.util.*; import jdk.test.lib.process.OutputAnalyzer; import jdk.test.lib.process.ProcessTools; -public class HugePageDetection { +public class TestHugePageDetection { public static void main(String[] args) throws Exception { From d78131ae9ee28a9a221bd60303da5fdba59a25a4 Mon Sep 17 00:00:00 2001 From: "tabata.daishi" Date: Tue, 12 May 2026 11:55:35 +0900 Subject: [PATCH 4/4] Revert "initial commit" This reverts commit f3015fbcd2a001e9d8eeada2109983736825ee4f. --- src/hotspot/os/linux/hugepages.cpp | 17 ++++------------- src/hotspot/os/linux/hugepages.hpp | 7 +------ ...ageDetection.java => HugePageDetection.java} | 4 ++-- 3 files changed, 7 insertions(+), 21 deletions(-) rename test/hotspot/jtreg/runtime/os/{TestHugePageDetection.java => HugePageDetection.java} (97%) diff --git a/src/hotspot/os/linux/hugepages.cpp b/src/hotspot/os/linux/hugepages.cpp index 6109415f585..a966739d064 100644 --- a/src/hotspot/os/linux/hugepages.cpp +++ b/src/hotspot/os/linux/hugepages.cpp @@ -36,7 +36,7 @@ #include StaticHugePageSupport::StaticHugePageSupport() : - _initialized(false), _pagesizes(), _default_hugepage_size(SIZE_MAX), _inconsistent(false) {} + _initialized(false), _pagesizes(), _default_hugepage_size(SIZE_MAX) {} os::PageSizes StaticHugePageSupport::pagesizes() const { assert(_initialized, "Not initialized"); @@ -141,24 +141,15 @@ void StaticHugePageSupport::print_on(outputStream* os) { } else { os->print_cr(" unknown."); } - if (_inconsistent) { - os->print_cr(" Support inconsistent. JVM will not use static hugepages."); - } } void StaticHugePageSupport::scan_os() { _default_hugepage_size = scan_default_hugepagesize(); if (_default_hugepage_size > 0) { _pagesizes = scan_hugepages(); - // See https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt: /proc/meminfo should match - // /sys/kernel/mm/hugepages/hugepages-xxxx. However, we may run on a broken kernel (e.g. on WSL) - // that only exposes /proc/meminfo but not /sys/kernel/mm/hugepages. In that case, we are not - // sure about the state of hugepage support by the kernel, so we won't use static hugepages. - if (!_pagesizes.contains(_default_hugepage_size)) { - log_info(pagesize)("Unexpected configuration: default pagesize (" SIZE_FORMAT ") " - "has no associated directory in /sys/kernel/mm/hugepages..", _default_hugepage_size); - _inconsistent = true; - } + assert(_pagesizes.contains(_default_hugepage_size), + "Unexpected configuration: default pagesize (" SIZE_FORMAT ") " + "has no associated directory in /sys/kernel/mm/hugepages..", _default_hugepage_size); } _initialized = true; LogTarget(Info, pagesize) lt; diff --git a/src/hotspot/os/linux/hugepages.hpp b/src/hotspot/os/linux/hugepages.hpp index 8d3e1f4b9ce..65c5999aa43 100644 --- a/src/hotspot/os/linux/hugepages.hpp +++ b/src/hotspot/os/linux/hugepages.hpp @@ -52,9 +52,6 @@ class StaticHugePageSupport { // - is the size one gets when using mmap(MAP_HUGETLB) when omitting size specifiers like MAP_HUGE_SHIFT) size_t _default_hugepage_size; - // If true, the kernel support for hugepages is inconsistent - bool _inconsistent; - public: StaticHugePageSupport(); @@ -63,8 +60,6 @@ class StaticHugePageSupport { os::PageSizes pagesizes() const; size_t default_hugepage_size() const; void print_on(outputStream* os); - - bool inconsistent() const { return _inconsistent; } }; enum THPMode { THPMode_always, THPMode_never, THPMode_madvise }; @@ -103,7 +98,7 @@ class HugePages : public AllStatic { static const THPSupport& thp_info() { return _thp_support; } static size_t default_static_hugepage_size() { return _static_hugepage_support.default_hugepage_size(); } - static bool supports_static_hugepages() { return default_static_hugepage_size() > 0 && !_static_hugepage_support.inconsistent(); } + static bool supports_static_hugepages() { return default_static_hugepage_size() > 0; } static THPMode thp_mode() { return _thp_support.mode(); } static bool supports_thp() { return thp_mode() == THPMode_madvise || thp_mode() == THPMode_always; } static size_t thp_pagesize() { return _thp_support.pagesize(); } diff --git a/test/hotspot/jtreg/runtime/os/TestHugePageDetection.java b/test/hotspot/jtreg/runtime/os/HugePageDetection.java similarity index 97% rename from test/hotspot/jtreg/runtime/os/TestHugePageDetection.java rename to test/hotspot/jtreg/runtime/os/HugePageDetection.java index 2dac98000f5..40d67198c5f 100644 --- a/test/hotspot/jtreg/runtime/os/TestHugePageDetection.java +++ b/test/hotspot/jtreg/runtime/os/HugePageDetection.java @@ -29,14 +29,14 @@ * @requires os.family == "linux" * @modules java.base/jdk.internal.misc * java.management - * @run driver TestHugePageDetection + * @run driver HugePageDetection */ import java.util.*; import jdk.test.lib.process.OutputAnalyzer; import jdk.test.lib.process.ProcessTools; -public class TestHugePageDetection { +public class HugePageDetection { public static void main(String[] args) throws Exception {