Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 12 additions & 3 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ without the `flare_` prefix, such as `input_decoded_images_total`.
| `host_hits` | Requests attached to a successfully restored host prefix | `flare_host_cache_hits_total` |
| `host_reused_tokens` | Successfully restored tokens beyond each request's admission GPU prefix | `flare_host_cache_reused_tokens_total` |
| `host_memory_records` | Checkpoint records in the host store's registered memory | `flare_host_cache_memory_records` |
| `host_disk_records` | Checkpoint records in the host store's record directory | `flare_host_cache_disk_records` |
| `host_disk_records` | Ready indexed checkpoint records in the host store's record directory | `flare_host_cache_disk_records` |
| `host_bytes_out` | Bytes copied from GPU checkpoints to the host store | `flare_host_cache_bytes_out_total` |
| `host_bytes_in` | Bytes copied from the host store into GPU pages and rows | `flare_host_cache_bytes_in_total` |
| `learned_drafter` | Boolean: the model has a learned drafter | none |
Expand Down Expand Up @@ -388,8 +388,17 @@ a disk-only store's local writes contribute zero. The gauge
writes. `flare_host_cache_store_skipped_total` includes duplicates and
retries; it is not a dropped-record counter. Local checkpoint pool capacity is
reported by `flare_host_cache_slots_in_use`, `flare_host_cache_slots_total`
(including automatic intake), and `flare_host_cache_intake_slots`. Used slots
include pages, row pieces, and staging allocations.
(including automatic intake when local disk is enabled), and
`flare_host_cache_intake_slots`. Used slots include pages, row pieces, and
staging allocations. On-disk storage separates ready indexed records and their logical lengths
(`flare_host_cache_disk_records` and `flare_host_cache_disk_bytes`) from
uncommitted reservations for parked or in-flight writes
(`flare_host_cache_disk_reserved_records` and
`flare_host_cache_disk_reserved_bytes`). Pooled deployments also export
`flare_host_cache_pool_inbound_bytes_per_second{level}` with `neighbour_gpu`,
`host_dram`, `host_nvme`, and `remote_nvme` source levels for the pool's source
ranking estimates, leaving `flare_host_cache_inbound_bytes_per_second` for the
local store's measured restore rate.

Dashboard DEPTH is the change in `verification_drafts` divided by the change in
`verification_rounds` over the sampling window. It averages each request's planned
Expand Down
129 changes: 98 additions & 31 deletions docs/prefix-cache-offload.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,14 @@ All combinations apply on one host. Ranks on separate hosts support zero warm
memory with disk and/or pool; nonzero warm memory is refused because that tier
holds every rank's bytes in one process. Each disk peer uses its host's intake.

Automatic registered intake is additional to the warm budget whenever warm
memory or local disk is enabled. It needs no setting: its slot count is
Automatic registered intake is additional to the warm budget whenever local disk
is enabled. Warm memory stores without local disk (memory-only or memory with a
pool) allocate zero intake slots and size the host slab directly from the warm
checkpoint budget (failing startup if the checkpoint share is smaller than one
page record). Disk intake needs no setting: its slot count is
`2 × max_active × row_slots + 2 × WINDOW_PAGES`, where `WINDOW_PAGES = 64`,
except for local tiers (`memory > 0` or local disk enabled) on an
integrated-memory device (`CU_DEVICE_ATTRIBUTE_INTEGRATED`), where intake
targets two streaming windows and two continuation rows,
except on an integrated-memory device (`CU_DEVICE_ATTRIBUTE_INTEGRATED`), where
disk intake targets two streaming windows and two continuation rows,
`2 × (WINDOW_PAGES + row_slots)` (`intake_slots(layout, 1)`).
The warm checkpoint budget rounds down to whole slots. If host headroom cannot
hold the full intake, it shrinks toward two complete windows,
Expand Down Expand Up @@ -527,7 +529,8 @@ model-stream work after the copies; the model stream never waits on an
offload event.

Transfers move records in windows of at most 64 pages plus the multi-slot row.
The pool contains warm checkpoint slots plus automatic intake slots. It is one
The pool contains warm checkpoint slots plus automatic intake slots when local
disk is enabled (zero intake slots when local disk is disabled). It is one
page-aligned anonymous mapping (`MAP_PRIVATE`, `MAP_ANONYMOUS`), prefaulted
writable (in bounded chunks on Unix) and registered once at startup. On Linux,
`eos::map_host` inspects
Expand Down Expand Up @@ -568,13 +571,33 @@ counts as packed when its pages or row are replicated; promotions count as a new
DRAM store. These decisions do not reduce GPU copy-out traffic.

Memory allocation keeps at least `intake_slots` free slots by evicting the
coldest ready, unpinned, durable records that, in pool mode, are not announced.
Maintenance starts writes of
the coldest dirty records, or retirements to the pool, when `free + clean` falls
below `2 × intake_slots`. Memory-only records are already durable. Maintenance
coldest ready, unpinned, durable records that, in pool mode, either are not yet
announced or have already completed pool handover for their current shape and
role. In warm memory-plus-pool mode, a record whose full handover succeeds
remains resident in DRAM as a clean, cheaply evictable copy so it can continue
serving local restores and acting as a local parent for descendant captures
until memory pressure evicts it. Role promotion, forking a non-fork parent, or
dropping a same-page parent row that covered an endpoint invalidates that clean
handover state and updates clean-slot accounting so the upgraded record is
re-offered before eviction. Pool-only capture buffers (`memory_bytes == 0`) drop
moved records immediately once unpinned.

Maintenance in composite mode starts writes of the coldest dirty records when
`free + clean` falls below `2 × intake_slots` (plus slots held by in-flight
compression). Maintenance in warm memory-plus-pool mode separates the
non-borrowable disk streaming reserve (`intake_slots`, which is zero without
local disk) from bounded foreground capture headroom inside the warm retention
region (`slot_count - intake_slots`): it starts retirements to the pool when
`free + reclaimable_clean` falls below `intake_slots + headroom(retention_slots,
max(row_slots, 1)) + compressing_slots`, where `headroom` is 5% of
`retention_slots`, floored at `2 × max(row_slots, 1)` and capped at 10% of
`retention_slots`. Clean ancestors blocked behind unpersisted descendants are
excluded from `reclaimable_clean` so maintenance and allocation retire blocking
leaves without stalling. Memory-only records are already durable. Maintenance
never waits for `Staged`; independent memory and disk copier queues share the
pool. No more than twice the intake plus one largest record is written ahead
of need, so a large warm tier does not eagerly write its contents to disk.
of need in composite mode, so a large warm tier does not eagerly write its
contents to disk.
Neither publication nor admission waits for I/O. GPU-only retries remain
unpinned so they cannot prevent admission. If a copier cannot drain at close,
the mapping is leaked rather than reused under outstanding copies.
Expand Down Expand Up @@ -702,7 +725,14 @@ GPU tier.

The disk thread in `selene/src/disk.rs` owns an `io_uring` ring on Linux or an
I/O completion port on Windows over raw v1–v3 record files opened for direct I/O,
and chunks direct transfers at 8 MiB. On raw v1–v3 opens it reads the 4 KiB
and chunks direct transfers at 8 MiB. Whole-record v4 packed writes—both
manager `WriteRecord` write-backs and local `WritePacked` writes—also use
direct I/O through owned 4 KiB-aligned staging or tail buffers with
zero-initialized padding, truncating the temporary file to the exact logical v4
length before `fdatasync` and rename (falling back to buffered writes only when
the filesystem refuses `O_DIRECT` with `EINVAL`). Partial unaligned streaming
`WriteRecord` windows stay buffered so adjacent windows in the temporary file
are never overwritten. On raw v1–v3 opens it reads the 4 KiB
header and expected page-checksum segment in one direct transfer when the
expected tail fits in its 1 MiB scratch buffer (`MAX_TAIL_PAGES`), retrying the
4 KiB header block alone on failure so truncated-file and invalid-header
Expand Down Expand Up @@ -856,21 +886,31 @@ receive logical eviction notices, including compaction. Any attached store can
receive completion refreshes. Every store call from the worker returns without waiting.

Admission consults the store after `plan_admission`: `lookup` runs above the
GPU hit, the policy in section 2.10 decides whether to fetch, and
`admit_planned` receives the inbound request. If capacity prevents reserving
the restore's pages and snapshot row, admission waits while existing requests,
inbound tickets, checkpoint pins, or fenced retirement may release resources.
Waiting plus estimated transfer time must remain below half the estimated
prefill time of the tokens gained. The worker retries after resource changes,
GPU hit, admission prices the prefill time saved by starting at the candidate
checkpoint instead of the GPU-resident prefix using the scheduler's read-only
prefill-delta estimator over prepared graph timings (including terminal/scored
variants, sliding-window tails, atomic spans, and partial fills, with a cold
per-token fallback only before prefill graphs are measured), compares effective
transfer time against half that saved prefill time, and passes accepted hits to
`admit_planned`. Row-only restores (`pages == 0`) track their end-to-end setup
and transfer latency separately from bulk page transfer bandwidth so fixed setup
cost prices row-only hits without distorting bulk bandwidth medians. If capacity
prevents reserving the restore's pages and snapshot row, admission waits while
existing requests, inbound tickets, checkpoint pins, or fenced retirement may
release resources. Waiting plus the same effective transfer time must remain
below half the same estimated saved prefill time. The worker retries after resource changes,
pin release, transfer completion, or wait-budget expiry; expiry is checked even
when resource counts stay unchanged. Other eligible requests can be admitted during this wait.
If no resource holder remains or the budget expires, admission tries recomputation.
If recomputation also lacks capacity, it waits for resource changes without
repeated timeout retries. A successful admission clears the wait accounting so
readmission after preemption starts a separate wait. Pooled lookups keep their
validated history across retries and recheck GPU residency. Pending and ready
tickets are retained; a ticket with no answer is replaced only when its request
is selected for admission. First lookups start even while capacity is blocked,
tickets are retained while GPU residency stays at or above the ticket's
requested offset; if GPU residency shrinks below that offset before admission,
the worker cancels the stale ticket and refreshes it at most once per admission
episode (falling back to local lookup on a further shrink). A ticket with no
answer is replaced only when its request is selected for admission. First lookups start even while capacity is blocked,
once prompt scoring is complete.
A newly created ticket starts the inbound job through `fetch`. On inbound failure the worker cancels each
waiter and pushes its `Incoming` to the front of the pending queue with host
Expand Down Expand Up @@ -927,9 +967,18 @@ Policy:
Offload limits interference through bounded work and explicit ownership:

- The manager has four write-back workers. Independent chains can flush
concurrently, with each parent written before its children. The claim
drain and flush share 270 seconds from the stop signal. The claim drain
allows the configured claim deadline plus two seconds (32 seconds by
concurrently, with each parent written before its children while respecting
pending former-tip pruning. Completed write-backs retain their clean arena
copies as cheaply evictable so subsequent restores hit RAM until an incoming
allocation needs a coalescable buddy block. Puts waiting on write-back or on
an in-flight key park in bounded FIFO waiter queues woken by disk completion,
arena release, cancellation, or timeout (with an independent 10 ms timer tick
enforcing deadlines); waiting offers coalesce directly to `Present` when the
published record covers the offer, while preserving independent waiter
ownership and rechecking bucket, role promotion, fork count, and descendant
coverage.
The claim drain and flush share 270 seconds from the stop signal. The claim
drain allows the configured claim deadline plus two seconds (32 seconds by
default), capped at four minutes. The flush gets the remaining time.
- The model stream never waits on an offload event. Host-observed completion
orders transfers and scheduler visibility. Shared bandwidth and copy engines
Expand Down Expand Up @@ -960,8 +1009,13 @@ Offload limits interference through bounded work and explicit ownership:
peers (`selene/src/shard.rs`) wait on `poll(POLLIN)` on their rank TCP socket
on Unix (`1 ms` sleep on non-Unix). Adding CPU affinity requires a
serving-latency measurement that shows a benefit.
- Page cache: all record I/O is direct, so disk writes neither grow the page
cache nor evict the core file's mappings.
- Page cache: raw v1–v3 record I/O, manager direct reads, manager whole-record
v4 write-backs, and local `WritePacked` writes use direct I/O (with owned
4 KiB-aligned zero-padded tail/staging buffers and exact-length truncation
before publish), so normal record writes neither grow the page cache nor
evict the core file's mappings. Partial unaligned streaming windows, local
v4 `ReadPacked` and metadata reads, and filesystems that refuse `O_DIRECT`
use buffered I/O.
- Memory: every slab pool is fixed at startup and sized by the defaults in
section 2.11. Descriptor arrays, rings, and events are preallocated.
- Backpressure: every queue is bounded. When the disk thread falls behind,
Expand All @@ -979,7 +1033,8 @@ Offload limits interference through bounded work and explicit ownership:
- Memory size: `flare run --prefix-cache-memory SIZE` or `[prefix_cache] memory`
sets the warm budget, shared by checkpoints and prepared CPU inputs as described
in section 1. Zero and an unset value disable warm retention; automatic intake
serves disk retention regardless. There is no minimum warm size or row-count warning.
serves disk retention regardless. Without local disk, a nonzero memory budget's
checkpoint share must hold at least one warm page.
- Disk directory: `--prefix-cache-disk DIR` or `[paths] prefix_cache` names
the directory under which
the model's record directory, `<identity prefix>-<layout fingerprint>`, is
Expand Down Expand Up @@ -1014,9 +1069,15 @@ Offload limits interference through bounded work and explicit ownership:
input limits, and the record directory, disk limit, scanned record count,
`staged` transport, and `scan` duration.
- Metrics expose `flare_host_cache_slots_in_use`, `flare_host_cache_slots_total`
(including intake), and `flare_host_cache_intake_slots`. Used slots include
(including intake when local disk is enabled), and
`flare_host_cache_intake_slots`. Used slots include
pages, every row piece, and staging allocations from the same local pool.
Rows are counted in these slot gauges; no separate row gauges exist.
Disk gauges separate ready indexed records and their logical lengths
(`flare_host_cache_disk_records` and `flare_host_cache_disk_bytes`) from
uncommitted reservations for parked or in-flight writes
(`flare_host_cache_disk_reserved_records` and
`flare_host_cache_disk_reserved_bytes`).
- The GPU prefix cache is derived, as the CLI design specifies. Host
retention is explicit because host
memory and disk are shared with other software.
Expand Down Expand Up @@ -1387,6 +1448,9 @@ same completion events the store produces.
(`inflight`, `slabs`, `queue`, `budget`). The same counter reports terminal
losses under the `oversize` and `io_error` reasons;
`flare_host_cache_store_reasons_total{reason}` counts attempts.
`flare_host_cache_pool_inbound_bytes_per_second{level}` reports the pool
restore rate estimate used for source ranking by source level
(`neighbour_gpu`, `host_dram`, `host_nvme`, `remote_nvme`).
- **Publication outcomes.** `Present` requires a committed local copy; a lookup
hint is not sufficient. `Oversize` includes required ancestor files that
cannot coexist within the disk limit even without unrelated records, and
Expand Down Expand Up @@ -1479,10 +1543,13 @@ is unavailable, the buffer retains records under the normal DRAM eviction policy
With separate rank processes, a pool without a local disk tier only restores.

When DRAM feeds the pool directly, the shutdown drain continues copying,
checksumming and retiring records until they finish or the configured time
expires. It stops early when the manager cannot accept records, so a manager
that is down does not hold shutdown for the whole drain time. Pool close cancels
unfinished puts before the host copier closes.
checksumming and retiring records that have not yet completed pool handover at
their current shape and role until they finish or the configured time expires.
Clean records already persisted in the pool stay resident without blocking
shutdown drain or triggering redundant puts. Drain stops early when the manager
cannot accept records, so a manager that is down does not hold shutdown for the
whole drain time. Pool close cancels unfinished puts before the host copier
closes.

## 3. Components and required test coverage

Expand Down
Loading
Loading