Skip to content

memory: disable THP compaction stalls, cap /tmp, trim glibc arenas and AT-SPI - #214

Open
tcballard wants to merge 2 commits into
OrchardLinux:mainfrom
tcballard:perf-memory-hygiene
Open

tcballard wants to merge 2 commits into
OrchardLinux:mainfrom
tcballard:perf-memory-hygiene

Conversation

@tcballard

Copy link
Copy Markdown
Contributor

Summary

Low-RAM memory hygiene measured on a 1 GB iPhone 6 (948 MiB MemTotal), safe across 1–4 GB boards:

  • Disable THP (never / never): Even with madvise + defer+madvise, MADV_HUGEPAGE requests from browsers and Qt triggered 98,743 direct compaction stalls (87% failure rate) on a 1 GB device.
  • Cap /tmp tmp.mount to size=15%: Prevents temporary files from consuming up to 50% of RAM (306 MiB of stale /tmp files pushed zram to 206 MiB physical RAM on 1 GB). On 4 GB iPads this still allows ~600 MiB.
  • Reap gpg-agent after omarchy-pacman-init.service: pacman-key left a 6 MiB gpg-agent --homedir /etc/pacman.d/gnupg running permanently after first-boot keyring setup; stop it via ExecStartPost.
  • Export NO_AT_BRIDGE=1 and MALLOC_ARENA_MAX=2 MALLOC_TRIM_THRESHOLD_=65536 in login-session (and systemd --user): suppresses the ~19 MiB AT-SPI accessibility bus and curbs multi-arena 2 MiB glibc heap chunk retention across threaded daemons (qs, labwc, portals, wireplumber).

Testing

  • Added tests/test_memory_hygiene.py (4/4 pass); test_gpu_video_session.py (11/11) and test_package_staging.py (7/7) pass.

…d AT-SPI

Measured on 1 GB iPhone 6 (948 MiB MemTotal):
- THP madvise + defer+madvise caused 98,743 direct compaction stalls (87%
  failure rate); set THP enabled and defrag to never.
- /tmp defaulted to 50% of RAM, letting stale temp files push zram past 200 MiB
  of physical RAM; cap tmp.mount to 15% of RAM.
- pacman-key left a 6 MiB gpg-agent daemon running permanently after first-boot
  keyring setup; stop it via ExecStartPost.
- Export NO_AT_BRIDGE=1 (suppresses 19 MiB at-spi accessibility stack) and
  MALLOC_ARENA_MAX=2 MALLOC_TRIM_THRESHOLD_=65536 (curbs 2 MiB glibc arena
  fragmentation across threaded daemons) in the login session and user manager.

Assisted-by: LLM
@tcballard
tcballard force-pushed the perf-memory-hygiene branch from 9fcc77a to bcd2b50 Compare December 2, 2026 06:14
@henrikklee

Copy link
Copy Markdown
Contributor

Thanks @tcballard. We've written down a bar for performance and memory changes (CONTRIBUTING, #245): fix the cause rather than switching things off, device measurements, every trade-off named, one change per PR. Measured against it, please split this one:

  • Keep, as their own PR: huge pages off, the memory allocator limits, and stopping gpg-agent after the first-boot keyring setup. These are fine.
  • Drop or justify separately: the /tmp size cap (the drop-in replaces the default mount options rather than adding to them, so /tmp silently loses nosuid/nodev and its inode limit, and a ~150 MB cap breaks large downloads in /tmp), and turning off the accessibility bus (that switches a system part off rather than fixing a cost).
    Thanks for the measurements throughout.

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.

2 participants