Skip to content

cache: fs-origin zero-copy pass-through (serve from {path}/{hex} without importing into the store) #1511

Closed

Description

@thiras

Split out of #1130 per its triage comment ("split fs pass-through from remote prewarm, and for fs pin the storage/outboard API and held/probe semantics before dispatch"). #1508 landed the discovery half (Origin::enumerate, the origin-held index, probe/DHT advertising); #1510 landed the http/s3 prewarm half. This is the remaining fs half.

Problem

To serve a blob from a configured fs origin the node imports it into the iroh-blobs store first, so a local origin costs two copies on the same disk for no benefit. Every origin byte transits the store today — dispatch.rs's miss ladder ends in populate/populate_local/pull_through_range, all of which land in iroh-blobs, and deliver reads back through CacheEngine::export_bao_range_stream.

Serve verified ranges directly from {path}/{hex[0..2]}/{hex}, using the sibling {hex}.obao4 when present and computing+persisting only the outboard when it is not (a fraction of a percent of the blob at 16 KiB chunk groups).

The open question from #1130 is answered — with a catch

Open question / main unknown: does iroh-blobs expose file-backed / referenced entries?

Yes: ImportMode::TryReference (iroh-blobs-0.103.0/src/api/proto.rs:630) via Blobs::add_path_with_opts, honored by the fs store as DataLocation::External, so export_bao opens the operator's file in place.

But it is probably the wrong route:

  1. add_path_with_opts computes the hash — you cannot assert "this file is H" — so it is a full BLAKE3 read pass, and it ignores an already-published {hex}.obao4. The issue's "use the sibling outboard if present" optimization is unreachable through it.
  2. Files under options.inline.max_data_inlined are copied into the store regardless of mode.
  3. Once referenced, the LRU driver's release_for_eviction can drop the tag on a blob whose bytes are the operator's origin file, which interacts badly with origin_held_size assuming origin content takes no eviction hold.

Preferred route: iroh-blobs-free, streaming

bao_tree::io::sync::encode_ranges_validated is generic over ReadAt / Outboard / Write, and positioned-io implements ReadAt for File. So a verified, header-less bao range can stream straight from the data file + PreOrderOutboard<File> in O(chunk-group) RAM, with no new dependency.

Work

  • crates/bao-range: a ReadAt-generic, Write-sink variant of encode_verified_range (src/lib.rs:318). Today it takes range_data: &[u8] and returns one Bytes, so a whole-blob pass-through would materialize the entire blob — the exact regression Buffered origin pull-through loads the whole blob into memory before serving #1132 removed. Note the header difference: encode_verified_range prepends the 8-byte LE size for import_bao_bytes; the client wire form is header-less.
  • Outboard computation/persistence: nothing in production writes an .obao4 today (every PreOrderMemOutboard::create call is test-only). Decide where a computed outboard lives — the operator's origin tree (layout is ready: fs.rs already reads {hex}.obao4 and enumerate skips *.obao4) or a cache-side sidecar under cache_dir. Writing into the operator's directory is the part worth deciding deliberately.
  • Serve path: a new tier in handlers/client/dispatch.rs (the has(hash) == Ok(false) ladder), a third size source at the size gate (origin_held_size already exists and is already consulted by probe and the slash-safety guard), an origin-backed sibling to CacheEngine::export_bao_range_stream, and delivery.rs teaching deliver about it (it hard-codes the store variant).
  • Eviction/hold semantics: origin-held content must stay outside the LRU/GC accounting — it is not the cache's disk to reclaim.

Test fixtures that already exist

crates/e2e/src/node.rs has seed_origin_blob_with_outboard and write_fs_origin_outboard; crates/cache/src/origin/fs.rs has seed_blob_with_outboard. The missing-outboard path (compute on first serve) is the new case.

Activity

  1. added
    rust
    on Jul 29, 2026
  2. thiras commented on Aug 1, 2026

    @thiras
    ContributorAuthor

    Audit note (2026-08-01, HEAD b2a9651): #1528 changed the serve-path shape this issue describes, so two body claims are now stale for the outboard-present case:

    • "every origin byte transits the store … deliver reads back through export" — an fs origin with a published {H}.obao4 now streams to the client via serve_via_local_outboard (crates/node/src/handlers/client/dispatch.rs:472-477), since FilesystemOrigin implements fetch_outboard (crates/cache/src/origin/fs.rs:400).

    The headline problem is untouched, though: that path still tees into the iroh-blobs store, so a local-disk origin still ends up with two copies. Also still missing: computing/persisting an outboard when absent (falls back to buffered populate_local), and the origin-held-outside-LRU eviction semantics. One enabler landed: bao-range now has positioned_io::ReadAt plumbing (crates/bao-range/src/lib.rs:278-283) that the preferred zero-copy route needs.

  3. alpergundogdu commented on Aug 19, 2026

    @alpergundogdu
    Contributor

    Attempted in #1750 (closed unmerged).

    Finding: serving fs-origin blobs zero-copy (bypassing the iroh-blobs store) trades away cache hits and own-origin coalescing for popular content, and the double-store it avoids is bounded by the LRU cache (cache_size_mb) rather than an unbounded mirror of the origin — so the net is unfavorable on the common path. A cached blob serves without re-reading or re-verifying the origin, whereas zero-copy re-verifies against the outboard on every serve; and concurrent same-hash misses coalesce onto one fill on the import path but become N independent reads under zero-copy. The two_clients_coalesce_one_upstream_pull_each_pays e2e made this visible (zero-copy neither coalesces nor promotes a cache entry).

    Revisit only as a size-aware gate. Zero-copy is a clear win for blobs larger than the cache — importing them thrashes the working set and they can't be cached anyway (the multi-GB AI-model case). So gate zero-copy on "won't fit the cache" rather than replacing import→cache→coalesce unconditionally. The reusable pieces (header-less ReadAt range encoder, streaming outboard compute, decdn origin index) live in #1750's history.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

prio:mediumrust

Type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions