Skip to content

Return freed large blocks to the system at once - #20

Merged
DankMiimer merged 1 commit into
linuxfrom
perf/native-memory
Nov 16, 2026
Merged

DankMiimer merged 1 commit into
linuxfrom
perf/native-memory

Conversation

@DankMiimer

Copy link
Copy Markdown
Owner

Closes the open item 0.2.9 shipped with: on the RG DS, memory with the zoomed-out park varied from run to run.

What it was

  • A sample of the RG DS process's memory map during the 400-second zoom round showed no graphics-driver mappings. The growth was in the ordinary heap (15 → 75–83 MiB) and anonymous memory (40 → 70–100 MiB).
  • A malloc_trim once a minute (tried, not kept) gave back 20–33 MiB each time, and the memory refilled within the minute. So glibc was keeping freed native memory.
  • After a large block is freed, glibc raises the size it takes straight from the system, so later large temporary buffers (sprite decoding, the driver's texture copies) stayed in the heap once freed.

The change

launch.sh sets MALLOC_MMAP_THRESHOLD_=262144 unless it is already set, next to the existing MALLOC_ARENA_MAX=2. Blocks over 256 KiB then go back to the system as soon as they are freed. The device report lists the variable, and a new launcher scenario checks both allocator defaults and that a user's own values are kept.

Results (same 400 s zoom round, published 0.2.9 archive, the setting passed in by the QA tool)

Minutes 1–6 RG DS RG34XXSP
0.2.9 as published 336–371 MiB 300–353 MiB
Fixed threshold 329–339 and 329–342 MiB (two rounds) 257–274 MiB
Park, warm minutes 59.7–60.0 FPS 59.3–59.6 FPS

Then a clean package of this commit on both handhelds (80 s park + Pokéwalker): pkforge-report.txt shows the launcher set MALLOC_MMAP_THRESHOLD_=262144. Both runs ended cleanly with no problems reported and userdata unchanged; peak memory was 316 MiB on the RG DS and 262 on the RG34XXSP.

Verification

  • Launcher scenarios: 21 pass in WSL (1 new); sh -n on launch.sh.
  • build.ps1 + verify-package.ps1 on the clean commit.
  • Not covered: handhelds other than the two reference ones (the setting is plain glibc and harmless elsewhere), and long sessions in Home and the editors.

🤖 Generated with Claude Code

With 0.2.9's zoomed-out drawing the RG DS's memory varied from run to run
(336-371 MiB in minutes 1-6). It was native memory glibc kept after it was
freed: after a large block is freed, glibc raises the size it takes directly
from the system, so later large temporary buffers (sprite decoding, the
graphics driver's texture copies) stayed in the heap. The launcher now sets
MALLOC_MMAP_THRESHOLD_=262144 unless it is already set.

Same zoom round on the published 0.2.9 archive: RG DS 329-342 MiB (two runs),
RG34XXSP 257-274 (was 300-353), park still 59-60 FPS in warm minutes. The
device report lists the variable; a launcher test checks both allocator
defaults and that a user's own values are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DankMiimer
DankMiimer merged commit 5846972 into linux Nov 16, 2026
6 checks passed
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.

1 participant