Skip to content

sptos-region

Memory region management for SPTOS Cognition Kernel

Overview

sptos-region implements the Region primitive from ADR-087. Regions are contiguous, capability-protected memory objects with one of three policies: Immutable, AppendOnly, or Slab. SPTOS does not implement demand paging -- all regions are physically backed at map time, eliminating page faults and swap complexity.

Key Features

  • Three region policies — Immutable (set-once, deduplicatable), AppendOnly (write cursor, max_size), and Slab (fixed-size slots from free list)
  • Slab allocator — Zero-fragmentation fixed-slot allocation with both standard and optimized implementations
  • Optional mmap backing — Linux mmap support via the mmap feature flag
  • Statistics collection — Track allocations, frees, and byte usage with the stats feature
  • no_std compatible — Works without std when the default feature is disabled

Dependencies

Key internal dependencies:

  • sptos-types — Kernel type definitions (RegionHandle, RegionPolicy, KernelError)

Usage

rust
use sptos_region::{RegionManager, RegionConfig, SlabAllocator};
use sptos_types::{RegionPolicy, CapHandle};

let mut manager = RegionManager::new();
let handle = manager.create_region(
    RegionPolicy::slab(64, 1024),
    CapHandle::null(),
)?;

API Reference

Core Types

TypeDescription
RegionManagerCentral manager for creating and accessing regions
RegionConfigConfiguration for region creation
SlabAllocatorFixed-size slot allocator with free-list management
SlabRegionA region backed by slab allocation
AppendOnlyRegionWrite-once append region with cursor tracking
ImmutableRegionSet-once region that cannot be modified after creation
OptimizedSlabAllocatorPerformance-optimized slab allocator variant
RegionStatsStatistics counters (requires stats feature)

Released under the MIT License.