-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Honor virtual memory limit #80295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Honor virtual memory limit #80295
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -184,4 +184,21 @@ check_prototype_definition( | |
| ${STATFS_INCLUDES} | ||
| HAVE_NON_LEGACY_STATFS) | ||
|
|
||
| set(CMAKE_REQUIRED_LIBRARIES) | ||
| check_cxx_source_runs(" | ||
| #include <fcntl.h> | ||
| #include <stdlib.h> | ||
| #include <stdio.h> | ||
| #include <unistd.h> | ||
|
|
||
| int main(void) { | ||
| int fd; | ||
|
|
||
| fd = open(\"/proc/self/statm\", O_RDONLY); | ||
| if (fd == -1) { | ||
| exit(1); | ||
| } | ||
| exit(0); | ||
| }" HAVE_PROCFS_STATM) | ||
|
Comment on lines
+187
to
+202
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the point of checking this at build time, shouldn't the runtime not depend on whether the build machine exposes statm?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to detect whether the OS supports that at all. We don't actually support /proc file system optionally on Linux. There is no other way to get the information we need there. We have similar checks in the PAL configure.cmake. |
||
|
|
||
| configure_file(${CMAKE_CURRENT_LIST_DIR}/config.gc.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.gc.h) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,9 @@ SET_DEFAULT_DEBUG_CHANNEL(VIRTUAL); // some headers have code with asserts, so d | |
| #include "pal/init.h" | ||
| #include "pal/utils.h" | ||
| #include "common.h" | ||
| #include <clrconfignocache.h> | ||
|
|
||
| #include <sys/resource.h> | ||
| #include <sys/types.h> | ||
| #include <sys/mman.h> | ||
| #include <errno.h> | ||
|
|
@@ -1617,11 +1619,33 @@ void ExecutableMemoryAllocator::Initialize() | |
| void ExecutableMemoryAllocator::TryReserveInitialMemory() | ||
| { | ||
| CPalThread* pthrCurrent = InternalGetCurrentThread(); | ||
| int32_t sizeOfAllocation = MaxExecutableMemorySizeNearCoreClr; | ||
| int32_t preferredStartAddressIncrement; | ||
| UINT_PTR preferredStartAddress; | ||
| UINT_PTR coreclrLoadAddress; | ||
|
|
||
| int32_t sizeOfAllocation = MaxExecutableMemorySizeNearCoreClr; | ||
| int32_t initialReserveLimit = -1; | ||
| rlimit addressSpaceLimit; | ||
| if ((getrlimit(RLIMIT_AS, &addressSpaceLimit) == 0) && (addressSpaceLimit.rlim_cur != RLIM_INFINITY)) | ||
| { | ||
| // By default reserve max 20% of the available virtual address space | ||
| rlim_t initialExecMemoryPerc = 20; | ||
| CLRConfigNoCache defInitialExecMemoryPerc = CLRConfigNoCache::Get("InitialExecMemoryPercent", /*noprefix*/ false, &getenv); | ||
|
||
| if (defInitialExecMemoryPerc.IsSet()) | ||
| { | ||
| DWORD perc; | ||
| if (defInitialExecMemoryPerc.TryAsInteger(16, perc)) | ||
|
||
| { | ||
| initialExecMemoryPerc = perc; | ||
| } | ||
| } | ||
|
|
||
| initialReserveLimit = addressSpaceLimit.rlim_cur * initialExecMemoryPerc / 100; | ||
| if (initialReserveLimit < sizeOfAllocation) | ||
| { | ||
| sizeOfAllocation = initialReserveLimit; | ||
| } | ||
| } | ||
| #if defined(TARGET_ARM) || defined(TARGET_ARM64) | ||
| // Smaller steps on ARM because we try hard finding a spare memory in a 128Mb | ||
| // distance from coreclr so e.g. all calls from corelib to coreclr could use relocs | ||
|
|
@@ -1697,7 +1721,7 @@ void ExecutableMemoryAllocator::TryReserveInitialMemory() | |
| // does not exceed approximately 2 GB. | ||
| // - The code heap allocator for the JIT can allocate from this address space. Beyond this reservation, one can use | ||
| // the DOTNET_CodeHeapReserveForJumpStubs environment variable to reserve space for jump stubs. | ||
| sizeOfAllocation = MaxExecutableMemorySize; | ||
| sizeOfAllocation = (initialReserveLimit != -1) ? initialReserveLimit : MaxExecutableMemorySize; | ||
| m_startAddress = ReserveVirtualMemory(pthrCurrent, nullptr, sizeOfAllocation, MEM_RESERVE_EXECUTABLE); | ||
| if (m_startAddress == nullptr) | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.