Merge separate g_tls_sll_head[] and g_tls_sll_count[] arrays into unified TinyTLSSLL struct to improve L1D cache locality. Expected performance gain: +12-18% from reducing cache line splits (2 loads → 1 load per operation). Changes: - core/hakmem_tiny.h: Add TinyTLSSLL type (16B aligned, head+count+pad) - core/hakmem_tiny.c: Replace separate arrays with g_tls_sll[8] - core/box/tls_sll_box.h: Update Box API (13 sites) for unified access - Updated 32+ files: All g_tls_sll_head[i] → g_tls_sll[i].head - Updated 32+ files: All g_tls_sll_count[i] → g_tls_sll[i].count - core/hakmem_tiny_integrity.h: Unified canary guards - core/box/integrity_box.c: Simplified canary validation - Makefile: Added core/box/tiny_sizeclass_hist_box.o to link Build: ✅ PASS (10K ops sanity test) Warnings: Only pre-existing LTO type mismatches (unrelated) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
53 lines
1.7 KiB
C
53 lines
1.7 KiB
C
// ss_os_acquire_box.h - SuperSlab OS Memory Acquisition Box
|
|
// Purpose: Low-level OS memory allocation (mmap/munmap) for SuperSlabs
|
|
// Box Theory: Encapsulates platform-specific aligned memory allocation
|
|
//
|
|
// Responsibilities:
|
|
// - Aligned mmap allocation (2MB boundary)
|
|
// - OOM diagnostics and error reporting
|
|
// - Global mmap counters
|
|
//
|
|
// Dependencies: None (pure OS interface)
|
|
//
|
|
// License: MIT
|
|
// Date: 2025-11-19
|
|
|
|
#ifndef HAKMEM_SS_OS_ACQUIRE_BOX_H
|
|
#define HAKMEM_SS_OS_ACQUIRE_BOX_H
|
|
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include <stdatomic.h>
|
|
|
|
// ============================================================================
|
|
// Global Counters (for debugging/diagnostics)
|
|
// ============================================================================
|
|
|
|
extern _Atomic uint64_t g_ss_mmap_count;
|
|
extern _Atomic uint64_t g_final_fallback_mmap_count;
|
|
|
|
// ============================================================================
|
|
// OS Acquisition API
|
|
// ============================================================================
|
|
|
|
// Acquire aligned SuperSlab memory from OS via mmap
|
|
//
|
|
// Parameters:
|
|
// size_class: Size class index (0-7, for statistics)
|
|
// ss_size: SuperSlab size in bytes (e.g., 2^21 = 2MB)
|
|
// ss_mask: Alignment mask (ss_size - 1)
|
|
// populate: If true, use MAP_POPULATE to prefault pages
|
|
//
|
|
// Returns: Aligned pointer or NULL on OOM
|
|
//
|
|
// Guarantees:
|
|
// - Returns NULL on OOM (never crashes)
|
|
// - Returned pointer is aligned to ss_size boundary
|
|
// - Logs OOM once per process (not spammy)
|
|
// - Updates g_ss_mmap_count counter
|
|
//
|
|
// Thread-safe: Yes (no shared state mutations except atomic counters)
|
|
void* ss_os_acquire(uint8_t size_class, size_t ss_size, uintptr_t ss_mask, int populate);
|
|
|
|
#endif // HAKMEM_SS_OS_ACQUIRE_BOX_H
|