Changes: - SUPERSLAB_LG_MIN: 20 → 19 (1MB → 512KB) - SUPERSLAB_LG_DEFAULT: 21 → 19 (2MB → 512KB) - SUPERSLAB_LG_MAX: 21 (unchanged, still allows 2MB) Benchmark Results: - ws=256: 72M → 79.80M ops/s (+10.8%, +7.8M ops/s) - ws=1024: 56.71M → 65.07M ops/s (+14.7%, +8.36M ops/s) Expected: +3-5% improvement Actual: +10-15% improvement (EXCEEDED PREDICTION!) Root Cause Analysis: - Perf analysis showed shared_pool_acquire_slab at 23.83% CPU time - Phase 1 removed memset overhead (+1.3%) - Phase 2 reduces mmap allocation size by 75% (2MB → 512KB) - Fewer page faults during SuperSlab initialization - Better memory granularity (less VA space waste) - Smaller allocations complete faster even without page faults Technical Details: - Each SuperSlab contains 8 slabs of 64KB (total 512KB) - Previous: 16-32 slabs per SuperSlab (1-2MB) - New: 8 slabs per SuperSlab (512KB) - Refill frequency increases slightly, but init cost dominates - Net effect: Major throughput improvement Phase 1+2 Cumulative Improvement: - Baseline: 64.61M ops/s - Phase 1 final: 72.92M ops/s (+12.9%) - Phase 2 final: 79.80M ops/s (+23.5% total, +9.4% over Phase 1) Files Modified: - core/hakmem_tiny_superslab_constants.h:12-33 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
84 lines
3.2 KiB
C
84 lines
3.2 KiB
C
// hakmem_tiny_superslab_constants.h - SuperSlab Layout Constants
|
|
// Purpose: Centralize all SuperSlab layout magic numbers
|
|
// Phase 6-2.5: Created to fix sizeof(SuperSlab) vs hardcoded offset mismatch
|
|
|
|
#ifndef HAKMEM_TINY_SUPERSLAB_CONSTANTS_H
|
|
#define HAKMEM_TINY_SUPERSLAB_CONSTANTS_H
|
|
|
|
// ============================================================================
|
|
// SuperSlab Layout Constants
|
|
// ============================================================================
|
|
|
|
// Log2 range for SuperSlab sizes:
|
|
// - MIN: 512KB (2^19) - Phase 2 optimization: reduced from 1MB
|
|
// - MAX: 2MB (2^21) - unchanged
|
|
// - DEFAULT: 512KB (2^19) - Phase 2 optimization: reduced from 2MB
|
|
//
|
|
// Phase 2-Opt2: Reduce SuperSlab size to minimize initialization cost
|
|
// Benefit: 75% reduction in allocation size (2MB → 512KB)
|
|
// Expected: +3-5% throughput improvement
|
|
// Rationale:
|
|
// - Smaller SuperSlab = fewer page faults during allocation
|
|
// - Better memory granularity (less wasted VA space)
|
|
// - Memset already removed in Phase 1, so pure allocation overhead
|
|
// - Perf analysis showed shared_pool_acquire_slab at 23.83% CPU time
|
|
#ifndef SUPERSLAB_LG_MIN
|
|
#define SUPERSLAB_LG_MIN 19
|
|
#endif
|
|
#ifndef SUPERSLAB_LG_MAX
|
|
#define SUPERSLAB_LG_MAX 21
|
|
#endif
|
|
#ifndef SUPERSLAB_LG_DEFAULT
|
|
#define SUPERSLAB_LG_DEFAULT 19
|
|
#endif
|
|
|
|
// Size of each slab within SuperSlab (fixed, never changes)
|
|
#define SLAB_SIZE (64 * 1024) // 64KB per slab
|
|
|
|
// SuperSlab struct size (as of P1.1)
|
|
// Actual value: sizeof(SuperSlab) = 1192 bytes
|
|
// This includes: magic, lg_size, size_class, total_active_blocks,
|
|
// remote_heads[], slabs[], slab_listed[], class_map[], etc.
|
|
// P1.1: Added class_map[32] (+32 bytes) for out-of-band class_idx lookup
|
|
#define SUPERSLAB_HEADER_SIZE 1192
|
|
|
|
// Slab 0 data offset (CRITICAL: Must be aligned to largest block size)
|
|
// Phase 6-2.5 FIX: Changed from 1024 to 2048
|
|
//
|
|
// Why 2048?
|
|
// - sizeof(SuperSlab) = 1088 bytes
|
|
// - Largest block size = 1024 bytes (class 7)
|
|
// - Must round up to next 1024-byte boundary: (1088 + 1023) & ~1023 = 2048
|
|
//
|
|
// Layout:
|
|
// [0..1087] SuperSlab header (1088 bytes)
|
|
// [1088..2047] Padding (960 bytes, unused)
|
|
// [2048..65535] Slab 0 data (63488 bytes = 64KB - 2048)
|
|
//
|
|
// Previous value (1024) caused:
|
|
// - 64-byte overlap with SuperSlab metadata (corruption)
|
|
// - Misalignment for class 7 allocations (1024 % 1024 != 0)
|
|
#define SUPERSLAB_SLAB0_DATA_OFFSET 2048
|
|
|
|
// Slab 0 usable size (for capacity calculation)
|
|
#define SUPERSLAB_SLAB0_USABLE_SIZE (SLAB_SIZE - SUPERSLAB_SLAB0_DATA_OFFSET) // 63488 bytes
|
|
|
|
// Regular slab (i > 0) usable size
|
|
#define SUPERSLAB_SLAB_USABLE_SIZE SLAB_SIZE // 65536 bytes
|
|
|
|
// ============================================================================
|
|
// Validation (compile-time check)
|
|
// ============================================================================
|
|
|
|
// Ensure SLAB0_DATA_OFFSET is aligned to largest block size (1024)
|
|
#if (SUPERSLAB_SLAB0_DATA_OFFSET % 1024) != 0
|
|
#error "SUPERSLAB_SLAB0_DATA_OFFSET must be 1024-byte aligned for class 7"
|
|
#endif
|
|
|
|
// Ensure SLAB0_DATA_OFFSET is large enough to contain SuperSlab header
|
|
#if SUPERSLAB_SLAB0_DATA_OFFSET < SUPERSLAB_HEADER_SIZE
|
|
#error "SUPERSLAB_SLAB0_DATA_OFFSET must be >= sizeof(SuperSlab)"
|
|
#endif
|
|
|
|
#endif // HAKMEM_TINY_SUPERSLAB_CONSTANTS_H
|