Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c85646f
lfm3 metal: opt in to exact warm turns
ashhart Nov 22, 2026
4a9068f
changelog: #4585 under Unreleased
ashhart Nov 23, 2026
b115771
qwen27 dflash: read and run the 9B's DFlash drafter beside DFlash2
grantoverton Nov 1, 2026
b1454f3
qwen27 served: the serving line names a v1 drafter "DFlash", DFlash2 …
grantoverton Nov 1, 2026
4a03875
qwen27 prompt memory: the planner counts a drafter's own tap planes a…
grantoverton Nov 1, 2026
891467e
qwen27 dflash v1: the ring keeps fused rows, and the full layer sees …
grantoverton Nov 1, 2026
c6d0eea
qwen27 served: the startup line names a v1 drafter "DFlash" too
grantoverton Nov 1, 2026
7dd0f0e
qwen27 lanes: the gathered taps' stride check reads the taps' source,…
ashhart Nov 22, 2026
8243dda
qwen27 dflash v1: the full layers' attention takes main's Shape, whic…
ashhart Nov 22, 2026
713f7a8
qwen27 dflash: retain main behavior beside the v1 drafter
ashhart Nov 23, 2026
a7d35ea
qwen27: grow a slot's K/V as its stream grows (opt-in TF_Q27_KV_GROW)
grantoverton Nov 1, 2026
4229e50
qwen27: free slots give back grown K/V; drafter taps rings grow as used
grantoverton Nov 1, 2026
93cb60f
qwen27: a fresh pass takes its prompt's K/V rows at once (TF_Q27_KV_G…
grantoverton Nov 2, 2026
9e87183
qwen27: adapt K/V growth and DFlash to current main
ashhart Nov 22, 2026
147e803
qwen27 served: format prompt fit setup
ashhart Nov 23, 2026
87fc023
qwen27 served: keep opt-in K/V setup within 600 lines
ashhart Nov 23, 2026
6e43faf
qwen27 served: extract helpers for formatted setup
ashhart Nov 23, 2026
473c0c7
changelog: #1896 under Unreleased
ashhart Nov 23, 2026
c559913
GLM on CUDA: a kept state's disk image on one rank, its parts and whe…
wojo Oct 25, 2026
ad74d2c
GLM on CUDA: --learn-conversations keeps every rank's part of a kept …
wojo Oct 26, 2026
6280c46
rows: a pool that reuses spare storage without trimming it reads a di…
wojo Oct 26, 2026
7713637
rows: a pool that also trims reads a disk state only within its budge…
wojo Oct 27, 2026
8a55948
GLM on CUDA: a disk read's seal refuses ring bases that do not hold t…
wojo Oct 27, 2026
0ecfef3
rows: the grid test runs on both writers, the test's thread and the I…
wojo Oct 27, 2026
ee6530e
GLM on CUDA: --spill-gib and --checkpoint-slots are refused, as --lea…
wojo Oct 28, 2026
a8badce
GLM on CUDA: the disk image downloads through cuda.memory.download, t…
wojo Nov 7, 2026
fd5dcb3
GLM on CUDA: a disk image's words record the world, the layout and th…
wojo Nov 7, 2026
3d4cab0
GLM on CUDA: --learn-conversations opens its store through the shared…
wojo Nov 11, 2026
418e2aa
GLM on CUDA: a disk read sends each block's rows to the other ranks i…
wojo Nov 16, 2026
3ba7bc0
GLM on CUDA: native/cuda.zig names glm_cuda where it compares, keepin…
wojo Nov 16, 2026
4011c5c
glm cuda: the disk ranks test's fake link answers cuLaunchKernelEx to…
ashhart Nov 20, 2026
ddbaa32
changelog: #1411 under Unreleased
ashhart Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

## Unreleased

- GLM-5.3-Flash on CUDA: with `--learn-conversations`, conversation states are kept on disk through the rows store, so after an eviction or a restart the next turn reads its state back instead of prefilling the whole conversation; at TP>1 every rank's part goes to rank 0's disk, so a state is read back on every rank or none (#1411, fixes #1312). Thanks to @wojo.

- Qwen on Metal: with `TF_Q27_KV_GROW=<rows>` (a multiple of 16; 0 or unset is off) a serve's K/V slots start at that many rows, grow as their streams do and give the rows back when a stream ends, and drafter tap rings grow the same way; replies are byte-identical with it on or off (#1896). Thanks to @grantoverton.

- LFM3 on Metal: warm turns, so a tool loop whose re-rendered history changes mid-conversation re-prefills only from the first changed token, with outputs identical to a fresh run (#N).

- Server: `tensorfold capabilities --json` now lists `TENSORFOLD_PARALLEL` and the other environment variables `serve` honours, so the desktop app's Engine variables page accepts them (#N, fixes #3684).

- Tests: host tests record where capped prompt chunks cut while another stream is live, family by family (#N).
Expand Down
4 changes: 3 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,9 @@ store for each model and build. That store takes the place of `--learn`'s store
with the flag neither reads nor writes the prefix files a plain `--learn` server keeps, and they stay on disk until the
cap below needs their room. After a restart, a crash or an eviction from RAM, the next turn reads the latest state back
instead of reading the conversation again from its first token. Qwen3.8-27B, Nemotron, Flash Next and GLM-5.3-Flash on
one Mac, and Nemotron, the Qwen3.5 hybrids and Flash Next on CUDA, keep them; other engines refuse the flag at startup.
one Mac, and Nemotron, the Qwen3.5 hybrids, Flash Next and GLM-5.3-Flash on CUDA keep them; other engines refuse the
flag at startup. GLM-5.3-Flash on CUDA across ranks writes every rank's part to rank 0's disk, so a state is read back
on every rank or on none; it takes neither `--spill-gib` nor `--checkpoint-slots`.

The engine stages an owned copy between rounds, and an I/O thread writes and fsyncs it. Staging has a 1 GiB byte permit
and at most eight jobs. Qwen3.8-27B widens the permit to one whole state at its `--context`, with none of its rows on
Expand Down
1 change: 1 addition & 0 deletions docs/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Diagnostics quote and escape the supplied text so it cannot create another termi
| `TF_MINIMAX_WORLD` | MiniMax-M3.1-Flash on CUDA: a whole rank count, 2 at CUDA, set with `TF_MINIMAX_RANK`; unset with it gives one rank |
| `TF_PROMPT_ROWS` | Native serving: a multiple of 16 from 128 through 2048; unset keeps the chip/family default |
| `TF_ANE_COLUMNS` | Whole u32 count; zero disables the experimental share; default zero |
| `TF_LFM3_METAL_WARM_TURNS` | Exactly `0` or `1`; default off. Uses one-row LFM3 Metal prefill even with caching disabled. A prompt cache enables background warm turns. |
| `TF_METAL4` | Metal: exactly `0` or `1`; `1` sends a family's GPU work through Metal 4 (macOS 26 and later) where the family supports it: the same kernels in the same order, with Metal 4's command queue, allocators, argument tables and barriers, and bit-identical outputs; `0` keeps Metal 3. DeepSeek-V4.1 defaults to `1` where the Mac has Metal 4 (its device test rigs to `0`); Macs without it stay on Metal 3 |
| `TF_DSV41_ROUND_PROF` | DeepSeek-V4.1 on Metal: exactly `0` or `1`; `1` logs decode rounds' host milliseconds (first encode to last wait) and GPU milliseconds by rows, every 1,024 rounds; default 0 |
| `TF_METAL4_TIMELINE` | Metal 4: a whole round count, default 0; `n` puts a GPU timestamp at every stage (between barriers) of `n` rounds of each kind a family names, after 8 warm ones, and logs their time by kernel and the longest stages. DeepSeek-V4.1 names its decode rounds by rows. Stamps cost GPU time, so stamped rounds read a little long |
Expand Down
124 changes: 88 additions & 36 deletions zig/src/core/lane_host_warm_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ const Box = struct {
}
};

const FakeSnaps = struct {
fn bytes(_: *anyopaque, at: u32) u64 {
return 64 + 4 * @as(u64, at);
}
fn save(ptr: *anyopaque, owner: ?*anyopaque, at: u32) anyerror!prompt_cache.Saved {
const f: *lanes.fake.Fake = @ptrCast(@alignCast(ptr));
return f.save(@ptrCast(@alignCast(owner.?)), at);
}
fn restore(_: *anyopaque, _: ?*anyopaque, _: prompt_cache.Saved) anyerror!void {
return error.BackendRestores;
}
fn drop(ptr: *anyopaque, saved: prompt_cache.Saved) void {
const f: *lanes.fake.Fake = @ptrCast(@alignCast(ptr));
f.drop(saved);
}
};
const fake_snap_vtable: prompt_cache.Snapshots.VTable = .{ .bytes = FakeSnaps.bytes, .save = FakeSnaps.save, .restore = FakeSnaps.restore, .drop = FakeSnaps.drop };

/// Chunks the fake ran for prompt-only streams.
const WarmChunks = struct {
n: std.atomic.Value(usize) = .init(0),
Expand Down Expand Up @@ -190,23 +208,6 @@ test "a warm pass its cache keeps nothing of runs no chunk: no planned mark, and

test "a warm_usable store keeps a warm pass's grid mark but not its end off the grid; without it, the end too" {
const gpa = std.testing.allocator;
const pc = api.prompt_cache;
const Snaps = struct {
fn bytes(_: *anyopaque, at: u32) u64 {
return 64 + 4 * @as(u64, at);
}
fn save(ptr: *anyopaque, owner: ?*anyopaque, at: u32) anyerror!pc.Saved {
const f: *lanes.fake.Fake = @ptrCast(@alignCast(ptr));
return f.save(@ptrCast(@alignCast(owner.?)), at);
}
fn restore(_: *anyopaque, _: ?*anyopaque, _: pc.Saved) anyerror!void {
return error.BackendRestores;
}
fn drop(ptr: *anyopaque, saved: pc.Saved) void {
const f: *lanes.fake.Fake = @ptrCast(@alignCast(ptr));
f.drop(saved);
}
};
for ([_]bool{ true, false }) |usable| {
var cfg = try lanes.Config.init(gpa, .{ .exact_width = 8, .gpu_tokens = true, .hidden_rows = true }, 8, 7);
defer cfg.deinit(gpa);
Expand All @@ -216,7 +217,7 @@ test "a warm_usable store keeps a warm pass's grid mark but not its end off the
var core = lanes.Engine.init(gpa, &cfg, target.backend(), clock.clock());
defer core.deinit();
// dots.mocr's rules, scaled down: a grid of 4 and no request starts, so only multiples of 4 resume
var store = pc.Store.init(gpa, .{ .ptr = &target, .vtable = &.{ .bytes = Snaps.bytes, .save = Snaps.save, .restore = Snaps.restore, .drop = Snaps.drop } }, .{ .planned = true, .grid = 4, .warm = .on, .warm_usable = usable }, 400);
var store = prompt_cache.Store.init(gpa, .{ .ptr = &target, .vtable = &fake_snap_vtable }, .{ .planned = true, .grid = 4, .warm = .on, .warm_usable = usable }, 400);
defer store.deinit();
var host = LaneHost.init(gpa, std.testing.io, &core, .{ .lanes = 2, .warm_turns = true });
host.cache = &store;
Expand All @@ -241,23 +242,6 @@ test "a warm_usable store keeps a warm pass's grid mark but not its end off the

test "a one-snapshot store keeps the warm pass's usable mark over an unusable end; the next request resumes the mark" {
const gpa = std.testing.allocator;
const pc = api.prompt_cache;
const Snaps = struct {
fn bytes(_: *anyopaque, at: u32) u64 {
return 64 + 4 * @as(u64, at);
}
fn save(ptr: *anyopaque, owner: ?*anyopaque, at: u32) anyerror!pc.Saved {
const f: *lanes.fake.Fake = @ptrCast(@alignCast(ptr));
return f.save(@ptrCast(@alignCast(owner.?)), at);
}
fn restore(_: *anyopaque, _: ?*anyopaque, _: pc.Saved) anyerror!void {
return error.BackendRestores;
}
fn drop(ptr: *anyopaque, saved: pc.Saved) void {
const f: *lanes.fake.Fake = @ptrCast(@alignCast(ptr));
f.drop(saved);
}
};
for ([_]bool{ true, false }) |usable| {
var cfg = try lanes.Config.init(gpa, .{ .exact_width = 8, .gpu_tokens = true, .hidden_rows = true }, 8, 7);
defer cfg.deinit(gpa);
Expand All @@ -270,7 +254,7 @@ test "a one-snapshot store keeps the warm pass's usable mark over an unusable en
// The 128-row cut and 192-row warm end, scaled to a grid of 4: the end at 6 is off it.

// A budget of one snapshot (88 B) fits either state, never both.
var store = pc.Store.init(gpa, .{ .ptr = &target, .vtable = &.{ .bytes = Snaps.bytes, .save = Snaps.save, .restore = Snaps.restore, .drop = Snaps.drop } }, .{ .planned = true, .grid = 4, .warm = .on, .warm_usable = usable }, 100);
var store = prompt_cache.Store.init(gpa, .{ .ptr = &target, .vtable = &fake_snap_vtable }, .{ .planned = true, .grid = 4, .warm = .on, .warm_usable = usable }, 100);
defer store.deinit();
var host = LaneHost.init(gpa, std.testing.io, &core, .{ .lanes = 2, .warm_turns = true });
host.cache = &store;
Expand Down Expand Up @@ -486,3 +470,71 @@ test "a warm pass gives way to a request still filling its prompt: no quiet wait
try std.testing.expectEqual(@as(usize, @intFromBool(quiet == 0)), behind.chunks.load(.monotonic));
}
}

test "a re-rendered tool history restores its rewind row and matches a fresh reply" {
const gpa = std.testing.allocator;
var cfg = try lanes.Config.init(gpa, .{ .exact_width = 8, .gpu_tokens = true, .hidden_rows = true }, 8, 7);
defer cfg.deinit(gpa);
var target: lanes.fake.Fake = .{ .gpa = gpa };
defer target.deinit();
var clock: lanes.fake.FixedClock = .{};
var core = lanes.Engine.init(gpa, &cfg, target.backend(), clock.clock());
defer core.deinit();
var store = prompt_cache.Store.init(gpa, .{ .ptr = &target, .vtable = &fake_snap_vtable }, .{ .chunk = 1, .min_prompt = 0, .warm = .waits }, 8192);
defer store.deinit();

const Reply = struct {
box: Box = .{},
ids: [4]u32 = undefined,
cached: u32 = 0,

fn event(ctx: *anyopaque, id: Id, e: *const Event) void {
const reply: *@This() = @ptrCast(@alignCast(ctx));
switch (e.*) {
.prefilled => |count| reply.cached = count,
.tokens => |ids| @memcpy(reply.ids[reply.box.tokens..][0..ids.len], ids),
else => {},
}
Box.event(&reply.box, id, e);
}
};

// The follow-up omits the assistant's reasoning, retaining the tool call and adding its result.
const predicted = [_]u32{ 1, 2, 3, 4, 70, 71, 80, 81, 9 };
const rendered = [_]u32{ 1, 2, 3, 4, 80, 81, 9, 90, 91, 10 };
const diff: u32 = @intCast(std.mem.indexOfDiff(u32, &predicted, &rendered).?);
const warm: Request = .{
.prompt = &predicted,
.max_tokens = 0,
.background = true,
.history_len = predicted.len,
.rewind_len = diff,
.born = 2,
.decode_spans = &.{.{ 2, 8 }},
};
const next: Request = .{ .prompt = &rendered, .max_tokens = 4, .decode_spans = &.{.{ 2, 6 }} };
var warm_reply: Reply = .{};
var fresh_reply: Reply = .{};
for ([_]?*prompt_cache.Store{ &store, null }, [_]*Reply{ &warm_reply, &fresh_reply }) |cache, reply| {
var host = LaneHost.init(gpa, std.testing.io, &core, .{ .lanes = 1 });
host.decoded_rows = true;
host.cache = cache;
host.advertiseCache(cache);
try host.start();
defer host.stop();
if (cache != null) {
var box: Box = .{};
try host.engine().submit(1, &warm, .{ .ctx = &box, .event = Box.event });
try std.testing.expectEqual(Reason.length, box.wait());
const continued = predicted ++ [_]u32{90};
const kept = store.find(&continued, &.{}, warm.decode_spans) orelse return error.WarmEndMissing;
try std.testing.expectEqual(@as(u32, predicted.len), kept.at);
}
try host.engine().submit(2, &next, .{ .ctx = reply, .event = Reply.event });
try std.testing.expectEqual(Reason.length, reply.box.wait());
try std.testing.expectEqual(reply.ids.len, reply.box.tokens);
}
try std.testing.expectEqual(diff, warm_reply.cached);
try std.testing.expectEqual(@as(u32, 0), fresh_reply.cached);
try std.testing.expectEqualSlices(u32, &fresh_reply.ids, &warm_reply.ids);
}
112 changes: 112 additions & 0 deletions zig/src/core/rows_pool_select_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,115 @@ test "restore selection: pooled buffers trim only when supported and never steal
s.release(borrowed);
}
}

test "restore selection: a pool without trim reads into the spare storage an eviction leaves, as a keep would" {
var tmp = t.tmpDir(.{});
defer tmp.cleanup();
const dir = try tmp.dir.realPathFileAlloc(t.io, ".", a);
defer a.free(dir);
var prompt: [64]u32 = undefined;
for (&prompt, 0..) |*token, i| token.* = @intCast(100 + i);
const rules: pc.Rules = .{ .min_prompt = 0, .min_gap = 1, .lookahead = 1 };
{
var f: Fake = .{ .gpa = a, .at = 20, .sum = fresh(prompt[0..20]) };
var table = f.pooled().vtable.*;
table.rows = &Image.api;
const family: pc.Snapshots = .{ .ptr = &f, .vtable = &table };
const r = try rows.Rows.open(a, family, options(dir));
defer r.deinit();
var s = pc.Store.init(a, family, rules, 1000);
defer s.deinit();
s.disk = r;
try t.expect(s.keep(&prompt, 20, null, &.{}, &.{}));
while (rows.write.step(r)) {}
}
var f: Fake = .{ .gpa = a, .at = 5, .sum = fresh(prompt[0..5]) };
var table = f.pooled().vtable.*;
table.rows = &Image.api;
table.trim = null;
const family: pc.Snapshots = .{ .ptr = &f, .vtable = &table };
const r = try rows.Rows.open(a, family, options(dir));
defer r.deinit();
var s = pc.Store.init(a, family, rules, 240);
defer s.deinit();
try t.expect(s.keep(&prompt, 5, null, &.{}, &.{}));
const borrowed = s.entries.items[0];
borrowed.borrowers = 1;
prompt[0] = 999;
f.at = 30; // another conversation's state: its storage, once evicted, can take the read (120 >= 110)
f.sum = fresh(prompt[0..30]);
try t.expect(s.keep(&prompt, 30, null, &.{}, &.{}));
prompt[0] = 100;
s.disk = r;
try t.expectEqual(.disk, rows.read.resumable(&s, &prompt, &.{}, &.{}).from);
const restored = rows.read.recall(&s, &prompt, 64, &.{}, &.{}, borrowed).?;
try t.expectEqual(@as(u32, 20), restored.at);
try t.expectEqual(@as(u64, 1), r.counts.reads);
try t.expectEqual(@as(u64, 1), s.counts.evicted);
try t.expect(s.held + s.spare() <= s.budget);
try family.vtable.restore(family.ptr, null, restored.saved);
try t.expectEqual(fresh(&prompt), f.pass(&s, &prompt, .{ .from = restored.at }));
s.release(borrowed);
}

/// A disk read into new storage, whatever spare storage the pool holds.
const Fresh = struct {
const api: rows.Image = .{ .parts = Image.parts, .gather = Image.gather, .blank = blank, .scatter = Image.scatter };
fn blank(ptr: *anyopaque, at: u32) !pc.Saved {
const f: *Fake = @ptrCast(@alignCast(ptr));
const previous = f.at;
f.at = at;
defer f.at = previous;
return f.snapshots().vtable.save(ptr, null, at);
}
};

test "restore selection: a pool that also trims reads a disk state only within its budget, whatever it reuses" {
var tmp = t.tmpDir(.{});
defer tmp.cleanup();
const dir = try tmp.dir.realPathFileAlloc(t.io, ".", a);
defer a.free(dir);
var prompt: [64]u32 = undefined;
for (&prompt, 0..) |*token, i| token.* = @intCast(100 + i);
const rules: pc.Rules = .{ .min_prompt = 0, .min_gap = 1, .lookahead = 1 };
{
var f: Fake = .{ .gpa = a, .at = 20, .sum = fresh(prompt[0..20]) };
var table = f.pooled().vtable.*;
table.rows = &Image.api;
const family: pc.Snapshots = .{ .ptr = &f, .vtable = &table };
const r = try rows.Rows.open(a, family, options(dir));
defer r.deinit();
var s = pc.Store.init(a, family, rules, 1000);
defer s.deinit();
s.disk = r;
try t.expect(s.keep(&prompt, 20, null, &.{}, &.{}));
while (rows.write.step(r)) {}
}
var f: Fake = .{ .gpa = a, .at = 5, .sum = fresh(prompt[0..5]) };
var table = f.pooled().vtable.*;
table.rows = &Fresh.api;
try t.expect(table.reuses != null and table.trim != null);
const family: pc.Snapshots = .{ .ptr = &f, .vtable = &table };
const r = try rows.Rows.open(a, family, options(dir));
defer r.deinit();
var s = pc.Store.init(a, family, rules, 240);
defer s.deinit();
try t.expect(s.keep(&prompt, 5, null, &.{}, &.{}));
const borrowed = s.entries.items[0];
borrowed.borrowers = 1;
prompt[0] = 999;
f.at = 30; // another conversation's state: once evicted, its spare storage is one the family says takes the read
f.sum = fresh(prompt[0..30]);
try t.expect(s.keep(&prompt, 30, null, &.{}, &.{}));
prompt[0] = 100;
s.disk = r;
try t.expectEqual(.disk, rows.read.resumable(&s, &prompt, &.{}, &.{}).from);
const restored = rows.read.recall(&s, &prompt, 64, &.{}, &.{}, borrowed).?;
try t.expectEqual(@as(u32, 20), restored.at);
try t.expectEqual(@as(u64, 1), r.counts.reads);
try t.expectEqual(@as(u64, 1), s.counts.evicted);
try t.expect(s.held + s.spare() <= s.budget); // the spare storage was trimmed for the new storage, not left over it
try family.vtable.restore(family.ptr, null, restored.saved);
try t.expectEqual(fresh(&prompt), f.pass(&s, &prompt, .{ .from = restored.at }));
s.release(borrowed);
}
13 changes: 8 additions & 5 deletions zig/src/core/rows_read.zig
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ fn one(r: *Rows, name: Name, kind: file.Kind, ext: []const u8, at: u32, ranges:
return o.trailer.payload + o.trailer.meta + @sizeOf(file.Trailer);
}

/// Whether a family refused what a file holds (words that differ, a size or a range that does not fit its blank).
/// Whether a family refused what a file holds (words that differ, of another world or layout; a size or range unfit).
fn refused(err: anyerror) bool {
return switch (err) {
error.SnapshotSize, error.BadKeptRange, error.DiskWords, error.KeptWordsDiffer => true,
error.SnapshotSize, error.BadKeptRange, error.DiskWords, error.KeptWordsDiffer, error.DiskWorld, error.DiskLayout => true,
else => false,
};
}
Expand Down Expand Up @@ -128,9 +128,9 @@ fn attempt(s: *pc.Store, prompt: []const u32, born: u32, starts: []const u32, sp
const name = candidate.name;
const bytes = r.blankBytes(candidate.at);
if (bytes > s.budget or s.most == 0) return have;
if (!ready(s, bytes)) present(r, chosen) catch |err| return failed(before, candidate.at, err, have); // nothing goes to make room for a state whose file is gone
if (!ready(s, candidate.at, bytes)) present(r, chosen) catch |err| return failed(before, candidate.at, err, have); // nothing goes to make room for a state whose file is gone
if (r.spill != .off) r.touch(chosen); // the newest: the spills that make room for it push older states off first
while (!ready(s, bytes)) {
while (!ready(s, candidate.at, bytes)) {
if (s.family.vtable.trim) |trim| {
const spare = s.spare();
trim(s.family.ptr, s.budget -| s.held -| bytes);
Expand Down Expand Up @@ -165,8 +165,11 @@ fn attempt(s: *pc.Store, prompt: []const u32, born: u32, starts: []const u32, sp
return e;
}

fn ready(s: *const pc.Store, bytes: u64) bool {
fn ready(s: *const pc.Store, at: u32, bytes: u64) bool {
if (s.held > s.budget or s.entries.items.len >= s.most) return false;
const f = s.family.vtable;
// a pool without trim reads into spare storage that takes the state, as a keep would
if (f.trim == null) if (f.reuses) |reuses| if (reuses(s.family.ptr, at)) return true;
const room = s.budget - s.held;
const spare = s.spare();
return spare <= room and bytes <= room - spare;
Expand Down
Loading
Loading