mirror of
https://github.com/mw00/project-maya.git
synced 2026-12-03 21:08:26 +07:00
[PR #434] [CLOSED] ds4: drop the experts' pages as they are copied, and set the load's threads and file order #524
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#524
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?
📋 Pull Request Information
Original PR: https://github.com/mw00/project-maya/pull/434
Author: @Ross-Yang-94
Created: 10/23/2026
Status: ❌ Closed
Base:
main← Head:ds4-load-experts📝 Commits (1)
d29b6c5ds4: drop the experts' pages as they are copied, and set the load's threads and file order📊 Changes
3 files changed (+120 additions, -2 deletions)
View changed files
📝
README.md(+16 -0)📝
docs/SETTINGS.md(+56 -0)📝
src/ds4/ds4_model.cu(+48 -2)📄 Description
What
Three changes to the expert load at start (
load_expertsandcopy_expertsinsrc/ds4/ds4_model.cu):posix_fadvise(DONTNEED)on each region when its copy is done, so that second copy does not accumulate. In place - where the CPU lane's experts are the file cache - only the VRAM experts' pages are dropped, as they already were.MAYA_DS4_LOAD_THREADS(default 12): the threads that read the experts' regions (an EXL3 or any other region pack; a GGUF pack's copies keep their own count).MAYA_DS4_LOAD_INTERLEAVE(default off): the files round-robin - the first expert of each file, then the second, ... - so the threads read several files at once (a pack split over two drives streams both).The two settings default to today's behaviour. The drop is on by default (
MAYA_DS4_LOAD_DROP_CACHE=0turns it off): the pack it saves pays minutes, the pack it slows pays seconds - the numbers are below, including the cost. The code readsSTRATA_DS4_LOAD_*(the alias mapsMAYA_*to it), as the other DS4 settings do.Why
The two copies. A 223 GB pack read into RAM is 223 GB of page cache as well, on a machine with 251 GB. Past the first ~77 GB every new page is then allocated by reclaiming inside the thread that copies: measured 0.79-0.91 GB/s, 124-140 GB of page cache, memory PSI full at 69.7%,
pgsteal_directgrowing at the very rate of the copy. Dropping each region once its copy is done takes the same load to 5.6-6.0 GB/s and the page cache to 4 MB.The order. The pack's files are read one after another, so a single file's regions are read in sequence. Interleaving reads several files at once, and more threads help on a machine with the cores.
Measurements
RTX 6000D 85 GB (PCIe 5.0 x16), Threadripper PRO 9965WX (24C/48T), 251 GB RAM, two NVMe drives; DeepSeek-V4.1-Flash, 512K context, v1.1.25 + this patch. Cold: the container stopped,
echo 3 > /proc/sys/vm/drop_caches, then started. The times are the engine's ownds4: loaded inline.UD-Q4_K_XL, GGUF, 11 files over two drives (65 GB of experts into VRAM, 223 GB copied into RAM):
/health200/health200, two loadsEXL3 2.9bpw, 203 GB (14.7k experts into 146.7 GB of RAM,
--mmap-experts off), two loads each:The middle line is what the drop costs. It is 4 s walking 203 GB of pages (about 20 us a MB), and on this pack the reclaim it saves costs less than that: the RAM tier is 147 GB, so the cache still has ~100 GB to live in and the kernel's reclaim stays mild. On the GGUF pack - 223 GB tied up in copies on a 251 GB machine - the same 4 s of walking saves five minutes. Hence on by default, with
MAYA_DS4_LOAD_DROP_CACHE=0where the drop costs more than it saves.What takes 203 GB down to 27 s is the order and the threads (the third line, all three together; I did not measure the order and threads without the drop).
When the 2 MB blocks run out
Fixing the page cache is not the end of it on this machine: the load still fell from 5.6-6.0 GB/s to 77 MB/s at 190 GB of the 223. That is not the disk and not the engine - it is the RAM tier's huge pages running out. The tier is mapped
MADV_HUGEPAGE, so the kernel backs it with 2 MB blocks; past ~190 GB there is no free order-9 block left to give (/proc/buddyinfo: none on either node;AnonPages214 GB withAnonHugePages178 GB of it - the tail of the tier is already 4 KB pages). Every further 2 MB fault then runs the direct compaction path in the faulting thread, synchronously, and when compaction cannot succeed it retries instead of giving up: 77 MB/s,compact_stall108 a second,compact_success0.kcompactdcannot get ahead either, because each new fault takes the free blocks it just made.echo defer > /sys/kernel/mm/transparent_hugepage/defragchanges what a fault does when it cannot have a huge page: it takes 4 KB at once and leaveskcompactdto refill in the background. On the same load that is 77 MB/s -> 760 MB/s,compact_stallback to zero, and the load finishes. (alwaysandmadvise, the usual settings, both compact in the fault.) Atmpfiles.dline keeps it across reboots:This is the machine's setting, not the engine's, so there is no code for it in this PR;
docs/SETTINGS.mdcarries it as an ops note. It is here because the symptom reads as a slow disk - that is how I chased it first - and because anyone loading a pack of this size on a machine of this size will hit it.Relation to #421
#421 proposes the same fix in the same place for the GGUF copy path (
DS4_COPY_DROP_CACHE, opt-in, partial boundary pages kept). This PR'scopy_expertshunk is that one-liner with the whole region dropped and the default on. The rest of this PR is not in #421: theload_expertspath (an EXL3 or any other region pack - the 203 GB case below, which #421 does not touch), and the two load settings. If #421 lands first I will drop thecopy_expertshunk here; the diff is small enough either way.Docs
A section in
docs/SETTINGS.md(the three settings, the page drop and its cost, both packs' numbers, the huge-page note) and a short one in the README's tuning part.Note
The two settings are a local patch I have carried since v1.1.21; the page drop came out of chasing a load that sat at 0.8 GB/s. Decode and prefill are untouched - these changes only affect how the load reads. Happy to reshape.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.