Repository navigation
fix(runtime): share large freed blocks across host lanes - #1869
Merged
Lorenzobattistela merged 2 commits intoOct 26, 2026
Merged
Conversation
The heap comment again says a host chain is handed off at KEEP_WORDS and that CAP_WORDS >= KEEP_WORDS, which keeps a large handoff to one block. The small-class check fails cleanly instead of writing past its four blocks. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Lorenzobattistela
approved these changes
Oct 26, 2026
nuxyel
added a commit
to nuxyel/BendTorch
that referenced
this pull request
Oct 29, 2026
luiscleto
added a commit
to luiscleto/framebender
that referenced
this pull request
Nov 10, 2026
…published with their READMEs Bend 2.0.40 hands large freed blocks to the shared pool itself (bendlang/bend#1869), so build.sh no longer patches the generated runtime; it stops on a Bend older than 2.0.40 instead. Same output on every suite (same, threads, par, out, index), same peak memory, same or slightly better time (docs/BENCHMARK.md, "Bend 2.0.40"). Imports move to lawful-words, -arrays and -halves 0.1.0.1 and lawful-bytes and -fields 0.1.1.1 (the same code, now published with their READMEs). The gate passes on 2.0.40; test/bcheck.sh's cap goes from 4 to 6 GB, as the --verdict of PROOF.bend now peaks near 3.8 GB. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Fixes #1856.
Each host lane currently keeps its last freed large block in COLD. Other lanes cannot reuse that block until the lane frees another block of the same class. Large temporary arrays can therefore increase peak memory with the worker count.
Send host blocks of at least
CAP_WORDS(256 KiB) directly to the shared bank inheap_hand. Smaller blocks keep the existing HOT/COLD policy. The decision stays in the generation handoff, with no new branch in the inlineheap_freepath. Device frees still usedev_cut.The cutoff uses
CAP_WORDSbecause GPU mode setsKEEP_WORDSto 256 words. A normal Bend host loop that fills and drops 2 KiB arrays showed heavy lock contention when those blocks also went directly to the bank. With the fixed cutoff, its paired median time ratios are 1.016 at one thread and 0.930 at 16 threads.The regression checks immediate reuse by another lane at 256 KiB and 1 MiB, no heap growth during reuse, live payload integrity, and smaller cached generations in both CPU and GPU modes. It fails on main. It also rejects the lower GPU cutoff.
A local Bend workload produces 32 arrays of 524,288 U32 cells on one lane, reads their endpoints on parallel lanes, and repeats this for 12 rounds. All runs return
2726963360. Medians of three runs on an Apple M5 Max:At 16 threads, this workload uses about 31% less peak RSS. Large-block retention in lane caches is zero in all final runs.
Validation against
dd7d74dbwith Bun 1.3.14 and Apple clang 21:BEND_POISON. Bun and interpreted IO also pass.bend.ts,safe.ts, and documentation tools.The cluster test/performance gates, CUDA, and BendTorch training were not run locally.