Repository navigation
GLM loader: the cached-page drop covers only what free memory lacks, and skips shards with none cached - #640
Merged
Conversation
…and skips shards with none ashhart#600 dropped every cached page of the checkpoint before each load, and msync walked every shard: about 2.5 s with nothing cached, and a later load lost the pages it could have read. page_cache.dropForLoad now drops only when free memory can't hold the load plus the paced reads' floor, shard by shard until the shortfall is covered, and invalidates no shard whose mincore count is zero. paced_read's floor and freeBytes are public for it.
BobClawblaw
force-pushed
the
glm-drop-only-deficit
branch
from
October 11, 2026 01:26
5254014 to
ac47e1c
Compare
Owner
|
Thank you, @BobClawblaw. This is in 1.0.6 (
All six prose replies were identical in all 12 arms. Wired memory peaked at 98-100 GiB a Mac in both builds. Free pages went lower with your change (the cache it keeps is clean and the kernel reclaims it), and no load stalled. |
jschmied
pushed a commit
to jschmied/TensorFold
that referenced
this pull request
Oct 11, 2026
…free memory lacks, and skips shards with none cached Thanks @BobClawblaw.
jschmied
pushed a commit
to jschmied/TensorFold
that referenced
this pull request
Oct 11, 2026
jschmied
pushed a commit
to jschmied/TensorFold
that referenced
this pull request
Oct 11, 2026
BlivionIaG
pushed a commit
to BlivionIaG/TensorFold
that referenced
this pull request
Oct 20, 2026
…free memory lacks, and skips shards with none cached Thanks @BobClawblaw.
BlivionIaG
pushed a commit
to BlivionIaG/TensorFold
that referenced
this pull request
Oct 20, 2026
BlivionIaG
pushed a commit
to BlivionIaG/TensorFold
that referenced
this pull request
Oct 20, 2026
BlivionIaG
pushed a commit
to BlivionIaG/TensorFold
that referenced
this pull request
Oct 20, 2026
The author rebased ashhart#640 onto main after our merge; this keeps the PR's current head in the history with no change to the tree.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #600, the two costs you measured there.
What changes
page_cache.dropForLoad(gpa, dir, load_bytes): the drop runs only when free memory (vm.page_free_count) can't hold the load (plan_bytes + e.arena.bytes) plus the paced reads' floor (3% of RAM, at least 8 GB). Then it drops shard by shard, in the index's order, until the shortfall is covered, and stops. The rest of the checkpoint stays cached for the reads.mincorecount is zero is not invalidated (msyncwalks every page of the mapping either way).paced_read.floorandfreeBytesare public so the drop uses the same floor the reads wait on.dropped 75.9 GiB of the checkpoint from the file cache, the 74.3 GiB free memory lacked for the load (1.46 s). Nothing is logged when nothing is dropped.Measured
One M5 Ultra (256 GB),
GLM_LAYERS=23(93 GB, about one Mac's half of the pair),--context 131072 --parallel 1, main 56150e6 against this branch, two rounds each. Ready is from process start to/v1/modelsanswering; the cached amounts aremincoreover the shards before and after.Every load's reply to the same prompt was identical to main's. Free memory never went under the 8 GB floor; a memory watchdog (kill under 6 GiB free) never fired. One Mac's loads leave nothing cached by themselves (F_NOCACHE reads), so "after a load" on one Mac only differs from cold when an earlier drop kept pages, as above.
Not measured here: the pair. Its two halves read different shards, so which shards the drop takes first matters more there than on one Mac; the index's order is what this uses.
Checks
zig build testpasses;page_cache's test now covers a drop of nothing wanted (no shard touched, the pages stay cached), a full drop (dropped equals cached), and a second pass over nothing cached (counted, not invalidated).zig fmt --check zig/srcclean; engine.zig stays at 587 lines.