~ knotless Search/
↑↓ move↵ open⇧↵ all results

zat.dev/zlay

atproto relay in zig · mirror of https://tangled.org/zat.dev/zlay

0
0
62 lines · 3.2 KB Raw History

musl + static-binary investigation — CLOSED (2026-06-14)

investigation into shipping zlay as a fully static FROM scratch binary (runs on any distro, tiny image, hermetic). outcome: closed. prod stays glibc + glibc-malloc. two durable results below.

verdict

  1. the "musl breaks RocksDB" belief is retired. it was a zig 0.15 codegen artifact (illegal instructions in RocksDB's LRU cache). on 0.16, musl builds, links, and runs clean — zero SIGILL across every musl canary pod's life at thread scale (~2,000–2,080 hosts, 15M+ frames, RocksDB indexing live
    • listReposByCollection paging). musl-libc is sound for our use.
  2. mimalloc is ruled out for zlay's workload. it does not return memory to the OS under our ~2,800-thread-heap model — RSS climbs unbounded. confirmed across v2.3.2, v3.3.2, MIMALLOC_PURGE_DELAY=0, and even under glibc.

the blocker for a static-musl deploy is therefore the allocator, not musl: glibc malloc's per-thread arenas + madvise page-return are what keep prod RSS flat (~2.5 GiB at ~2,950 hosts), and that's glibc-specific. no validated static-musl allocator reproduces it.

the isolation matrix (operator canary, RSS at ~2,030–2,080 hosts, same load)

libcallocatorRSS behaviorverdict
glibcglibc malloc (prod)flat 2.6 GiB, 30h+baseline
muslmimalloc v2.3.2 (default)slow climb past 2.6 GiBfails
muslmimalloc v2.3.2, PURGE_DELAY=0climb ~+300 MiB/hretention ruled out
muslmimalloc v3.3.2 (default)climb → 4 GiB OOMversion not the cause
glibcmimalloc v3.3.2climb → 3.4 GiB+ risingisolates the cause

the last row is the discriminator: holding the allocator at mimalloc and swapping musl→glibc, the climb persists; holding the allocator at glibc malloc, RSS is flat. the only variable that tracks the climb is mimalloc. (mimalloc #1111 reports a v2.x multithreaded RSS pathology fixed in v3 — but v3 still climbs here, so our thread model hits a path the v3 fix doesn't cover. mechanism not proven; MIMALLOC_SHOW_STATS didn't survive the kill path.)

allocator options for a static-musl binary (all dead-ends, for the record)

  • mimalloc — ruled out (above).
  • jemalloc — segfaults under musl.
  • musl's own malloc — no per-thread arenas; known-poor at our thread count; no reason to expect glibc-like page return. untested, not pursued.
  • tcmalloc / static-glibc — untested candidates; only worth trying if a static binary becomes a genuine need.

what was built (the revivable harness)

the -Duse_mimalloc=true build option (compiles mimalloc's static.c with MI_MALLOC_OVERRIDE, MI_LIBC_MUSL on musl) lives on branch musl-mimalloc-static — pushed, not merged (we stay glibc). the three glibc-malloc calls (mallinfo/malloc_info/malloc_trim) are gated on isGnuLibC() there. the operator left the canary infra (isolated pg + PVCs + deployment) up as a revivable repro harness.

if revisited

only worth it if a static binary becomes a real need (e.g. a deploy constraint). the path would be static-musl + tcmalloc (or a tuned static-glibc), measured the same way. otherwise: nothing — glibc prod is flat, cheap, and fine.