[Feature Request] Restore a chain of Diff snapshots with the `File` memory backend, without merging

Aperta
#6,485 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
28/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
linux, rust

Direzione di ricerca

Start with the snapshot loading path for PUT /snapshot/load and the memory mapping code described in the issue; compare it with the single-file hole handling in #6396. The issue proposes layered File mappings and optional Diff hole filling, but leaves design choices open. Done means loading a Diff chain works as described while preserving shared page cache and addressing mapping contention.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Feature Request

We restore many short-lived microVMs from layered snapshots: a Full snapshot of a booted guest, with Diff snapshots on top, each taken from a microVM restored from its parent. Today the File backend can only restore such a chain after it has been merged. The snapshot docs say a Diff "must be merged with a base snapshot into a full snapshot", by copying each layer over the base with snapshot-editor edit-memory rebase.

For us, merging has two costs:

  • A full-size memory file for every leaf snapshot. Each new Diff means writing a complete copy of guest memory, however small the Diff is.
  • No sharing between leaves. A File restore shares page cache between microVMs restored from the same memory file. Once each leaf is merged into its own file, microVMs restored from different leaves of the same base no longer share the base's pages.

The other option today is a UFFD handler that layers the chain. That works, but every page a microVM touches is copied into its own private memory, and every microVM needs a handler process.

Describe the desired solution

An optional list of Diff memory files on PUT /snapshot/load with the File backend, oldest first. Firecracker would map the bottom memory file MAP_PRIVATE as it does today. It would then map each layer's data extents, found with SEEK_DATA/SEEK_HOLE, over that mapping with MAP_FIXED | MAP_PRIVATE, so every guest page maps the newest layer that holds it. All of this happens during the load, before the microVM runs. The kernel then serves each page from the page cache of the file that holds it. That page cache is shared by every microVM restored from the same layers, with no handler involved.

The request could look like this:

curl --unix-socket /tmp/firecracker.socket -i \
    -X PUT 'http://localhost/snapshot/load' \
    -H 'Accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
            "snapshot_path": "./diff2/snapshot_file",
            "mem_backend": {
                "backend_type": "File",
                "backend_path": "./full/mem_file"
            },
            "mem_file_layers": ["./diff1/mem_file", "./diff2/mem_file"]
    }'

Mapping count. Each data extent splits the guest memory mapping, so a layer costs about two mappings per extent. That could run into vm.max_map_count at around 32k runs. We hit lock contention well before that:

  • The cost: When the diff has a large number of extents, a restore can have a large number of mappings as well. When testing, a significant percentage of the top on-CPU kernel stacks were spinning on the memory files' i_mmap_rwsem. Each extent takes it for writing in __split_vma at restore, and each mapping takes it again in unlink_file_vma at teardown. Every microVM restored from the same files shares that lock.
  • The fix: we gave the Diff a minimum hole size of 64 pages (256 KiB). When the Diff is written, any shorter gap between two dirty pages is written as data too. Those pages are clean, so their contents are still in guest memory. This helped to reduce the contention.
  • Where it could live: an orchestrator could enforce this offline, by copying the parent's bytes into short holes. It's cheaper in Firecracker, which has the dirty bitmap and guest memory at hand when it writes the Diff. Possible ways include adding it as an optional field on PUT /snapshot/create (diff_gap_fill_pages), or maybe a name like diff_min_hole_pages, or a KiB value, might read better.

Describe possible alternatives

  • Merge first (snapshot-editor edit-memory rebase), as documented, with the costs above.
  • *A UFFD handler that layers the chain: Every touched page becomes a private copy, and each microVM needs a handler.
  • An explicit extent list instead of SEEK_DATA: entries of (file, file offset, guest memory offset, length). That would also cover:
    • layers on hugetlbfs, which can't report holes;
    • files that lost their holes in transit;
    • chunk files from a content-addressed store.
  • #5840's fd replies. Its page responses already carry (fd, file offset, guest offset, length), the same data as a layer's extents. A handler could install this layout through it given two things:
    • a range could be mapped private, copy-on-write
    • the layout could be applied during the load, before the microVM runs, rather than per fault.

Curious whether you'd rather go that way than add a load field, also would be happy to send a PR!

Additional context

  • #6396 does something very similar at File load for a single file: it walks the memory file and maps anonymous memory over its holes with MAP_FIXED. Based on that, it seems natural to map anonymously only the ranges that are holes in every layer.

Checks

  • Have you searched the Firecracker Issues database for similar requests?
  • Have you read all the existing relevant Firecracker documentation?
  • Have you read and understood Firecracker's core tenets?
Lingua principale
Rust
Stelle
38.2k
Fork
2.8k
Merge medio
2g 12h
PR unite (30g)
59

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di firecracker-microvm/firecracker

Tutte le issue di firecracker-microvm/firecracker

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.