1 Star 0 Fork 13

佛系少年中二/openjdk-21

forked from src-openEuler/openjdk-21 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
BackPort-JDK-8324580-SIGFPE-on-THP-initialization-on.patch 5.19 KB
一键复制 编辑 原始数据 按行查看 历史
wuyafang 提交于 2024-10-14 11:38 . sync bishengjdk21 patches
Subject: BackPort of JDK-8324580: SIGFPE on THP initialization on kernels < 4.10
---
src/hotspot/os/linux/hugepages.cpp | 13 +++++++++++++
src/hotspot/os/linux/hugepages.hpp | 1 +
src/hotspot/os/linux/os_linux.cpp | 6 +++++-
.../jtreg/runtime/os/HugePageConfiguration.java | 14 ++++++++++++++
.../os/TestHugePageDecisionsAtVMStartup.java | 3 ++-
5 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/src/hotspot/os/linux/hugepages.cpp b/src/hotspot/os/linux/hugepages.cpp
index f9f9dd497..715bfc165 100644
--- a/src/hotspot/os/linux/hugepages.cpp
+++ b/src/hotspot/os/linux/hugepages.cpp
@@ -230,6 +230,19 @@ void THPSupport::print_on(outputStream* os) {
StaticHugePageSupport HugePages::_static_hugepage_support;
THPSupport HugePages::_thp_support;
+size_t HugePages::thp_pagesize_fallback() {
+ // Older kernels won't publish the THP page size. Fall back to default static huge page size,
+ // since that is likely to be the THP page size as well. Don't do it if the page size is considered
+ // too large to avoid large alignment waste. If static huge page size is unknown, use educated guess.
+ if (thp_pagesize() != 0) {
+ return thp_pagesize();
+ }
+ if (supports_static_hugepages()) {
+ return MIN2(default_static_hugepage_size(), 16 * M);
+ }
+ return 2 * M;
+}
+
void HugePages::initialize() {
_static_hugepage_support.scan_os();
_thp_support.scan_os();
diff --git a/src/hotspot/os/linux/hugepages.hpp b/src/hotspot/os/linux/hugepages.hpp
index cb7c992d7..5d196504c 100644
--- a/src/hotspot/os/linux/hugepages.hpp
+++ b/src/hotspot/os/linux/hugepages.hpp
@@ -107,6 +107,7 @@ public:
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(); }
+ static size_t thp_pagesize_fallback();
static void initialize();
static void print_on(outputStream* os);
diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp
index 4da04ebc7..4ece9f471 100644
--- a/src/hotspot/os/linux/os_linux.cpp
+++ b/src/hotspot/os/linux/os_linux.cpp
@@ -3843,8 +3843,12 @@ void os::large_page_init() {
// In THP mode:
// - os::large_page_size() is the *THP page size*
// - os::pagesizes() has two members, the THP page size and the system page size
- assert(HugePages::supports_thp() && HugePages::thp_pagesize() > 0, "Missing OS info");
_large_page_size = HugePages::thp_pagesize();
+ if (_large_page_size == 0) {
+ log_info(pagesize) ("Cannot determine THP page size (kernel < 4.10 ?)");
+ _large_page_size = HugePages::thp_pagesize_fallback();
+ log_info(pagesize) ("Assuming THP page size to be: " EXACTFMT " (heuristics)", EXACTFMTARGS(_large_page_size));
+ }
_page_sizes.add(_large_page_size);
_page_sizes.add(os::vm_page_size());
diff --git a/test/hotspot/jtreg/runtime/os/HugePageConfiguration.java b/test/hotspot/jtreg/runtime/os/HugePageConfiguration.java
index f475af4c2..14cb88fb6 100644
--- a/test/hotspot/jtreg/runtime/os/HugePageConfiguration.java
+++ b/test/hotspot/jtreg/runtime/os/HugePageConfiguration.java
@@ -84,6 +84,20 @@ class HugePageConfiguration {
return _thpPageSize;
}
+ // Returns the THP page size (if exposed by the kernel) or a guessed THP page size.
+ // Mimics HugePages::thp_pagesize_fallback() method in hotspot (must be kept in sync with it).
+ public long getThpPageSizeOrFallback() {
+ long pageSize = getThpPageSize();
+ if (pageSize != 0) {
+ return pageSize;
+ }
+ pageSize = getStaticDefaultHugePageSize();
+ if (pageSize != 0) {
+ return Math.min(pageSize, 16 * 1024 * 1024);
+ }
+ return 2 * 1024 * 1024;
+ }
+
// Returns true if the THP support is enabled
public boolean supportsTHP() {
return _thpMode == THPMode.always || _thpMode == THPMode.madvise;
diff --git a/test/hotspot/jtreg/runtime/os/TestHugePageDecisionsAtVMStartup.java b/test/hotspot/jtreg/runtime/os/TestHugePageDecisionsAtVMStartup.java
index 340c13707..18242578d 100644
--- a/test/hotspot/jtreg/runtime/os/TestHugePageDecisionsAtVMStartup.java
+++ b/test/hotspot/jtreg/runtime/os/TestHugePageDecisionsAtVMStartup.java
@@ -125,7 +125,8 @@ public class TestHugePageDecisionsAtVMStartup {
out.shouldContain("[info][pagesize] UseLargePages=1, UseTransparentHugePages=0");
out.shouldContain("[info][pagesize] Large page support enabled");
} else if (useLP && useTHP && configuration.supportsTHP()) {
- String thpPageSizeString = buildSizeString(configuration.getThpPageSize());
+ long thpPageSize = configuration.getThpPageSizeOrFallback();
+ String thpPageSizeString = buildSizeString(thpPageSize);
// We expect to see exactly two "Usable page sizes" : the system page size and the THP page size. The system
// page size differs, but its always in KB).
out.shouldContain("[info][pagesize] UseLargePages=1, UseTransparentHugePages=1");
--
2.33.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Autistic_boyya/openjdk-21.git
[email protected]:Autistic_boyya/openjdk-21.git
Autistic_boyya
openjdk-21
openjdk-21
master

搜索帮助