Skip to content

Run the shell's jemalloc without transparent huge pages, purging in the background - #15199

Open
dhh wants to merge 3 commits into
quattrofrom
shell-jemalloc-conf
Open

dhh wants to merge 3 commits into
quattrofrom
shell-jemalloc-conf

Conversation

@dhh

@dhh dhh commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What

omarchy-launch-shell starts Quickshell with MALLOC_CONF=thp:never,background_thread:true. A MALLOC_CONF the user already set is appended after it, so their options still win (jemalloc applies options in order).

The single arena (narenas:1), the other big win, is compiled into Omarchy's quickshell package instead: omacom/omarchy-pkgs#1004. It can't go in the environment, because programs the shell starts inherit MALLOC_CONF.

Why

I profiled the shell before changing anything. Quickshell allocates through jemalloc, and on a stock Omarchy machine the allocator's defaults were the biggest single cost in the process, ahead of anything the QML does:

  • Transparent huge pages. Arch ships transparent_hugepage=always. jemalloc's arenas got backed by 2 MB pages that are mostly never touched. On an idle shell, 230–270 MB of the ~330 MB anonymous memory sat in AnonHugePages.
  • Purging. jemalloc only hands freed pages back while the program keeps allocating, and an idle shell barely allocates. Without the background thread, RSS stayed put after the shell freed ~70 MB.
  • Arenas. The default is 4 arenas per CPU, 128 on this 32-thread machine, so each of the shell's ~33 threads keeps its own pool of freed pages. One arena takes off another ~85 MB.

Apps started from the launcher, menu or bar go through execDetached, then uwsm-app, then a scope, and they inherit the shell's environment. So does everything run in a terminal opened that way. An earlier revision of this PR put narenas:1 there too, and a review caught the effect on children. I measured fd -u . /usr (best of 5):

child's MALLOC_CONF wall user CPU
none 0.030 s 0.25 s
thp:never,background_thread:true (this PR) 0.030 s 0.20 s
thp:never,narenas:1,background_thread:true 0.062 s 0.77 s

The two options kept here cost a child nothing. background_thread adds one sleeping thread to a jemalloc process; I counted 2 threads instead of 1 in a jemalloc-preloaded Python. Keyboard-launched terminals don't go through the shell and get neither option.

Measurements

One monitor, 2560x1440 at scale 1.6, Starship theme, the user's real 16-widget bar. Numbers are from /proc/<pid>/smaps_rollup, RSS in MB.

idle after opening every bar panel, the menu, clipboard, emoji and theme picker once
quattro 462–492 628–677
this PR (environment only) 405 573
this PR + omarchy-pkgs#1004 (patched quickshell) 321–327 483–486
floor: empty Quickshell with one bar window, patched 147

Frame timing with QSG_RENDER_TIMING=1, across the open/close sequence of every panel (about 680 frames per run, two runs each), comparing stock quickshell with the patched one:

GUI thread per frame (polish + sync + animations) render thread per frame, including the vsync wait
stock 0.3.2-4 mean 0.40 / 0.35 ms, p99 7 / 8 ms, max 36 / 26 ms mean 3.4 / 3.8 ms, max 24 / 24 ms
patched, one arena mean 0.36 / 0.33 ms, p99 8 / 7 ms, max 23 / 23 ms mean 4.0 / 3.0 ms, max 22 / 21 ms

One arena doesn't change frame times measurably.

Tests

  • test/shell.d/launch-shell-test.sh asks jemalloc itself, through mallctl, which options it parsed from the environment the shell got: huge pages off, the background thread on, and the arena count left at jemalloc's own default. It also checks that a user's MALLOC_CONF overrides ours. Mutation-checked: adding narenas:1 back, or dropping the variable, fails it.
  • ./test/shell: only the 6 known baseline failures. ./test/cli passes.
  • No new QML warnings in the shell log; the only binding loops are the existing displayCutouts and hints ones.

For a human to check

  • Land omarchy-pkgs#1004 for the bigger half of the gain. It builds green on both arches and is a draft only so it does not merge itself overnight.
  • After a restart, check grep -E 'Rss|AnonHuge' /proc/$(pgrep -f 'quickshell -n -p')/smaps_rollup. Expect about 400 MB RSS without the package change and about 320 MB with it.

🤖 Generated with Claude Code

With Arch's transparent huge pages always on, jemalloc backed the shell's
arenas with 2 MB pages it mostly never touched, and its default of four
arenas per CPU gave each of the shell's threads its own pool of freed
pages. It also only returns freed pages while the program keeps
allocating, which an idle shell does not. thp:never, one arena and the
background purge thread take about 150 MB off an idle shell and let
memory freed later actually leave.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@greptile-apps

greptile-apps Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable new issue was found.

Summary

The launcher disables jemalloc huge pages and enables background cleanup. It now leaves the arena count to the Quickshell package.

  • Quickshell starts without huge pages and purges freed memory in the background.

Reviews (3) · Last reviewed commit: "Keep the shell's arena count out of the ..." · Reviewed by Greptile

Comment thread test/shell.d/launch-shell-test.sh Resolved
dhh and others added 2 commits October 12, 2026 18:57
Programs the shell starts inherit MALLOC_CONF, and one arena halved the
speed of a multithreaded jemalloc program like fd. The arena count now
comes compiled into Omarchy's quickshell package; huge pages off and the
background purge thread stay here, since they cost a child nothing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@dhh dhh changed the title Run the shell's jemalloc on one arena without transparent huge pages Run the shell's jemalloc without transparent huge pages, purging in the background Oct 12, 2026
@dhh
dhh requested a review from outfoxxed October 13, 2026 12:33
@omarchybot omarchybot added the enhancement New feature or request label Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants