mirror of
https://github.com/kvcache-ai/AgentENV.git
synced 2026-11-05 01:17:36 +00:00
[GH-ISSUE #119] Add opt-in dirty-page tracking for memory snapshot page selection #38
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#38
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?
Originally created by @xeonliu on GitHub (Aug 4, 2026).
Original GitHub issue: https://github.com/kvcache-ai/AgentENV/issues/119
Affected component
Firecracker runtime
Problem statement
AgentENV currently configures fresh VMs with
track_dirty_pages = false, and file-backed snapshot restore does not setSnapshotLoadParams.track_dirty_pages. Memory snapshots are requested as FirecrackerDiffsnapshots, but without dirty tracking Firecracker usesmincore(2)to select pages.That makes the result sparse, but not truly incremental:
mincoreeven though a snapshot may need them.Consequently, a sandbox that changes only a small amount of memory between checkpoints may still write an OverlayBD layer approaching its resident working-set size. Frequent pause, snapshot, resume, and fork operations then pay unnecessary pause latency, storage I/O, object-storage/network transfer, and layer-compaction cost.
Firecracker PR #5274 explicitly distinguishes
mincoresnapshots from dirty-page tracked snapshots, and Firecracker issue #5768 describes the former as closer to sparse snapshots than differential snapshots:I did not find an existing AgentENV issue or PR proposing true dirty-page page selection. AgentENV PR #92 adds optional compression, but compression reduces stored bytes rather than selecting only pages written during the current snapshot epoch, and it does not reduce the page set read from Firecracker.
Use case
Long-running agent and RL sandboxes can have 1-8 GiB of guest memory and a large read-mostly working set. Between two checkpoints, the workload may modify only tens of MiB. The same environment may be checkpointed or forked many times during one trajectory.
For these workloads, each memory layer should contain approximately the pages actually written since tracking began, rather than the full resident working set. Reading a large restored working set should not by itself make the next memory layer large.
Current behavior and workarounds
The default direct path is:
The legacy path creates a sparse
mem.binDiff snapshot and converts its data extents intooverlaybd.commit.Current mitigations are insufficient:
mincoreavoids copying never-resident anonymous pages, but cannot distinguish read-only resident pages from written pages.mem.binpath can reuse Firecracker's snapshot transaction, but adds an intermediate large-file write/read cycle before OverlayBD packaging.Related AgentENV work:
Desired behavior
mincorevsdirty) rather than silently changing the current default.track_dirty_pages = trueand file-backed restores are configured withSnapshotLoadParams.track_dirty_pages = true, so the selected page set comes from the KVM and Firecracker/VMM dirty bitmaps instead ofmincore.Acceptance criteria:
mincoremode.mincoreand dirty modes.Proposed approach
Start with an explicit opt-in mode rather than silently changing the current default. The exact config shape is open for discussion, for example:
The dirty mode would likely require:
MachineConfiguration.track_dirty_pages = truefor fresh VMs.SnapshotLoadParams.track_dirty_pages = truefor file-backed restores.SegmentMappingrepresentation, and retain the current directprocess_vm_readv -> compact_to -> overlaybd.commitdata path.Open questions for maintainers:
mincoredeliberately preferred to avoid KVM dirty-logging overhead, or is it currently a compatibility/default choice?GET /vm/dirty-memory-rangeshonortrack_dirty_pages(KVM dirty log) and fall back tomincorewhen it is off?mincoremode is used with swap enabled?Compatibility and operational impact
API/config changes:
Snapshot or storage format changes:
New host/runtime requirements:
mincoremode's swap precondition should be explicit.Upgrade and rollback considerations:
mincoremode.Alternatives considered
mincoreand rely on compression (AgentENV PR #92): simple, but captures a read-resident superset and does not provide true write-set deltas; compression adds pause CPU.Non-goals
Contribution
I can implement it
Pre-submission checklist
@yingdi-shan commented on GitHub (Aug 4, 2026):
Thanks for raising this. One additional factor worth considering is that AgentENV already enables DAMON reclaim in the guest together with balloon free-page reporting. For filesystem data, there are effectively two cache levels: the underlying image data may already reside in the host page cache, while the guest keeps another copy in its own page cache. Using DAMON allows cold, reclaimable pages to be released from the Firecracker process, so they should no longer be included by mincore.
The current DAMON settings are relatively conservative, and tuning parameters such as min_age, quota_sz and the watermarks more aggressively may reduce snapshot size further, potentially addressing much of this concern without the runtime overhead of dirty-page tracking.