From 0629552ee5c2cb0b7608d58c10585b6170bad18e Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Wed, 29 Nov 2023 09:19:29 -0800 Subject: [PATCH] Avoid redundant GetVirtualMemoryLimit syscall (#95376) --- src/coreclr/gc/gc.cpp | 3 ++- src/coreclr/gc/unix/gcenv.unix.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index 820dcbf687baad..e3231dec87aedb 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -48097,7 +48097,8 @@ HRESULT GCHeap::Initialize() // If no hard_limit is configured the reservation size is min of 1/2 GetVirtualMemoryLimit() or max of 256Gb or 2x physical limit. gc_heap::regions_range = max((size_t)256 * 1024 * 1024 * 1024, (size_t)(2 * gc_heap::total_physical_mem)); } - gc_heap::regions_range = min(gc_heap::regions_range, GCToOSInterface::GetVirtualMemoryLimit()/2); + size_t virtual_mem_limit = GCToOSInterface::GetVirtualMemoryLimit(); + gc_heap::regions_range = min(gc_heap::regions_range, virtual_mem_limit/2); gc_heap::regions_range = align_on_page(gc_heap::regions_range); } GCConfig::SetGCRegionRange(gc_heap::regions_range); diff --git a/src/coreclr/gc/unix/gcenv.unix.cpp b/src/coreclr/gc/unix/gcenv.unix.cpp index af11fb7b6ecf80..3ce1ddec98e3e6 100644 --- a/src/coreclr/gc/unix/gcenv.unix.cpp +++ b/src/coreclr/gc/unix/gcenv.unix.cpp @@ -1089,7 +1089,7 @@ const AffinitySet* GCToOSInterface::SetGCThreadsAffinitySet(uintptr_t configAffi #if HAVE_PROCFS_STATM // Return the size of the user-mode portion of the virtual address space of this process. -size_t GetCurrentVirtualMemorySize() +static size_t GetCurrentVirtualMemorySize() { size_t result = (size_t)-1; size_t linelen;