Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/gc/unix/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#cmakedefine01 HAVE_SYS_MMAN_H
#cmakedefine01 HAVE_PTHREAD_THREADID_NP
#cmakedefine01 HAVE_PTHREAD_GETTHREADID_NP
#cmakedefine01 HAVE_VM_FLAGS_SUPERPAGE_SIZE_ANY
#cmakedefine01 HAVE_MAP_HUGETLB
#cmakedefine01 HAVE_SCHED_GETCPU
#cmakedefine01 HAVE_NUMA_H
Expand Down
9 changes: 9 additions & 0 deletions src/gc/unix/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ check_cxx_source_compiles("
}
" HAVE_PTHREAD_GETTHREADID_NP)

check_cxx_source_compiles("
#include <sys/mman.h>

int main()
{
return VM_FLAGS_SUPERPAGE_SIZE_ANY;
}
" HAVE_VM_FLAGS_SUPERPAGE_SIZE_ANY)

check_cxx_source_compiles("
#include <sys/mman.h>

Expand Down
2 changes: 2 additions & 0 deletions src/gc/unix/gcenv.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@ void* GCToOSInterface::VirtualReserveAndCommitLargePages(size_t size)
{
#if HAVE_MAP_HUGETLB
uint32_t largePagesFlag = MAP_HUGETLB;
#elif HAVE_VM_FLAGS_SUPERPAGE_SIZE_ANY
uint32_t largePagesFlag = VM_FLAGS_SUPERPAGE_SIZE_ANY;
#else
uint32_t largePagesFlag = 0;
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/pal/src/config.h.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef _PAL_CONFIG_H_INCLUDED
#define _PAL_CONFIG_H_INCLUDED 1

#cmakedefine01 HAVE_VM_FLAGS_SUPERPAGE_SIZE_ANY
#cmakedefine01 HAVE_MAP_HUGETLB
#cmakedefine01 HAVE_IEEEFP_H
#cmakedefine01 HAVE_SYS_VMPARAM_H
#cmakedefine01 HAVE_MACH_VM_TYPES_H
Expand Down
16 changes: 16 additions & 0 deletions src/pal/src/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ endif()

set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS})

check_cxx_source_compiles("
#include <sys/mman.h>
int main()
{
return VM_FLAGS_SUPERPAGE_SIZE_ANY;
}
" HAVE_VM_FLAGS_SUPERPAGE_SIZE_ANY)

check_cxx_source_compiles("
#include <sys/mman.h>
int main()
{
return MAP_HUGETLB;
}
" HAVE_MAP_HUGETLB)

check_cxx_source_compiles("
#include <lttng/tracepoint.h>
int main(int argc, char **argv) {
Expand Down
29 changes: 22 additions & 7 deletions src/pal/src/map/virtual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ static size_t s_virtualPageSize = 0;
static LPVOID ReserveVirtualMemory(
IN CPalThread *pthrCurrent, /* Currently executing thread */
IN LPVOID lpAddress, /* Region to reserve or commit */
IN SIZE_T dwSize); /* Size of Region */
IN SIZE_T dwSize, /* Size of Region */
IN DWORD fAllocationType); /* Allocation Type */


// A memory allocator that allocates memory from a pre-reserved region
Expand Down Expand Up @@ -915,7 +916,7 @@ static LPVOID VIRTUALReserveMemory(
if (pRetVal == NULL)
{
// Try to reserve memory from the OS
pRetVal = ReserveVirtualMemory(pthrCurrent, (LPVOID)StartBoundary, MemSize);
pRetVal = ReserveVirtualMemory(pthrCurrent, (LPVOID)StartBoundary, MemSize, flAllocationType);
}

if (pRetVal != NULL)
Expand Down Expand Up @@ -958,7 +959,8 @@ static LPVOID VIRTUALReserveMemory(
static LPVOID ReserveVirtualMemory(
IN CPalThread *pthrCurrent, /* Currently executing thread */
IN LPVOID lpAddress, /* Region to reserve or commit */
IN SIZE_T dwSize) /* Size of Region */
IN SIZE_T dwSize, /* Size of Region */
IN DWORD fAllocationType) /* Allocation type */
{
UINT_PTR StartBoundary = (UINT_PTR)lpAddress;
SIZE_T MemSize = dwSize;
Expand Down Expand Up @@ -986,6 +988,19 @@ static LPVOID ReserveVirtualMemory(
mmapFlags |= MAP_FIXED;
#endif // HAVE_VM_ALLOCATE

if ((fAllocationType & MEM_LARGE_PAGES) != 0)
{
#if HAVE_MAP_HUGETLB
mmapFlags |= MAP_HUGETLB;
TRACE("MAP_HUGETLB flag set\n");
#elif HAVE_VM_FLAGS_SUPERPAGE_SIZE_ANY
mmapFlags |= VM_FLAGS_SUPERPAGE_SIZE_ANY;
TRACE("VM_FLAGS_SUPERPAGE_SIZE_ANY flag set\n");
#else
TRACE("Large Pages requested, but not supported in this PAL configuration\n");
#endif
}

mmapFlags |= MAP_ANON | MAP_PRIVATE;

LPVOID pRetVal = mmap((LPVOID) StartBoundary,
Expand Down Expand Up @@ -1338,10 +1353,10 @@ VirtualAlloc(
}

/* Test for un-supported flags. */
if ( ( flAllocationType & ~( MEM_COMMIT | MEM_RESERVE | MEM_RESET | MEM_TOP_DOWN | MEM_RESERVE_EXECUTABLE ) ) != 0 )
if ( ( flAllocationType & ~( MEM_COMMIT | MEM_RESERVE | MEM_RESET | MEM_TOP_DOWN | MEM_RESERVE_EXECUTABLE | MEM_LARGE_PAGES ) ) != 0 )
{
ASSERT( "flAllocationType can be one, or any combination of MEM_COMMIT, \
MEM_RESERVE, MEM_TOP_DOWN, or MEM_RESERVE_EXECUTABLE.\n" );
MEM_RESERVE, MEM_TOP_DOWN, MEM_RESERVE_EXECUTABLE, or MEM_LARGE_PAGES.\n" );
pthrCurrent->SetLastError( ERROR_INVALID_PARAMETER );
goto done;
}
Expand Down Expand Up @@ -2145,7 +2160,7 @@ void ExecutableMemoryAllocator::TryReserveInitialMemory()
// Do actual memory reservation.
do
{
m_startAddress = ReserveVirtualMemory(pthrCurrent, (void*)preferredStartAddress, sizeOfAllocation);
m_startAddress = ReserveVirtualMemory(pthrCurrent, (void*)preferredStartAddress, sizeOfAllocation, 0 /* fAllocationType */);
if (m_startAddress != nullptr)
{
break;
Expand Down Expand Up @@ -2175,7 +2190,7 @@ void ExecutableMemoryAllocator::TryReserveInitialMemory()
// - The code heap allocator for the JIT can allocate from this address space. Beyond this reservation, one can use
// the COMPlus_CodeHeapReserveForJumpStubs environment variable to reserve space for jump stubs.
sizeOfAllocation = MaxExecutableMemorySize;
m_startAddress = ReserveVirtualMemory(pthrCurrent, nullptr, sizeOfAllocation);
m_startAddress = ReserveVirtualMemory(pthrCurrent, nullptr, sizeOfAllocation, 0 /* fAllocationType */);
if (m_startAddress == nullptr)
{
return;
Expand Down