Skip to content

Allow savestate undo disable for pcsx_rearmed on old3ds#18755

Merged
LibretroAdmin merged 5 commits intolibretro:masterfrom
notaz:savestate_undo_disable
Feb 22, 2026
Merged

Allow savestate undo disable for pcsx_rearmed on old3ds#18755
LibretroAdmin merged 5 commits intolibretro:masterfrom
notaz:savestate_undo_disable

Conversation

@notaz
Copy link
Contributor

@notaz notaz commented Feb 22, 2026

Description

pcsx_rearmed is usable on old3ds, especially on some 2D games. However it goes unstable as soon as a savestate is loaded/saved. Turns out that due to large PSX savestates, the savestate undo buffers may eat something like 18MB out of ~42MB of RAM available to the core. When that happens the libctru variation in RetroArch tries to salvage memory from linear memory and/or stack, and when those are small or start overlapping with heap space things go real bad.

This PR proposes a way to disable the savestate undo feature from the core, as well as some other tweaks to reduce mem use in savestate code. See the individual commits for more explanation.

Related Issues

notaz/pcsx_rearmed#403 (on new3ds likely the same)

This frees ~160k of RAM without any downsides that I know of.
It's not much, but helps pcsx_rearmed on old3ds where it barely fits in RAM.
Regardless if `save_state_in_background` is enabled or not, it does
exactly the same so the check can be removed.
content_load_state_from_ram() doesn't need the backup copy,
content_save_state() never touches the ram_buf. It seems the whole
logic was copy-pasted from content_undo_load_state() without thinking.
Just take the source pointer instead of making a copy and then freeing it.
This is a big deal on slow platforms having to deal with large states,
like psx on old3ds.
The undo feature may amount to at least 4 simultaneous buffers:
save undo, load undo, the current save/load buffer, temporary buffer.

When emulating a system with relatively large states on a system with
little RAM (like PSX on old3ds) that amounts to something like ~18MB of
~42MB available to the core. Under memory pressure the libctru variation
in RetroArch tries to salvage some memory from the main stack and linear
memory, but since those are variable, they start to overlap creating
instability.

The solution is to just disable the undo feature.
@LibretroAdmin LibretroAdmin merged commit f724cc3 into libretro:master Feb 22, 2026
35 checks passed
notaz added a commit to notaz/pcsx_rearmed that referenced this pull request Feb 23, 2026
@zoltanvb
Copy link
Contributor

/*
 * Environ 4, 5 are no longer supported (GET_VARIABLE / SET_VARIABLES),
 * and reserved to avoid possible ABI clash.
 */

Wouldn't it be better to reserve a new ID from libretro.h eventually?

@notaz
Copy link
Contributor Author

notaz commented Feb 24, 2026

The ID is not 5 but 0x800005, 0x80000x from what I understood is not part of libretro API, but a way to configure RetroArch specifically.

@notaz notaz deleted the savestate_undo_disable branch March 2, 2026 01:56
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.

3 participants