purgeable-kv-pool

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

purgeable-kv-pool

Demonstrates kernel-synchronous volatile KV/prefix cache slabs backed by Darwin mach_vm_allocate(..., VM_FLAGS_PURGABLE) and mach_vm_purgable_control using x/purgeable and x/mempressure with zero cgo (CGO_ENABLED=0).

What it demonstrates

  1. Purgeable slab pool allocation & population: allocates a configurable pool of fixed-size Mach VM purgeable slabs (default 256 MiB: 64 × 4 MiB) and populates deterministic page-strided prefix blocks with checksums.
  2. Kernel-synchronous volatile transitions (NonVolatile -> Volatile -> NonVolatile): releases slabs to VM_PURGABLE_VOLATILE (FIFO or LIFO), re-acquires them as VM_PURGABLE_NONVOLATILE, verifies every intact slab's checksum, and benchmarks per-slab transition latency (µs/slab).
  3. VM_PURGABLE_EMPTY and ErrPurged semantics: explicitly empties a probe slab via Slab.MarkEmpty(), verifies Slab.State() == Empty, verifies Slab.Pin() returns purgeable.ErrPurged while leaving the slab NonVolatile and zero-filled, and empties the entire idle pool via Pool.MarkAllEmpty() to confirm accurate purged-slab accounting.
  4. Live Darwin VM accounting (x/mempressure.Snapshot()): tracks PhysFootprint (jetsam ledger) and ResidentSize across every lifecycle phase. Marking slabs Volatile removes them from PhysFootprint immediately while keeping their physical pages warm in ResidentSize; MarkAllEmpty() reclaims the physical pages immediately while preserving virtual address reservations.

Usage

# Default 256 MiB pool (64 x 4 MiB slabs, FIFO)
CGO_ENABLED=0 go run ./examples/kernel/purgeable-kv-pool

# 512 MiB pool with LIFO eviction behavior
CGO_ENABLED=0 go run ./examples/kernel/purgeable-kv-pool -size-mib=512 -behavior=lifo

# Run package and example tests
CGO_ENABLED=0 go test -v -count=1 ./x/purgeable ./examples/kernel/purgeable-kv-pool

Measured Results

Hardware & OS: Apple M4 Max, macOS 26.6.2 (25G83), Go 1.27.0 darwin/arm64, CGO_ENABLED=0.

Summary Table
Pool Size Slabs Behavior Release (NonVolatile -> Volatile) Acquire (Volatile -> NonVolatile) Full Round-Trip Volatile PhysFootprint Delta Volatile ResidentSize Delta Post-MarkAllEmpty ResidentSize Delta
256 MiB 64 × 4 MiB fifo 1.89 µs/slab 1.57 µs/slab 3.46 µs/slab +0.19 MiB (from +256.17 MiB) +256.09 MiB +0.56 MiB
512 MiB 128 × 4 MiB lifo 1.57 µs/slab 1.45 µs/slab 3.02 µs/slab +0.30 MiB (from +512.30 MiB) +512.08 MiB +1.05 MiB
256 MiB Default Run (fifo)
purgeable-kv-pool: total=256 MiB (64 slabs x 4 MiB), behavior=fifo, bench-iters=20

[1] Populate deterministic prefix blocks
    elapsed: 101.945ms (2511.2 MiB/s)

[2] NonVolatile -> Volatile -> NonVolatile Verification
    intact slabs: 64/64 (kernel-purged: 0), checksums ok: true

[3] Transition Latency (20 rounds x 64 slabs)
    MarkVolatile (Release):    1.89 µs/slab
    MarkNonVolatile (Acquire): 1.57 µs/slab
    Full round-trip:           3.46 µs/slab

[4] VM_PURGABLE_EMPTY & ErrPurged Verification
    single-slab State()==Empty: true, Pin()==ErrPurged: true, zeroed: true
    pool MarkAllEmpty detected purged slabs: 64/64

[5] x/mempressure.Snapshot() Footprint Deltas (vs baseline)
    Phase                        PhysFoot MiB    Delta MiB Resident MiB    Delta MiB
    baseline                             4.03        +0.00         5.88        +0.00
    populated (NonVolatile)            260.20      +256.17       261.95      +256.08
    marked Volatile                      4.22        +0.19       261.97      +256.09
    re-acquired (NonVolatile)          260.22      +256.19       261.97      +256.09
    after MarkAllEmpty                   4.64        +0.61         6.44        +0.56
    after Close                          4.53        +0.50         6.45        +0.58
512 MiB Run (lifo)
purgeable-kv-pool: total=512 MiB (128 slabs x 4 MiB), behavior=lifo, bench-iters=20

[1] Populate deterministic prefix blocks
    elapsed: 432.896ms (1182.7 MiB/s)

[2] NonVolatile -> Volatile -> NonVolatile Verification
    intact slabs: 128/128 (kernel-purged: 0), checksums ok: true

[3] Transition Latency (20 rounds x 128 slabs)
    MarkVolatile (Release):    1.57 µs/slab
    MarkNonVolatile (Acquire): 1.45 µs/slab
    Full round-trip:           3.02 µs/slab

[4] VM_PURGABLE_EMPTY & ErrPurged Verification
    single-slab State()==Empty: true, Pin()==ErrPurged: true, zeroed: true
    pool MarkAllEmpty detected purged slabs: 128/128

[5] x/mempressure.Snapshot() Footprint Deltas (vs baseline)
    Phase                        PhysFoot MiB    Delta MiB Resident MiB    Delta MiB
    baseline                             3.95        +0.00         5.78        +0.00
    populated (NonVolatile)            516.25      +512.30       517.86      +512.08
    marked Volatile                      4.25        +0.30       517.86      +512.08
    re-acquired (NonVolatile)          516.39      +512.44       518.00      +512.22
    after MarkAllEmpty                   5.20        +1.25         6.83        +1.05
    after Close                          5.02        +1.06         6.89        +1.11

Documentation

Rendered for darwin/amd64

Overview

Command purgeable-kv-pool demonstrates kernel-synchronous volatile KV/prefix cache slabs backed by Darwin mach_vm_purgable_control via x/purgeable, paired with live process footprint accounting from x/mempressure.

Jump to

Keyboard shortcuts

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