[PR #434] [CLOSED] ds4: drop the experts' pages as they are copied, and set the load's threads and file order #524

Closed
opened 2026-10-29 21:26:24 +07:00 by bsakaguchi · 0 comments
Owner

📋 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)

  • d29b6c5 ds4: 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_experts and copy_experts in src/ds4/ds4_model.cu):

  • The read pages are dropped once the bytes are copied. A buffered read leaves the expert's bytes in the file cache as well as in VRAM or RAM. The load now calls 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=0 turns it off): the pack it saves pays minutes, the pack it slows pays seconds - the numbers are below, including the cost. The code reads STRATA_DS4_LOAD_* (the alias maps MAYA_* 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_direct growing 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 own ds4: loaded in line.

UD-Q4_K_XL, GGUF, 11 files over two drives (65 GB of experts into VRAM, 223 GB copied into RAM):

  • before: 0.79-0.91 GB/s, page cache 124-140 GB, ~6 min to /health 200
  • after: 5.6-6.0 GB/s, page cache 4 MB, 56.7-58.6 s to /health 200, two loads

EXL3 2.9bpw, 203 GB (14.7k experts into 146.7 GB of RAM, --mmap-experts off), two loads each:

  • 12 threads, file by file, no pages dropped (today): 41.4 and 42.1 s, 6.4 GB/s, page cache 140-143 GB
  • pages dropped, 12 threads, file by file: 45.2 and 48.5 s, 5.2-5.6 GB/s, page cache 11 GB
  • pages dropped, 24 threads, interleaved: 27.1 and 27.0 s, 11.4 GB/s, page cache 12 GB

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=0 where 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; AnonPages 214 GB with AnonHugePages 178 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_stall 108 a second, compact_success 0. kcompactd cannot get ahead either, because each new fault takes the free blocks it just made.

echo defer > /sys/kernel/mm/transparent_hugepage/defrag changes what a fault does when it cannot have a huge page: it takes 4 KB at once and leaves kcompactd to refill in the background. On the same load that is 77 MB/s -> 760 MB/s, compact_stall back to zero, and the load finishes. (always and madvise, the usual settings, both compact in the fault.) A tmpfiles.d line keeps it across reboots:

w /sys/kernel/mm/transparent_hugepage/defrag - - - - defer

This is the machine's setting, not the engine's, so there is no code for it in this PR; docs/SETTINGS.md carries 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's copy_experts hunk is that one-liner with the whole region dropped and the default on. The rest of this PR is not in #421: the load_experts path (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 the copy_experts hunk 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.

## 📋 Pull Request Information **Original PR:** https://github.com/mw00/project-maya/pull/434 **Author:** [@Ross-Yang-94](https://github.com/Ross-Yang-94) **Created:** 10/23/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `ds4-load-experts` --- ### 📝 Commits (1) - [`d29b6c5`](https://github.com/mw00/project-maya/commit/d29b6c5812607beb543d130d51683a3ee207bd7f) ds4: 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) <details> <summary>View changed files</summary> 📝 `README.md` (+16 -0) 📝 `docs/SETTINGS.md` (+56 -0) 📝 `src/ds4/ds4_model.cu` (+48 -2) </details> ### 📄 Description ### What Three changes to the expert load at start (`load_experts` and `copy_experts` in `src/ds4/ds4_model.cu`): - **The read pages are dropped once the bytes are copied.** A buffered read leaves the expert's bytes in the file cache as well as in VRAM or RAM. The load now calls `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=0` turns it off): the pack it saves pays minutes, the pack it slows pays seconds - the numbers are below, including the cost. The code reads `STRATA_DS4_LOAD_*` (the alias maps `MAYA_*` 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_direct` growing 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 own `ds4: loaded in` line. **UD-Q4_K_XL, GGUF, 11 files over two drives** (65 GB of experts into VRAM, 223 GB copied into RAM): - before: 0.79-0.91 GB/s, page cache 124-140 GB, ~6 min to `/health` 200 - after: 5.6-6.0 GB/s, page cache 4 MB, **56.7-58.6 s** to `/health` 200, two loads **EXL3 2.9bpw, 203 GB** (14.7k experts into 146.7 GB of RAM, `--mmap-experts off`), two loads each: - 12 threads, file by file, no pages dropped (today): **41.4 and 42.1 s**, 6.4 GB/s, page cache 140-143 GB - pages dropped, 12 threads, file by file: **45.2 and 48.5 s**, 5.2-5.6 GB/s, page cache 11 GB - pages dropped, 24 threads, interleaved: **27.1 and 27.0 s**, 11.4 GB/s, page cache 12 GB 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=0` where 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; `AnonPages` 214 GB with `AnonHugePages` 178 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_stall` 108 a second, `compact_success` 0. `kcompactd` cannot get ahead either, because each new fault takes the free blocks it just made. `echo defer > /sys/kernel/mm/transparent_hugepage/defrag` changes what a fault does when it cannot have a huge page: it takes 4 KB at once and leaves `kcompactd` to refill in the background. On the same load that is 77 MB/s -> 760 MB/s, `compact_stall` back to zero, and the load finishes. (`always` and `madvise`, the usual settings, both compact in the fault.) A `tmpfiles.d` line keeps it across reboots: w /sys/kernel/mm/transparent_hugepage/defrag - - - - defer This is the machine's setting, not the engine's, so there is no code for it in this PR; `docs/SETTINGS.md` carries 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's `copy_experts` hunk is that one-liner with the whole region dropped and the default on. The rest of this PR is not in #421: the `load_experts` path (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 the `copy_experts` hunk 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:26:24 +07:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mw00/project-maya#524
No description provided.