mirror of
https://github.com/mw00/project-maya.git
synced 2026-12-03 21:08:26 +07:00
[GH-ISSUE #507] [BUG] [DS4] Load-time OOM kill on one NUMA node with DS4_ENGRAM_RAM=1 + --mmap-experts off #210
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
mw00/project-maya#210
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @zhangxiaoxing on GitHub (Oct 26, 2026).
Original GitHub issue: https://github.com/mw00/project-maya/issues/507
Load-time OOM kill on one NUMA node with
DS4_ENGRAM_RAM=1+--mmap-experts offSummary
On a 2-socket / 512 GB host, Maya v1.1.28 is reliably SIGKILLed by the kernel during load on node 0, while the machine still has ~195 GiB of
MemAvailableand global memory PSI is 0.00. The kill is a node-localCONSTRAINT_MEMORY_POLICYOOM, not a machine-wide OOM:DS4_ENGRAM_RAM=1maps andmlock()s the two complete Engram tables — 202.758 GB decimal (189 GiB). On the failing starts essentially all of it was resident on node 0 (Node 0 ... mlocked:201740944kB).--mmap-experts offthen puts all 6,771 CPU-lane experts (106.3 GB) into anonymous host memory.place_experts()allocates each layer's host block separately per NUMA node withnode_map()→anon_alloc()→mbind(MPOL_BIND, {node X}). There is no check of node-local free memory on this path.MPOL_BINDforbids falling back to node 1, so the kernel kills the process instead of spilling.place_experts()has no RAM budget at all on this path. For GGUF/MXFP4 packs the analogouscopy_experts()path has a machine-global budget (ram_room()/kRamMargin) with per-nodeMPOL_BINDplacement — the same class of bug.This is not a v1.1.28 regression. The same unguarded
node_map(bytes, X, NH)host allocation exists in v1.1.24–v1.1.27; it is atds4_model.cu:4977in v1.1.27 andds4_model.cu:5185in v1.1.28.Environment
6afa525, local HTTPS patch on top;VERSION 1.1.28, build stampcf28053a13c8876d)ds4_model.cu:4977)--tp 2,--layer-split auto6.8.0-136-generictrellis/suh/svhtensors; not GGUF/MXFP4)/DPC_HOME/...), 460.9 GB--pack … --max-context 262144 --tp 2 --mmap-experts off --dspark noneDS4_ENGRAM_RAM=1ulimit -l unlimitedThe engine is started directly by
capture-engine.sh(no server), with the same args/env as the service. The service path (run-captured.sh) shows the same failure, but the server reports onlyexit code 1.Steps to reproduce
On a 2-socket host with two NUMA nodes, start with the config above (
DS4_ENGRAM_RAM=1,--mmap-experts off,--tp 2).Ensure the Engram tables are already in page cache on one socket (this happens naturally after a previous start/kill; a cold cache with
numactl --interleave=allmay avoid it).Run the engine directly and record memory/PSI:
Observe: exit status
137, the engine's stderr ends atEngram RAM ONLY, globalMemAvailableis still very high, and the kernel log has a node-local OOM record.Local captures used for this report (to attach):
.stage/engine-capture-20261026-101643/and.stage/engine-capture-20261026-104645/.20261026-10164310:18:14 used=315708MB avail=199731MB full avg10=0.0020261026-10464510:48:21 used=322382MB avail=193057MB full avg10=1.26The two engine stderr files are byte-identical (31 lines each): 30
Engram RAM file … lockedprogress lines followed by the finalEngram RAM ONLYline, then nothing.Expected behavior
MemAvailableof ~195 GiB with 0.00 global PSI should not coexist with a fatal OOM.Actual behavior
Kernel OOM record (trimmed from
/var/log/kern.log)all_unreclaimable? yes.nodemask=0+CONSTRAINT_MEMORY_POLICYmeans the faulting allocation was bound to node 0 and could not use node 1's free memory.memory.log: global memory was not exhaustedFrom
.stage/engine-capture-20261026-101643/memory.log:At the kill,
MemAvailablewas 199,731 MB = 195.0 GiB, and global PSIfull avg10was 0.00. From the post-lock sample to the last sample, machine-wideusedrose by ~46 GB — the copy is 106.3 GB in total — while 195 GiB still appeared available.engine.err: the last line is the Engram lockNo CUDA placement lines, no "experts VRAM leaves over" line, no error message. The next thing the process sees is SIGKILL.
signals.log: SIGKILL on the main PID and its threadsThe main PID matches the
pid=1707741in the kernel OOM record. The second capture's main PID is 1745546, matching the other record.Service/TUI
serve/server.py:561raises this when the engine dies beforeREADY. The engine's real termination (SIGKILL; 137 in shell notation, -9 fromPopen.wait()) is lost; the user sees the server's exit code 1.Root cause
1. The Engram tables are locked on one socket
DS4_ENGRAM_RAM=1callsEgReader::pin_range()(src/ds4/ds4_engram_io.hpp:140), whichmmap()s each table andmlock()s it in 256 MB chunks (:164). The two tables total 202.758 GB decimal / 188.8 GiB. On the failing starts they were essentially all on node 0:file-rss:198224000kB= 189.0 GiB (the locked tables);Node 0 ... mlocked:201740944kB= 192.4 GiB;mlock()does not migrate pages; it locks them where the page cache already has them.docs/SETTINGS.md:508-510warns about exactly this:2.
--mmap-experts offallocates host experts per node, with no RAM budgetFor a non-GGUF pack,
file_expertsis false when--mmap-experts off(ds4_model.cu:2566-2582), andNH = min(2, cores.size()) = 2(:3216). Every layer then does:node_map()(:212) isos::anon_alloc()(src/ds4/ds4_os.hpp:363):There is no
ram_avail()/ram_room()/ per-node free-memory check inplace_experts()on Linux before this allocation. The only failure test ismmap() == nullptr, which does not fire under Linux overcommit. Thembind()return value is also ignored.The total host copy is 106.3 GB (6,771 experts), split into two parts: ~53.15 GB per node / ~49.5 GiB per node. Node 0 has ~59 GiB after the Engram lock, so only ~8–10 GiB remains for page cache, kernel, and other tenants. The load's page cache alone can exceed that.
3. First touch happens during the expert copy
load_experts()(:5734) reads each expert and, for a non-VRAM expert, callsrepack_part()(:5831) into the pre-allocated node-X block.repack_part()(:2416) doesmemcpy()into that block. That is the first touch of the anonymous pages — and the kernel trace'srep movsbfault path.When node 0 reaches its min watermark, the allocation is still
MPOL_BIND-ed to node 0. The kernel cannot fall back to node 1, so it invokes the OOM killer for the allocating task:CONSTRAINT_MEMORY_POLICY, nodemask=0.4. Why global RAM checks did not catch it
ram_room()(:1212) isMemAvailableminushelper_pending;kRamMarginis 8 GiB (:1119). This is machine-global. The budget incopy_experts()(:5432) is:But for a non-GGUF pack,
copy_experts()is never called. The only call site is insideload_experts_mx()(:5334), which is entered only whenL[0].lay.fmt == kFmtMXFP4(:5735). The reported pack is EXL3, so the fatal path isplace_experts()→load_experts(), which has no budget at all.For
NH=2, the correct budget is per node: a copy can fit globally but not on node 0. A globalcantherefore both over-selects experts and suppresses the "do not all fit" warning in exactly the case that fails. On the deployment side, the local preflight's only RAM gate is globalfree -g>= 300 GB (it passed at ~470 GB available at start), so it cannot catch a single-node shortfall either.For a GGUF/MXFP4 pack,
copy_experts()has the analogous bug: its budget is machine-global, whilenode_map()binds each half to a node. On a 2-socket host with one node already full, the sameCONSTRAINT_MEMORY_POLICYkill follows.DS4_COPY_NUMA=1works around that path by settingNH=1, which makesanon_alloc()skip thembind()(:5457-5460). It does not affectplace_experts(), so it is a no-op for the non-GGUF path in this report.5. The missing "experts VRAM leaves over" line is expected
That line is printed only inside
if (file_experts)(:3180-3206). With--mmap-experts offon a non-GGUF pack,file_expertsis false, so the line is not expected. Its absence is not evidence of an unknown allocation site; the site isplace_experts()+load_experts().Why restarting does not help
After a SIGKILL, the kernel unlocks the mlocked file pages, but they stay in the page cache on the socket where they were. The next start's
mlock()re-locks them in place rather than migrating them. The engine itself does not drop the page cache beforemlock(), so node 0 stays full and every retry dies at the same point. This is the "ratchet" described indocs/SETTINGS.md:508-510.A separate
DS4_COPY_NUMA=1attempt confirms this:numa-watchrecorded node 0 falling from 232 GiB to 2 GiB while node 1 stayed at ~186 GiB, thenENGINE GONE:That run had
DS4_COPY_NUMA=1in the config, which is consistent with the variable being ignored on this pack.Workarounds
For this host (verified)
Rebalance node 0 before starting, then start under an interleave policy:
Keep
DS4_COPY_NUMA=2(or leave it unset). This made the load succeed here. The successful start reports:The per-node
Mlockedis now balanced (~72 GiB on each node), instead of ~192 GiB on node 0.Note:
numactl --interleave=allalone does not move pages already cached on node 0; thedrop_cachesstep is required. The interleave policy fixes the Engram/page-cache placement, but the expert blocks themselves are stillMPOL_BIND-ed bymbind(), so it does not override the per-node bind.@ChicoPinto70 commented on GitHub (Oct 26, 2026):
Wow!!! I had the same problem!!! I had a OOM every time I disabled the mmap in my Dual Xeon E5-2699v3. But with the drop_cache solution, now, I can disable it and the TG improved from around 40 tok/s to 43 tok/s.
THANK YOU, @zhangxiaoxing !!!!!
@mw00 commented on GitHub (Oct 27, 2026):
Thank you for the very clear analysis. You were right: the CPU lane's RAM copies were bound to their node with MPOL_BIND, so a node full of locked Engram tables meant an OOM kill even with half the machine free. In v1.1.34 the copies prefer their node instead of requiring it: they land there while it has room, and the rest goes to the other node rather than the process being killed. Placement is unchanged when both nodes have room. Your
drop_caches+numactl --interleave=allworkaround still helps keep the Engram tables balanced across the sockets, which is faster.Closing - please reopen if v1.1.34 still stops at load.
Released in v1.1.34: https://github.com/mw00/project-maya/releases/tag/v1.1.34