Memory Cards: Use file memory mapping instead of explicit file I/O - #12187
Open
F0bes wants to merge 3 commits into
Open
Memory Cards: Use file memory mapping instead of explicit file I/O#12187F0bes wants to merge 3 commits into
F0bes wants to merge 3 commits into
Conversation
kamfretoz
approved these changes
Jan 13, 2025
kamfretoz
left a comment
Contributor
There was a problem hiding this comment.
Works good on both linux and mac
F0bes
force-pushed
the
memory-card-destroyer-9000
branch
2 times, most recently
from
January 14, 2025 03:49
7fcfbda to
cbc55d4
Compare
F0bes
force-pushed
the
memory-card-destroyer-9000
branch
4 times, most recently
from
March 17, 2025 22:28
4c6da80 to
a572c80
Compare
kamfretoz
suggested changes
Mar 19, 2025
Contributor
There was a problem hiding this comment.
Formatting an unformatted folder memcard causes PCSX2 to crash on linux with this backtrace:
*************** Unhandled SIGSEGV at 0x60f19fbec15e ***************
0x0060f1a03e07f9 LogCallstack [/home/runner/work/pcsx2/pcsx2/common/CrashHandler.cpp:284]
0x0060f1a03e06e3 CrashSignalHandler [/home/runner/work/pcsx2/pcsx2/common/CrashHandler.cpp:315]
0x0060f1a0400853 SignalHandler [/home/runner/work/pcsx2/pcsx2/common/Linux/LnxHostSys.cpp:362]
0x00754dd22421ff
0x0060f19fbec15e ReadFromFile [/home/runner/work/pcsx2/pcsx2/pcsx2/SIO/Memcard/MemoryCardFolder.cpp:909]
0x0060f19fbec3a6 ReadDataWithoutCache [/home/runner/work/pcsx2/pcsx2/pcsx2/SIO/Memcard/MemoryCardFolder.cpp:1014]
0x0060f19fbec3a6 Read [/home/runner/work/pcsx2/pcsx2/pcsx2/SIO/Memcard/MemoryCardFolder.cpp:972]
0x0060f19fbfced5 Read [/home/runner/work/pcsx2/pcsx2/pcsx2/SIO/Memcard/MemoryCardFolder.cpp:2332]
0x0060f19fbfced5 FileMcd_Read [/home/runner/work/pcsx2/pcsx2/pcsx2/SIO/Memcard/MemoryCardFile.cpp:768]
0x0060f19fbfced5 Read [/home/runner/work/pcsx2/pcsx2/pcsx2/SIO/Sio.h:51]
0x0060f19fbfced5 ReadData [/home/runner/work/pcsx2/pcsx2/pcsx2/SIO/Memcard/MemoryCardProtocol.cpp:246]
0x0060f19fbdc643 Memcard [/home/runner/work/pcsx2/pcsx2/pcsx2/SIO/Sio2.cpp:301]
0x0060f19fbdc643 Write [/home/runner/work/pcsx2/pcsx2/pcsx2/SIO/Sio2.cpp:441]
0x0060f19fb80505 psxDma11 [/home/runner/work/pcsx2/pcsx2/pcsx2/IopDma.cpp:241]
0x0060f1ddbce010
*******************************************************************
Aborting application.
fish: Job 1, './PCSX2-linux-Qt-x64-appimage…' terminated by signal SIGABRT (Abort)
F0bes
force-pushed
the
memory-card-destroyer-9000
branch
from
March 19, 2025 22:25
3fd18cc to
e6c6cd8
Compare
Member
Author
|
I don't actually modify how folder memory cards work. Can you confirm if this issue was introduced by this PR? |
Contributor
|
I confirm that this issue was not introduced by this PR as it was also crashing on master. |
F0bes
force-pushed
the
memory-card-destroyer-9000
branch
2 times, most recently
from
January 11, 2026 17:12
47ce68f to
882ec9b
Compare
F0bes
marked this pull request as ready for review
January 11, 2026 17:12
This fixes the two terabytes of logging we get to search through when we want to find something in a macOS actions run.
This appeared to work under x86, but on ARM this (rightfully) fails.
F0bes
force-pushed
the
memory-card-destroyer-9000
branch
from
January 17, 2026 19:27
882ec9b to
fac76b7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Changes
Instead of freads for every memory card read, and fwrite for every memory card write, map the entire memory card into a memory mapping and let the OS manage caching / paging and be a little more efficient.
I've also implemented a separate thread that will asynchronously flush the memory map and the file caches. This triggers when our heuristic to detect memory card saves determines that the memory card has been saved to. It doesn't flush on every game write to the memory card, since a save can take many writes to the memory card. It all depends on the game. With this implementation, we benefit from the speed improvement from memory mapped file access and most importantly reduces the time window for external events such as BSoD, AC power less, etc to result in corrupted memory card files.
Rationale behind Changes
This completely eliminated a bottleneck I found on the Persona 3 memory card menu. Overall memory card reads and block clearing should be faster with less EE thread usage.
As stated above, the time window for your memory card to be corrupted due to power loss or other external events becomes smaller. Beforehand, we had no way of knowing whether the memory card still had dirty pages in memory or not.
This should hopefully address #12433
Suggested Testing Steps
This is experimental and with all memory card code changes, scary! Please do not try this on memory cards you don't want to possibly lose.
To test you just have see if memory card stuff works. Saving / formatting / reading.