Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Address feedback
  • Loading branch information
EgorBo committed Jun 15, 2022
commit 5897d6d1a09098df6dc3c3e17fc1dcdedb2589e8
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/include/pal/virtual.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class ExecutableMemoryAllocator
// that can be used to calculate an approximate location of the memory that
// is in 2GB range from the coreclr library. In addition, having precise size of libcoreclr
// is not necessary for the calculations.
static const int32_t CoreClrLibrarySize = 10 * 1024 * 1024;
static const int32_t CoreClrLibrarySize = 16 * 1024 * 1024;

#ifdef TARGET_XARCH
Copy link
Member

Choose a reason for hiding this comment

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

This ifdef is incorrect, we don't define TARGET_XARCH out of JIT. Can you please use
#if defined(TARGET_ARM) || defined(TARGET_ARM64) here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, yes, again I am using JIT's flags in the VM 😞 the incorrect define slightly regressed x64/x86 by decreasing preferable size from 2Gb to 1Gb. Thanks, fixed

// This constant represent the max size of the virtual memory that this allocator
Expand Down
53 changes: 32 additions & 21 deletions src/coreclr/pal/src/map/virtual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2196,34 +2196,45 @@ void ExecutableMemoryAllocator::TryReserveInitialMemory()
preferredStartAddress += preferredStartAddressIncrement;

} while (sizeOfAllocation >= MemoryProbingIncrement);
#else

// Always try to allocate above the location of libcoreclr on arm - we want to start allocating near it (withih 128Mb distance)
// however, we want to reserve as much as possible (ideally, 756Mb)
preferredStartAddress = coreclrLoadAddress + CoreClrLibrarySize;
#else // TARGET_XARCH

do
if ((coreclrLoadAddress < 0xFFFFFFFF) || ((coreclrLoadAddress - MaxExecutableMemorySizeNearCoreClr) < 0xFFFFFFFF))
{
m_startAddress = ReserveVirtualMemory(pthrCurrent, (void*)preferredStartAddress, sizeOfAllocation, MEM_RESERVE_EXECUTABLE);
if (m_startAddress != nullptr)
{
break;
}
// Try to allocate above the location of libcoreclr on arm - we want to start allocating near it (withih 128Mb distance)
// however, we want to reserve as much as possible (ideally, 756Mb)
preferredStartAddress = coreclrLoadAddress + CoreClrLibrarySize;

// Try to allocate a smaller region...
sizeOfAllocation -= 64 * 1024 * 1024;
const int32_t smallestAllocSize = MaxExecutableMemorySizeNearCoreClr / 3 * 2;
if (sizeOfAllocation < smallestAllocSize)
do
{
// ...but not less than 2/3rd of what we initially planned
sizeOfAllocation = smallestAllocSize;
}
m_startAddress = ReserveVirtualMemory(pthrCurrent, (void*)preferredStartAddress, sizeOfAllocation, MEM_RESERVE_EXECUTABLE);
if (m_startAddress != nullptr)
{
break;
}

// Try to allocate a smaller region...
sizeOfAllocation -= 64 * 1024 * 1024;
const int32_t smallestAllocSize = MaxExecutableMemorySizeNearCoreClr / 3 * 2;
if (sizeOfAllocation < smallestAllocSize)
{
// ...but not less than 2/3rd of what we initially planned
sizeOfAllocation = smallestAllocSize;
}

// Probe each 8Mb
preferredStartAddress += 8 * 1024 * 1024;
// Probe each 8Mb
preferredStartAddress += 8 * 1024 * 1024;

// bail out if preferredStartAddress is already too far from coreclr and we won't be able to use relocs
} while ((preferredStartAddress - coreclrLoadAddress) < (128 * 1024 * 1024));
// bail out if preferredStartAddress is already too far from coreclr and we won't be able to use relocs
} while ((preferredStartAddress - coreclrLoadAddress) < (128 * 1024 * 1024));
}
else
{
// Rare case: if we have to reserve memory above the coreclr we'll only try to allocate 128Mb (for relocs) in front of it.
// It doesn't make much sense to do probing here in a loop
preferredStartAddress = coreclrLoadAddress - 128 * 1024 * 1024;
m_startAddress = ReserveVirtualMemory(pthrCurrent, (void*)preferredStartAddress, 128 * 1024 * 1024, MEM_RESERVE_EXECUTABLE);
}
#endif

if (m_startAddress == nullptr)
Expand Down