Skip to content
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

Decrease instances of the dreaded 2GB allocation error on macOS. Ish. #331

Merged

Conversation

ryanmcgrath
Copy link
Collaborator

This PR implements a macOS-specific AllocateVirtualMemory() function that works around the various nuances across the supported macOS versions. I've given this build to quite a few people and they've reportedly experienced far less cases of errors in allocating below the 2GB boundary (but they can still happen, because on macOS this just isn't as reliable).

I would 100% welcome Jos or someone looking this over and smacking me upside the head if this seems absolutely insane... but, hey, it works.

Ish.

macOS and MAP_32BIT

This codebase actually predates macOS Catalina, and since it's building against an older SDK it'd have been going the "best effort" route due to no support for MAP_32BIT.

However, Catalina actually introduced MAP_32BIT and made it more widely available in 10.15.4. This is one of the differences in how this block of code executes (e.g, Linux vs macOS). MAP_32BIT can be used to request allocation below the 4GB boundary. We really want to get below 2GB, but the differences in this flag on macOS mean we still need to do some annoying workarounds to try and get low.

The block itself is just separated entirely so as to not muck with the rest of the platforms, and I condensed the MAP_JIT check into here as well for brevity.

I was thinking about the 2GB Executable Memory error that users
experience, and decided to look into it again. I realized that this
function actually predates macOS Catalina, and since it's building
against an older SDK it'd have been going the "best effort" route due to
no support for `MAP_32BIT`.

However, Catalina actually introduced `MAP_32BIT` and made it more
widely available in `10.15.4`. This is one of the differences in how
this block of code executes (e.g, Linux vs macOS). `MAP_32BIT` can be
used to request allocation below the 4GB boundary, which is what we're
after here.

The block itself is just separated entirely so as to not muck with the
rest of the platforms, and I condensed the `MAP_JIT` check into here as
well for brevity.

I've tested the built version of this on 10.15.7 and 11.5 and not hit
issues, but this should probably still be tested further.
Source/Core/Common/MemoryUtil.cpp Outdated Show resolved Hide resolved
@NikhilNarayana NikhilNarayana merged commit ad9a266 into project-slippi:slippi Jan 1, 2022
jordan-zilch pushed a commit to jordan-zilch/Ishiiruka that referenced this pull request May 17, 2022
…project-slippi#331)

* Adds a macOS-specific `AllocateExecutableMemory()`

I was thinking about the 2GB Executable Memory error that users
experience, and decided to look into it again. I realized that this
function actually predates macOS Catalina, and since it's building
against an older SDK it'd have been going the "best effort" route due to
no support for `MAP_32BIT`.

However, Catalina actually introduced `MAP_32BIT` and made it more
widely available in `10.15.4`. This is one of the differences in how
this block of code executes (e.g, Linux vs macOS). `MAP_32BIT` can be
used to request allocation below the 4GB boundary, which is what we're
after here.

The block itself is just separated entirely so as to not muck with the
rest of the platforms, and I condensed the `MAP_JIT` check into here as
well for brevity.

I've tested the built version of this on 10.15.7 and 11.5 and not hit
issues, but this should probably still be tested further.

* Force 4kb page size alignment for macOS, formatting fixes

* Apply the Rosetta 2 MemoryArena base finding code for x86_64 macOS, remove Rosetta check entirely.

* macOS and the 2GB boundary, or: an unholy workaround to fix the dreaded 2GB for (some) users who experience it.

* RoundPage ifdefd out of WIN32, comments explaining why
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants