Skip to content

Commit

Permalink
8312620: WSL Linux build crashes after JDK-8310233
Browse files Browse the repository at this point in the history
Backport-of: 25058cd23ac9c8993e7acfd82728ee4c623f0914
  • Loading branch information
tstuefe committed Aug 31, 2023
1 parent e0b39c7 commit 804ce09
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
17 changes: 13 additions & 4 deletions src/hotspot/os/linux/hugepages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include <dirent.h>

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");
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion src/hotspot/os/linux/hugepages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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 class THPMode { always, never, madvise };
Expand Down Expand Up @@ -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(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down

1 comment on commit 804ce09

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.