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
MemArena: Keep fastmem memory region mapped on Linux to ensure nothing allocates within the fastmem space. #9834
MemArena: Keep fastmem memory region mapped on Linux to ensure nothing allocates within the fastmem space. #9834
Conversation
1832d7f
to
0fef9c7
Compare
62782c6
to
22c3ed1
Compare
22c3ed1
to
239f495
Compare
5e52e6e
to
3d21dc7
Compare
a10ed2c
to
1bc4a51
Compare
2472fca
to
26e4436
Compare
Source/Core/Common/MemArena.h
Outdated
| #ifdef _WIN32 | ||
| HANDLE hMemoryMapping; | ||
| #else | ||
| #ifdef ANDROID | ||
| int fd; | ||
| #else | ||
| int m_shm_fd; | ||
| void* m_reserved_region; | ||
| std::size_t m_reserved_region_size; | ||
| #endif | ||
| #endif |
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.
| #ifdef _WIN32 | |
| HANDLE hMemoryMapping; | |
| #else | |
| #ifdef ANDROID | |
| int fd; | |
| #else | |
| int m_shm_fd; | |
| void* m_reserved_region; | |
| std::size_t m_reserved_region_size; | |
| #endif | |
| #endif | |
| #if defined(_WIN32) | |
| HANDLE hMemoryMapping; | |
| #elif defined(ANDROID) | |
| int fd; | |
| #else | |
| int m_shm_fd; | |
| void* m_reserved_region; | |
| std::size_t m_reserved_region_size; | |
| #endif |
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.
Additionally - hMemoryMapping and fd lack m_ prefix, so they probably should be renamed for consistency (or avoid using prefix for new member variables too).
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.
Regarding the variable prefixes, I've tried to avoid touching multiple platforms in a single PR, so they'll be done one at a time. The Windows equivalent PR is #9544. There is no Android one yet because I'm not familiar with that platform.
Regarding the defines, our codebase seems to use both variants. Not sure whether it's better to check for the symbol or for a nonzero definition.
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.
Does new Linux approach fail to work on Android?
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.
Genuinely, no idea. I don't have an Android device capable of running Dolphin to test it.
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.
With android being Linux at its core I'd expect this approach to work, unless it is artificially restricted by permissions. Unfortunately, I don't have Dolphin-capable android device/VM/emulator either for quick testing.
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.
shm is not available on Android.
26e4436
to
9773041
Compare
9773041
to
3519906
Compare
3519906
to
38464c2
Compare
| @@ -28,30 +28,39 @@ MemArena::~MemArena() = default; | |||
| void MemArena::GrabSHMSegment(size_t size) | |||
| { | |||
| const std::string file_name = "/dolphin-emu." + std::to_string(getpid()); | |||
| fd = shm_open(file_name.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600); | |||
| if (fd == -1) | |||
| m_shm_fd = shm_open(file_name.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600); | |||
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.
If dolphin crashes, this file will stay until the system is rebooted. This is because it has the pid appended to it and Linux has shm persistence (normally /dev/shm is a tmpfs), so no other instance can come later and clean it up.
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.
Not wrong, but it's unlinked literally the next line, so it would have to crash at a very specific point in time. Not sure if there's much we can do about this? This is also a pre-existing issue.
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.
I completely missed that, then it's ok. Feel free to disregard this.
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.
Also if you dig back in the history, the reason it has the pid attached is because at some point in time there were issues where multiple instances would grab the same if you had netplay with two instances on the same system. So I'd rather not change that.
Is there a way on Linux to say 'this file should not actually show up in the file system, I just need it for myself'?
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.
I found https://man7.org/linux/man-pages/man2/memfd_create.2.html which might be what you could replace the shm_open / shm_unlink with. But that would be another PR as the shm_unlink works fine for now,
38464c2
to
ffbe6cb
Compare
|
If no one has any objections I'd like to merge this sometime soon. The Windows variant has been merged for a few weeks now and apart from one issue of no longer launching on Win7 (which is fixed) I haven't heard any issues with it. I've also re-tested this today (on Xubuntu 20.04) and have confirmed that it does indeed fix freezing issues with large texture packs. |
Same idea as #9544 but for Linux. As I understand correctly Linux allows this brutal clobbering of regions, but I honestly only have half an idea what I'm doing here. Please scrutinize.
This should fix the bug (on Linux) where large texture packs break emulation, such as 12404 or 11994, but I cannot 100% confirm it.