Skip to content
Permalink
Browse files
8261636: The test mapping in hugetlbfs_sanity_check should consider L…
…argePageSizeInBytes

Reviewed-by: tschatzl, iwalulya
  • Loading branch information
kstefanj committed Mar 1, 2021
1 parent 702ca62 commit 0a7fff46cfabf5b419a39fe632c3e7afb4845af2
Showing with 16 additions and 11 deletions.
  1. +14 −11 src/hotspot/os/linux/os_linux.cpp
  2. +2 −0 src/hotspot/os/linux/os_linux.hpp
@@ -3529,11 +3529,19 @@ bool os::Linux::transparent_huge_pages_sanity_check(bool warn,
return result;
}

int os::Linux::hugetlbfs_page_size_flag(size_t page_size) {
if (page_size != default_large_page_size()) {
return (exact_log2(page_size) << MAP_HUGE_SHIFT);
}
return 0;
}

bool os::Linux::hugetlbfs_sanity_check(bool warn, size_t page_size) {
bool result = false;
void *p = mmap(NULL, page_size, PROT_READ|PROT_WRITE,
MAP_ANONYMOUS|MAP_PRIVATE|MAP_HUGETLB,
-1, 0);

// Include the page size flag to ensure we sanity check the correct page size.
int flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_HUGETLB | hugetlbfs_page_size_flag(page_size);
void *p = mmap(NULL, page_size, PROT_READ|PROT_WRITE, flags, -1, 0);

if (p != MAP_FAILED) {
// We don't know if this really is a huge page or not.
@@ -3980,10 +3988,9 @@ char* os::Linux::reserve_memory_special_huge_tlbfs_only(size_t bytes,

int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
int flags = MAP_PRIVATE|MAP_ANONYMOUS|MAP_HUGETLB;
// Ensure the correct page size flag is used when needed.
flags |= hugetlbfs_page_size_flag(os::large_page_size());

if (os::large_page_size() != default_large_page_size()) {
flags |= (exact_log2(os::large_page_size()) << MAP_HUGE_SHIFT);
}
char* addr = (char*)::mmap(req_addr, bytes, prot, flags, -1, 0);

if (addr == MAP_FAILED) {
@@ -4053,11 +4060,7 @@ char* os::Linux::reserve_memory_special_huge_tlbfs_mixed(size_t bytes,
}

// Commit large-paged area.
flags |= MAP_HUGETLB;

if (os::large_page_size() != default_large_page_size()) {
flags |= (exact_log2(os::large_page_size()) << MAP_HUGE_SHIFT);
}
flags |= MAP_HUGETLB | hugetlbfs_page_size_flag(os::large_page_size());

result = ::mmap(lp_start, lp_bytes, prot, flags, -1, 0);
if (result == MAP_FAILED) {
@@ -87,6 +87,8 @@ class Linux {
static bool hugetlbfs_sanity_check(bool warn, size_t page_size);
static bool shm_hugetlbfs_sanity_check(bool warn, size_t page_size);

static int hugetlbfs_page_size_flag(size_t page_size);

static char* reserve_memory_special_shm(size_t bytes, size_t alignment, char* req_addr, bool exec);
static char* reserve_memory_special_huge_tlbfs(size_t bytes, size_t alignment, char* req_addr, bool exec);
static char* reserve_memory_special_huge_tlbfs_only(size_t bytes, char* req_addr, bool exec);

1 comment on commit 0a7fff4

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 0a7fff4 Mar 1, 2021

Please sign in to comment.