From 1890d85c0e647d3f890e3c7152f8cd2e60dfd826 Mon Sep 17 00:00:00 2001 From: Per Liden Date: Fri, 17 Sep 2021 07:51:45 +0000 Subject: [PATCH] 8273872: ZGC: Explicitly use 2M large pages Reviewed-by: eosterlund, tschatzl, stefank --- .../gc/z/zPhysicalMemoryBacking_linux.cpp | 18 +++++++++--------- src/hotspot/share/gc/z/zArguments.cpp | 7 +++++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/hotspot/os/linux/gc/z/zPhysicalMemoryBacking_linux.cpp b/src/hotspot/os/linux/gc/z/zPhysicalMemoryBacking_linux.cpp index 7a113055423aa..951b98d6cce40 100644 --- a/src/hotspot/os/linux/gc/z/zPhysicalMemoryBacking_linux.cpp +++ b/src/hotspot/os/linux/gc/z/zPhysicalMemoryBacking_linux.cpp @@ -58,6 +58,9 @@ #ifndef MFD_HUGETLB #define MFD_HUGETLB 0x0004U #endif +#ifndef MFD_HUGE_2MB +#define MFD_HUGE_2MB 0x54000000U +#endif // open(2) flags #ifndef O_CLOEXEC @@ -175,12 +178,6 @@ ZPhysicalMemoryBacking::ZPhysicalMemoryBacking(size_t max_capacity) : return; } - if (ZLargePages::is_explicit() && os::large_page_size() != ZGranuleSize) { - log_error_p(gc)("Incompatible large page size configured " SIZE_FORMAT " (expected " SIZE_FORMAT ")", - os::large_page_size(), ZGranuleSize); - return; - } - // Make sure the filesystem block size is compatible if (ZGranuleSize % _block_size != 0) { log_error_p(gc)("Filesystem backing the heap has incompatible block size (" SIZE_FORMAT ")", @@ -199,17 +196,20 @@ ZPhysicalMemoryBacking::ZPhysicalMemoryBacking(size_t max_capacity) : } int ZPhysicalMemoryBacking::create_mem_fd(const char* name) const { + assert(ZGranuleSize == 2 * M, "Granule size must match MFD_HUGE_2MB"); + // Create file name char filename[PATH_MAX]; snprintf(filename, sizeof(filename), "%s%s", name, ZLargePages::is_explicit() ? ".hugetlb" : ""); // Create file - const int extra_flags = ZLargePages::is_explicit() ? MFD_HUGETLB : 0; + const int extra_flags = ZLargePages::is_explicit() ? (MFD_HUGETLB | MFD_HUGE_2MB) : 0; const int fd = ZSyscall::memfd_create(filename, MFD_CLOEXEC | extra_flags); if (fd == -1) { ZErrno err; log_debug_p(gc, init)("Failed to create memfd file (%s)", - ((ZLargePages::is_explicit() && err == EINVAL) ? "Hugepages not supported" : err.to_string())); + (ZLargePages::is_explicit() && (err == EINVAL || err == ENODEV)) ? + "Hugepages (2M) not available" : err.to_string()); return -1; } @@ -445,7 +445,7 @@ ZErrno ZPhysicalMemoryBacking::fallocate_compat_mmap_tmpfs(size_t offset, size_t } // Advise mapping to use transparent huge pages - os::realign_memory((char*)addr, length, os::large_page_size()); + os::realign_memory((char*)addr, length, ZGranuleSize); // Touch the mapping (safely) to make sure it's backed by memory const bool backed = safe_touch_mapping(addr, length, _block_size); diff --git a/src/hotspot/share/gc/z/zArguments.cpp b/src/hotspot/share/gc/z/zArguments.cpp index e22db0c52a8be..ad59d2fbcecfb 100644 --- a/src/hotspot/share/gc/z/zArguments.cpp +++ b/src/hotspot/share/gc/z/zArguments.cpp @@ -72,6 +72,13 @@ void ZArguments::initialize() { vm_exit_during_initialization("The flag -XX:+UseZGC can not be combined with -XX:ConcGCThreads=0"); } + // Large page size must match granule size + if (!FLAG_IS_DEFAULT(LargePageSizeInBytes) && LargePageSizeInBytes != ZGranuleSize) { + vm_exit_during_initialization(err_msg("Incompatible -XX:LargePageSizeInBytes, only " + SIZE_FORMAT "M large pages are supported by ZGC", + ZGranuleSize / M)); + } + // The heuristics used when UseDynamicNumberOfGCThreads is // enabled defaults to using a ZAllocationSpikeTolerance of 1. if (UseDynamicNumberOfGCThreads && FLAG_IS_DEFAULT(ZAllocationSpikeTolerance)) {