Repository navigation
Conversation
…y stops growing With --api-server-count > 1 every front-end worker renders and tokenizes long prompts on many threads (the default executor and the tokenizers' rayon pool). glibc malloc gives each thread its own arena and keeps freed memory there, so a worker's RSS keeps growing over a long run. jemalloc hands freed pages back to the OS and leaves the thread count, and so the tokenizer parallelism, unchanged. _start_frontend_workers now sets LD_PRELOAD to libjemalloc.so.2 only while it spawns the workers (an existing LD_PRELOAD is kept behind it) and restores the environment right after. The API process and the engine processes, started before, keep their allocator. When the host has no libjemalloc.so.2 the workers fall back to glibc malloc with one warning; the server starts as before. The allocator the workers got is logged once. No new options or environment variables. --api-server-count 1 is unchanged. Tests: tests/entrypoints/test_api_server_helpers.py (preload set only while spawning, an existing preload kept and restored, an existing jemalloc preload left alone, glibc fallback with a warning, restore on a failed spawn). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🏷️ CI GuideRuns automatically on every eligible PR before approval:
Heavy model tests:
Path scope:
|
valar-cop
left a comment
There was a problem hiding this comment.
a few small things..
perf/rss numbers on the pr head? description says still in progress and numbers are from earlier main + local patches
ci ATOM Test Gate failed — main is already broken the same way (medium): The collected log is empty (0 bytes), so the failing step is unknown here. The same gate fails on main at 01:53, 09:15 and 09:40 the same day and is 3 success / 3 failure on other recent runs, so it predates this two-file api_server/test change.
same job on main: ['2026-11-25T09:40 failure', '2026-11-25T09:15 failure', '2026-11-25T01:53 failure'], on other recent runs: {'success': 3, 'failure': 3}
.valar/ci/job_139149834085.log: 0 bytes
next: Rely on a re-run or the next main run; nothing to fix in this PR. https://github.com/ROCm/ATOM/actions/runs/45594693078/job/139149834085
| ) | ||
| proc.start() | ||
| processes.append(proc) | ||
| logger.info( |
There was a problem hiding this comment.
this logs the intent, not what actually loaded. fallback soname is never verified and ld.so just warns and runs glibc, so maybe log the real allocator from the worker once?
There was a problem hiding this comment.
Done in 73309e1: each worker now logs the allocator it actually mapped (read from /proc/self/maps, falls back to "glibc malloc"); the parent log line now only says what was put in LD_PRELOAD.
| monkeypatch.delenv("LD_PRELOAD", raising=False) | ||
|
|
||
|
|
||
| def test_preload_is_set_only_while_the_workers_are_spawned(monkeypatch, no_preload): |
There was a problem hiding this comment.
nothing asserts the spawn loop runs inside the with, so removing the wrapper keeps tests green. add a test that records LD_PRELOAD in fake start()?
There was a problem hiding this comment.
Added test_the_workers_are_started_with_jemalloc_preloaded in 73309e1: it runs _start_frontend_workers with a fake Process.start() that records LD_PRELOAD; replacing the with by a nullcontext makes it fail.
| _JEMALLOC_CANDIDATES = ( | ||
| "/usr/lib/x86_64-linux-gnu/libjemalloc.so.2", | ||
| "/usr/lib/aarch64-linux-gnu/libjemalloc.so.2", | ||
| "/usr/lib64/libjemalloc.so.2", |
There was a problem hiding this comment.
Agreed, the path list was unnecessary. Removed in 73309e1: jemalloc is now found by soname with ctypes.util.find_library("jemalloc") and LD_PRELOAD=libjemalloc.so.2 is resolved by ld.so like any other library (checked in the ATOM nightly image: it maps /usr/lib/x86_64-linux-gnu/libjemalloc.so.2).
|
ci triage for 66ea35f:
|
|
GPU re-validation on this head (
Result: pass. |
…orker loaded
Drop the list of distro paths: LD_PRELOAD resolves a soname like any other
library, so ctypes.util.find_library("jemalloc") is enough. ld.so only warns
when a preload fails, so each front-end worker now logs the allocator it
actually mapped. Add a test that the workers are started inside the
LD_PRELOAD window.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With
--api-server-count> 1 every front-end worker renders and tokenizes longprompts on many threads (the default executor and the tokenizers' rayon pool).
glibc malloc gives each thread its own arena and keeps freed memory there, so a
worker's RSS keeps growing over a long run. jemalloc hands freed pages back to the
OS and leaves the thread count, and so the tokenizer parallelism, unchanged.
_start_frontend_workersnow setsLD_PRELOADtolibjemalloc.so.2only while itspawns the workers (an existing
LD_PRELOADis kept behind it) and restores theenvironment right after. The API process and the engine processes, started before,
keep their allocator. jemalloc is looked up by soname (
ctypes.util.find_library),the same way the dynamic linker resolves
LD_PRELOAD, so no distro paths arelisted. When the host has no jemalloc the workers fall back to glibc malloc with
one warning; the server starts as before. Since ld.so only warns when a preload
fails, each worker logs the allocator it actually mapped (from
/proc/self/maps).No new options or environment variables.
--api-server-count 1is unchanged.Tests
tests/entrypoints/test_api_server_helpers.py(preload set only whilespawning, an existing preload kept and restored, an existing jemalloc preload
left alone, glibc fallback with a warning, restore on a failed spawn, the
workers'
start()runs with jemalloc inLD_PRELOAD, the mapped allocator isread from the process maps).
find_library("jemalloc")returnslibjemalloc.so.2and
LD_PRELOAD=libjemalloc.so.2maps/usr/lib/x86_64-linux-gnu/libjemalloc.so.2.DeepSeek-V4.1-Flash DEP8,
--api-server-count 4): the 4 front-end workers mapjemalloc and no other process does; GSM8K not below main; under a 60 min
synthetic load the workers' RSS stops growing after about 20 min and settles
about 15% below main's.
Performance
DeepSeek-V4.1-Flash DEP8, 8x MI355X, InferenceX AgentX c512,
--api-server-count 4, 3600 s. Measured with the same change on an earlier main plus local patches; not re-measured on this head. jemalloc: 1 run; glibc: 2 runs on a different machine.Alternatives tried on the same setup: capping glibc at 4 arenas plus a 16-thread rayon pool kept memory flat but cost 1.4% throughput and +15% TTFT p50; 4 arenas alone cost 9.0%. Runs longer than 1 h are not done yet.
🤖 Generated with Claude Code