mirror of
https://github.com/kvcache-ai/AgentENV.git
synced 2026-11-05 01:17:36 +00:00
[PR #124] [MERGED] feat(overlaybd): move background download into the shared full-file cache #195
Labels
No labels
bug
documentation
enhancement
enhancement
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/AgentENV#195
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/kvcache-ai/AgentENV/pull/124
Author: @huajq
Created: 8/5/2026
Status: ✅ Merged
Merged: 8/6/2026
Merged by: @yingdi-shan
Base:
main← Head:bk_cache📝 Commits (1)
8daf172feat(overlaybd): move background download into the shared full-file cache📊 Changes
21 files changed (+2937 additions, -1969 deletions)
View changed files
📝
CLAUDE.md(+1 -1)📝
Cargo.lock(+1 -1)📝
config/default.toml(+3 -3)📝
config/oss_default.toml(+3 -3)📝
docs/src/configuration/reference.md(+23 -11)📝
src/cfg.rs(+23 -3)📝
src/setup/deps.rs(+5 -0)📝
storage/overlaybd/Cargo.toml(+0 -1)➕
storage/overlaybd/src/backend/cache/bk_download.rs(+780 -0)📝
storage/overlaybd/src/backend/cache/full_file_cache/cache_entry.rs(+37 -17)📝
storage/overlaybd/src/backend/cache/full_file_cache/cache_pool.rs(+322 -96)📝
storage/overlaybd/src/backend/cache/full_file_cache/cache_store.rs(+254 -70)📝
storage/overlaybd/src/backend/cache/mod.rs(+3 -0)📝
storage/overlaybd/src/backend/cache/tests.rs(+773 -1)➖
storage/overlaybd/src/bk_download.rs(+0 -1561)📝
storage/overlaybd/src/config.rs(+163 -10)📝
storage/overlaybd/src/download_gate.rs(+84 -9)📝
storage/overlaybd/src/image/image_file.rs(+266 -126)📝
storage/overlaybd/src/image/image_service.rs(+130 -29)📝
storage/overlaybd/src/lib.rs(+0 -2)...and 1 more files
📄 Description
What
Move OverlayBD background download from a per-ImageFile downloader (private
.downloadstaging file, whole-layeroverlaybd.commitpromotion,SwitchFileswap) into one scheduler perFileCacheBackendthat fills the shared full-file cache directly. Completed cache blocks become visible to foreground reads immediately, and foreground/background fetches of the same block are deduplicated by the per-block loader election.Why
The old design fetched the same bytes twice (foreground page-in cache vs. the background
.downloadstaging file) and only made downloaded data usable after a whole-layer switch. Filling the shared cache instead removes the duplicate fetch and lets every block serve foreground reads as soon as it lands.Related issue
N/A
Scope and non-goals
Included:
BkDownloadScheduler(storage/overlaybd/src/backend/cache/bk_download.rs) and its wiring throughFileCacheBackend,ImageService, andImageFile.download.blockSize(default 16 MiB) is one source request; contiguous missing cache blocks within a chunk coalesce into a single read, already-cached blocks are skipped, and blocks are published to the cache bitmap as they land.download.maxConcurrentFilesknob (default 8); validation bounds for all download knobs including the backend-wide scratch budget.bk_download.rs(1561 lines).Non-goals / intentionally excluded:
overlaybd.commitpromotion and no switch-to-local after a full download. Cache-only completion: the cache is a bounded, evictable working set; evicted blocks are re-fetched on demand. Disk pressure is not solved by materializing layers into another local file of the same total size.Design and behavior changes
Scheduler semantics:
cache_id, shared across sandboxes) and never fails under load; only execution is bounded —maxConcurrentFileslayer tasks per backend andmaxInflightBlocksconcurrent chunk fetches. Ready tasks dispatch round-robin per device key.maxMBpsthrottling, per-chunk hedge timeout with reissue, and try_cnt retry with backoff are preserved from the old downloader; retries re-enumerate missing chunks only.Safety fixes (found in review, each covered by a targeted test):
Dropstops downloads; clones never inherit scheduler ownership. Shutdown is an idempotent, caller-independent drain that closes both semaphores; the run guard is built before spawn, so abort-before-first-poll cannot leak the active counter.DEFAULT_MAX_REFILLINGnow gates only range prefill).Compatibility and operations
download.maxConcurrentFiles(default 8).download.blockSizeremains the background chunk size (default now 16 MiB) and is aligned down to whole cache blocks at runtime. Validation now boundsblockSize/concurrency/maxInflightBlocks/maxConcurrentFiles; previously accepted extreme values are rejected at config load.overlaybd.commitfiles for remote layers; pre-existing local commit files still open through the existing local-layer path.ringdependency is dropped from the overlaybd crate (the trailing whole-file hasher is gone).Validation
make fmtmake clippymake test-unitmake -C services test(required whenservices/changes)maketargetCommands and results:
Skipped checks and reasons:
tests/integration): require KVM/network namespaces; covered instead by the real OSS E2E below on the same build.make -C services test: noservices/changes.Real OSS experiment (Aliyun OSS bucket
agentenv-oss-validation, same dataset shape as PR #540): ubuntu 24.04 guest, 8 GiB RAM, 4 GiB dirtied (random), OSS-backed snapshot, release build, public endpoint, caches cleared per round.Risks and reviewer notes
backend/cache/bk_download.rs(scheduler lifecycle),backend/cache/full_file_cache/cache_store.rs(background_refill_range/refill_block_runelection + publication),cache_pool.rs(scheduler ownership, pressure accounting),download_gate.rs(atomic floor admission).ImageFile::dropno longer stops downloads — tasks are shared per blob and finish independently; reviewers should confirm this matches sandbox churn expectations.p2p_publish_url) is now inert; kept to keep this PR focused, removal is a follow-up.Checklist
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.