apfs-weight-checkpoint

command
v0.6.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

apfs-weight-checkpoint

Zero-CGo, zero-sudo unified-memory weight streaming and crash-safe APFS Copy-on-Write checkpointing built with x/apfs.

What It Demonstrates

  • Unified-Memory Weight Streaming (apfs.OpenMapped, apfs.Madvise): Maps a 32 MiB weight shard with F_NOCACHE and MADV_SEQUENTIAL, computes a 64-bit reduction, releases file-backed pages (MADV_DONTNEED fallback on read-only file mappings per XNU VM semantics), and cycles a 4 MiB anonymous scratch buffer through MADV_FREE_REUSABLE (apfs.FreeReusable) and MADV_FREE_REUSE (apfs.FreeReuse).
  • Sub-Millisecond CoW Checkpointing (apfs.CloneFile): Snapshots the 32 MiB shard in ~215 µs using clonefile(2).
  • Crash-Safe CoW Atomic Layer Update: Clones the live shard to a staging file (apfs.CloneFile), mutates a 1 MiB layer slice via writable mmap, issues a drive flush barrier with F_FULLFSYNC (apfs.FullSync), swaps atomically with os.Rename, and verifies the v1 checkpoint is untouched while the live shard holds v2 weights.

Usage

CGO_ENABLED=0 go run ./examples/kernel/apfs-weight-checkpoint

Measured Output (Apple M4 Max, CGO_ENABLED=0)

apfs-weight-checkpoint (size=32 MiB, temp=/var/folders/kj/qbc32fzd2pv6ngnsysy8vpmw0000gn/T/apfs-weight-ckpt-2058383648)

[1] Created & F_FULLFSYNC'd 32 MiB weight shard in 37.455ms (854.4 MiB/s)
[2] Unified-Memory Weight Streaming (F_NOCACHE + MADV_SEQUENTIAL)
    reduced 32 MiB in 7.542ms (4242.7 MiB/s), checksum=b5e130a462f80f84
    VM reclaim/reuse: file=DontNeed (XNU RO file fallback); anon 4 MiB scratch=FreeReusable -> FreeReuse ok
[3] Instant CoW Checkpoint
    apfs.CloneFile(32 MiB): 215 µs
[4] Crash-Safe CoW Atomic Layer Update (1 MiB slice at +8 MiB)
    CloneFile:   143 µs | Mutate:  2161 µs | FullSync: 5.476ms | Rename:  971 µs
[5] Integrity Verified
    checkpoint v1 checksum=b5e130a462f80f84 (matches pre-update: true)
    live shard v2 checksum=8b83ccd35820074b (updated atomically: true)

Documentation

Rendered for darwin/amd64

Overview

Command apfs-weight-checkpoint demonstrates unified-memory weight streaming with madvise page reclamation and crash-safe APFS CoW atomic checkpointing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL