-
Couldn't load subscription status.
- Fork 5.2k
Enable GC Regions on Mac #115251
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
Enable GC Regions on Mac #115251
Changes from all commits
42cf430
e789573
5fe5e62
7990cf5
ff2904d
c746c16
db2b2cb
63a230d
a0ee7ec
47ba0b7
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 |
|---|---|---|
|
|
@@ -49318,8 +49318,18 @@ HRESULT GCHeap::Initialize() | |
| } | ||
| else | ||
| { | ||
| #ifdef MULTIPLE_HEAPS | ||
| // 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)); | ||
| #else // MUTLIPLE_HEAPS | ||
| #if defined(TARGET_IOS) || defined(TARGET_TVOS) | ||
| // On iOS and tvOS only try to reserve 1/4 of physical memory | ||
| gc_heap::regions_range = (size_t)(gc_heap::total_physical_mem / 4); | ||
|
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.
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. How much is 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. https://alwaysprocessing.blog/2022/02/20/size-matters is a great description of iOS virtual address space limitations. The available address space is limited and precious, very similar to the situation on 32-bit OSes. 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.
I expect that this number will be even lower for real world apps that load a bunch of libraries and occupy/fragment the address space further. iOS does some address space randomization, so the exact size of the largest block of memory that we are able to reserve will differ from run to run. And if we reserve too big of a block, other parts of the app may run into out of memory errors while there is a plenty of memory available. I think it means that we should treat iOS as 32-bit OS when it comes to memory reservations. Unless we figure out how to make regions GC work well on 32-bit OSes, we should probably keep using segments GC on iOS, maybe even lower default segment size to make it work more like 32-bit OS. 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.
on my iPhone 16 Pro its 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. Then the question is whether we want to keep macOS on segments too to get a real-world test coverage for segments on 64-bit architectures in an easy to diagnose environment. 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. Don't have a strong preference since Mac has always been on segments. However, given the overall memory policy differences do we feel that iOS specific issues would be repro-able on Mac to help with diagnosing? |
||
| #else // TARGET_IOS && TARGET_TVOS | ||
| // 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 = (size_t)(2 * gc_heap::total_physical_mem); | ||
| #endif // TARGET_IOS && TARGET_TVOS | ||
| #endif // MUTLIPLE_HEAPS | ||
| } | ||
| size_t virtual_mem_limit = GCToOSInterface::GetVirtualMemoryLimit(); | ||
| gc_heap::regions_range = min(gc_heap::regions_range, virtual_mem_limit/2); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -140,11 +140,11 @@ inline void FATAL_GC_ERROR() | |||||
| // | ||||||
| // This means any empty regions can be freely used for any generation. For | ||||||
| // Server GC we will balance regions between heaps. | ||||||
| // For now disable regions for standalone GC and macOS builds | ||||||
| // For now disable regions for standalone GC and iOS and tvOS builds | ||||||
|
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.
Suggested change
might as well take this opportunity to fix this comment since we do have a standalone GC with regions. |
||||||
| // For SunOS or illumos this is temporary, until we can add MAP_PRIVATE | ||||||
| // to the mmap() calls in unix/gcenv.unix.cpp More details here: | ||||||
| // https://github.com/dotnet/runtime/issues/104211 | ||||||
| #if defined (HOST_64BIT) && !defined (BUILD_AS_STANDALONE) && !defined(__APPLE__) && !defined(__sun) | ||||||
| #if defined (HOST_64BIT) && !defined (BUILD_AS_STANDALONE) && !defined(__sun) | ||||||
mangod9 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| #define USE_REGIONS | ||||||
| #endif //HOST_64BIT && BUILD_AS_STANDALONE && !__APPLE__ | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ static int Main() | |
|
|
||
| long lowerBound, upperBound; | ||
| lowerBound = 1200 * 1024; // ~1.2 MB | ||
| upperBound = 1600 * 1024; // ~1.6 MB | ||
| upperBound = 1700 * 1024; // ~1.7 MB | ||
|
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 reason for this change? 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 test checks for size_on_disk of the test binary. Regions adds more code which puts it over the test threshold. |
||
|
|
||
| if (fileSize < lowerBound || fileSize > upperBound) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the comment?