Skip to content

feat: add dirty memory clear API - #30

Open
Hygge-Gezelligheid wants to merge 1 commit into
kvcache-ai:v1.15.1-patch-nestedvirtfrom
Hygge-Gezelligheid:feat/clear-dirty-memory
Open

Hygge-Gezelligheid wants to merge 1 commit into
kvcache-ai:v1.15.1-patch-nestedvirtfrom
Hygge-Gezelligheid:feat/clear-dirty-memory

Conversation

@Hygge-Gezelligheid

@Hygge-Gezelligheid Hygge-Gezelligheid commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Add PUT /vm/dirty-memory-ranges/clear so external snapshot consumers can clear dirty records after committing a snapshot. The endpoint accepts {}, returns 204 on success, and supports only PUT.

With dirty tracking enabled, it clears KVM dirty logs and Firecracker bitmaps, then conservatively re-marks activated virtio queue pages as dirty. With dirty tracking disabled, it returns success without performing any clearing.

Usage constraints

  • The VM must be started and paused. With dirty tracking enabled, keep it paused and coordinate other memory writers throughout state capture, export, commit, and CLEAR.
  • Native snapshots and external exports share one dirty baseline. With dirty tracking enabled, subsequent Diffs must be applied to the complete image committed before CLEAR.
  • With dirty tracking disabled, GET continues to use mincore to query page residency. CLEAR does not establish an incremental baseline or guarantee that the next export contains only new writes.
  • CLEAR does not modify guest memory contents or pause state. A KVM failure may leave partially cleared logs, with no rollback. Recover from the last committed snapshot in a replacement instance rather than transparently retrying.

Validation

All 9 CLEAR unit tests passed on ARM64, covering:

  • Request bodies, paths, response status, and preconditions, including rejection of GET and PATCH on /clear.
  • Repeated CLEAR, unchanged guest memory contents and pause state, and tracking of subsequent writes.
  • Errors in the first, middle, and last slots, with no subsequent reset of Firecracker bitmaps.
  • Re-marking activated MMIO virtio queue pages and skipping unplugged slots.
  • Success with dirty tracking disabled, without reading KVM dirty logs or resetting retained Firecracker dirty bits.

All 4 real-guest integration cases passed, testing the following flows with PCI both enabled and disabled:

  • Tracking enabled: create a full external baseline; CLEAR without a preceding dirty GET; export changes A, commit S1, and CLEAR; write B and zero pages; directly create a native Diff; apply it to S1, restore, and verify the actual guest memory contents.
  • Tracking disabled: CLEAR is rejected while the VM is running; after pausing, repeated calls return 204, with memory contents, GET results, and pause state unchanged; the VM can subsequently resume.

Swagger validation and relevant formatting and static checks passed. Historical full-suite runs on x86 and ARM additionally covered an incorrect S0 base, another CLEAR/Diff/restore cycle after restoration, external-only incremental recovery, and background I/O. These results are retained as one-off validation records. x86 was not rerun in this round.

@Hygge-Gezelligheid
Hygge-Gezelligheid changed the base branch from v1.15.1-patch to v1.15.1-patch-nestedvirt October 28, 2026 01:23
@Hygge-Gezelligheid
Hygge-Gezelligheid force-pushed the feat/clear-dirty-memory branch 5 times, most recently from 59eadc7 to 5aa55d5 Compare October 30, 2026 07:32
Add PUT /vm/dirty-memory-ranges/clear for paused microVMs with dirty
tracking enabled, or succeed without clearing when tracking is disabled.
Clear KVM and Firecracker dirty records, then mark
activated virtio queue memory dirty using existing interfaces.

Document the shared baseline for native and external snapshots and
non-atomic failure semantics. Cover API validation, clearing behavior,
and incremental restore across snapshot consumers.

Signed-off-by: Yicheng Lin <linyc25@mails.tsinghua.edu.cn>
@Hygge-Gezelligheid Hygge-Gezelligheid changed the title feat: add explicit dirty memory clearing API feat: add dirty memory clear API Oct 30, 2026
@Hygge-Gezelligheid
Hygge-Gezelligheid marked this pull request as ready for review October 30, 2026 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant