Skip to content

common, kernel: tune low-RAM host allocator, cold hints, and lazy kernel page backing - #930

Open
nowhere02 wants to merge 3 commits into
nx2-experimentalfrom
perf/nx2-low-ram-host-allocator
Open

nowhere02 wants to merge 3 commits into
nx2-experimentalfrom
perf/nx2-low-ram-host-allocator

Conversation

@nowhere02

@nowhere02 nowhere02 commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Tunes the host allocator for machines with 18 GiB of RAM or less and makes the kernel's dynamic page pool commit lazily. Standalone; no dependency on the other PRs in this series (part 2 of 4).

  • src/common/host_memory.{h,cpp}: ConfigureLowMemoryAllocator() (glibc only: M_ARENA_MAX=4, mmap/trim thresholds 128 KiB; EDEN_NX2_LOW_RAM=0|1 overrides), TrimHostHeap() (malloc_trim), AllocateZeroedVirtualPages() / FreeVirtualPages(), and the "memory is low" floor raised to max(2 GiB, total/7).
  • src/common/settings.h: cold_hint_mode defaults to WhenRamIsLow.
  • src/yuzu/main.cpp, src/yuzu_cmd/yuzu.cpp: call ConfigureLowMemoryAllocator() at startup.
  • src/core/hle/kernel/k_dynamic_page_manager.h: lazy zero-page backing instead of std::vector + per-page memset (~72 MiB no longer touched at boot).
  • src/video_core/shader_warm/shader_warm_builder.cpp: trim the heap after the precache build.

The allocator tuning is a no-op on non-glibc platforms and on hosts above 18 GiB unless EDEN_NX2_LOW_RAM=1.

Assisted-by: Antigravity (RAM profiling, implementation, and verification)

Type of change

  • Bug fix
  • Game compatibility / game-support
  • Performance
  • New feature
  • Refactor / cleanup
  • CI / build
  • Documentation

Related issues

N/A

Testing

  • Tested on Windows
  • Tested on Linux
  • Tested on macOS
  • Tested on NVIDIA
  • Tested on AMD
  • Tested on Intel

Standalone branch: ninja -C build -j10 yuzu eden-cli tests builds; ./build/bin/tests "[common],[game_presets]" passes (5,814,822 assertions in 73 test cases). Not built or run on Windows or macOS (the Windows branch of AllocateZeroedVirtualPages is untested).

Games tested:

Ocarina of Time and Mario Kart World on Linux (Ryzen 5, Vega iGPU, 15.4 GiB RAM), with all 4 PRs of the series applied together.

Checklist

  • I built it locally and it compiles without new warnings
  • I did not add any copyrighted game data, keys or firmware
  • Docs updated if needed
  • I added AI Disclosure if one was used

Screenshots / logs

Measured with the full series applied, Ocarina of Time, 240 s in game: system swap growth +5,570 MiB before, +525 MiB after. Process swap at the end 1,469 MiB before, 104 MiB after. These numbers are for the whole series, not this PR alone.

Summary by CodeRabbit

  • Bug Fixes
    • Improved memory-pressure detection, including a higher low-memory threshold, to help the app respond sooner when available RAM is limited.
    • Updated the default cold-memory hint behavior to activate when RAM is low.
    • Improved memory allocation and cleanup during system memory management and shader-cache preparation.

PastaLaPate and others added 3 commits November 22, 2026 00:19
A manual dispatch gains a linux_arch choice (both, x86_64 or aarch64) that narrows the base Linux legs and the Nix linux systems, and a build_nix tick that skips the Nix job entirely. Defaults keep pushes, dailies, PR builds and untouched manual runs building both architectures with Nix on.

Cherry-picked verbatim onto nx2 and nx2-experimental so a rebase of nx2-experimental onto nx2 drops it as already applied.
`no` keeps the skip the boolean could express. `only` runs the Nix job for
the systems the Linux/macOS ticks (and linux_arch) select, and skips the
Linux, Windows and macOS jobs -- plus the release job, whose assets all come
from those legs, so publishing there would only fail on an empty artifact
set. Default stays `yes`: pushes, dailies, PR builds and untouched manual
runs are unchanged.
…nel page backing

On hosts with 18 GiB of RAM or less, glibc's per-thread arenas and its
dynamic mmap threshold kept freed memory resident across the process.

- Add Common::ConfigureLowMemoryAllocator(): cap glibc arenas at 4 and pin the
  mmap/trim thresholds at 128 KiB. Called at startup from both frontends.
  EDEN_NX2_LOW_RAM=0|1 forces it off or on.
- Add Common::TrimHostHeap() (malloc_trim) and call it after the shader
  precache build.
- Default cold_hint_mode to WhenRamIsLow and raise the "memory is low" floor
  to max(2 GiB, total / 7).
- Back KDynamicPageManager with lazily committed zero pages
  (AllocateZeroedVirtualPages) instead of a std::vector plus a memset of every
  page.

Assisted-by: Antigravity (RAM profiling, implementation, and verification)
@github-actions
github-actions Bot changed the base branch from nx2 to nx2-experimental November 22, 2026 03:36
@github-actions

Copy link
Copy Markdown

Retargeted to nx2-experimental for pre-build testing. It will be promoted to nx2 after validation.

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: df70816d-cea5-4031-893a-2c11783ffd1f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

3 participants