mirror of
https://github.com/mw00/project-maya.git
synced 2026-12-03 21:08:26 +07:00
[PR #588] [CLOSED] DeepSeek: Windows drops the copied source pages and bounds the in-place experts' working set #611
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#611
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/588
Author: @handmade0octopus
Created: 10/28/2026
Status: ❌ Closed
Base:
main← Head:pr/windows-inplace-ws-trim📝 Commits (2)
0e62c78IQ1_M: MSVC keeps ggml's delta rounding (35 of 11,220 subnormal rows differed without it)30ac28aDeepSeek: Windows drops the experts' source pages it has copied and bounds the in-place ones' working set📊 Changes
7 files changed (+337 additions, -24 deletions)
View changed files
📝
CMakeLists.txt(+8 -1)📝
docs/SETTINGS.md(+19 -5)📝
src/ds4/ds4_model.cu(+105 -3)📝
src/ds4/ds4_os.hpp(+94 -8)📝
src/kernels/cpu/iq_avx2.cpp(+9 -1)📝
tests/ds4_copy_cache.cpp(+6 -6)➕
tests/ds4_copy_cache_windows_test.cpp(+96 -0)📄 Description
The bug
On Windows, a long DeepSeek request on a warm-capped pack (some CPU-lane experts copied into RAM, the rest read in
place from the GGUFs) drains the machine's free memory until nothing is left. Measured on one box (one GPU, 128 GB
RAM, Maya-S IQ2_XXS with an 82 GB warm cap, fresh 32,768-token prompt + a 2,048-token decode, a 1 Hz client-side
guard at 6,144 MiB of available RAM):
(run cancelled mid-decode) - the drain is prompt-dependent, so a cap validated once is not safe;
grew +0.5 GB and the system cache shrank 20 GB (the OS reclaiming under pressure): file-backed pages of the
in-place experts faulting into this process's working set and never leaving it;
are flat (22-36 GiB free throughout), 6,177 uncopied experts left 6.0 GiB.
Linux never sees this: the same pages sit in the page cache, which counts as available. On Windows a mapped file
page resident in a working set counts as in use until demoted, and nothing demoted it:
os::advise(fd, off, n, /*need=*/false)- the release hint at every copy/promotion/swap site - was a no-op onWindows;
os::pread_direct/open_directare Windows stubs, so the unbuffered hybrid inIoQueuenever engages and everyruntime expert read is buffered (that pool self-trims, so it is the secondary consumer);
PrefetchVirtualMemorydeliberately fault the experts in.The fix (Windows-scoped; Linux code paths unchanged)
os::unlock_range(p, n): demotes a mapped range's whole interior pages from the process working set to thestandby list with
VirtualUnlock(the working-set documentation: unlocked pages are removed even though thecall reports
ERROR_NOT_LOCKED). A clean file-backed page stays resident and soft-faults back unchanged - itonly counts as available again. Interior pages only: an edge page may hold a neighbour's bytes.
os::advise(!need)is real on Windows now:map_rokeeps an fd→view registry,advisedemotes through it.This makes the ten existing release sites (expert copies, VRAM promotions, RAM swaps) effective there.
release_copied_cachedrops its Windows no-op: after an expert's bytes are copied, its whole interior sourcepages are demoted the same way (81-95 GB of double-held pages per load on the machine above).
(
lane_take/lane_take_winCPU-lane keep-lists,ahead_ask's prefetches) into a bounded ring,reference-counted per range - a range is demoted only when its oldest note's count reaches zero, i.e. no use
since that note, so hot experts are never churned. A trimmer thread keeps the process working set under the
load's own size plus
MAYA_DS4_INPLACE_TRIM_GB(default 6 GB on Windows, 0 elsewhere;MAYA_DS4_INPLACE_TRIM_MS, default 250). An un-counted first build demoted hot pages through their stale notesand cost 13% decode; the counted one costs none.
Results on the machine above (fresh prompts, 6,144 MiB floor, visible servers, live telemetry)
Packs whose experts are all copied and pinned (IQ1_M in production) are unaffected by construction: the ring stays
empty and the trimmer thread no-ops.
Tests
ds4_copy_cache_windows_test(Windows CTest): copied source pages leave the working set with byte-identicalre-fault;
unlock_range/adviseinterior-only semantics; edge pages retained; sub-page, null, bad-fd andoverflow ranges rejected;
working_set_bytessane; an independent expert copy stays intact;native_rows_exact_testpasses (its Windows arm needs the MSVC IQ1_M rounding fix in the first commit: withoutit 35 of 11,220 subnormal cases differ from ggml-cpu);
after re-fault.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.