// hakmem_bigcache.h - Big-Block Cache (Box理論) // Purpose: Per-site ring cache for large allocations (>= 1MB) // // License: MIT // Date: 2025-10-21 // Phase 2c: Dynamic hash table implementation #pragma once #include #include #ifdef __cplusplus extern "C" { #endif // ============================================================================ // BigCache Box - サイト別大規模ブロックキャッシュ // ============================================================================ // Phase 2c: Dynamic hash table configuration #define BIGCACHE_INITIAL_CAPACITY 256 // Initial bucket count (power of 2) #define BIGCACHE_MAX_CAPACITY 65536 // Max 64K buckets (power of 2) #define BIGCACHE_LOAD_FACTOR 0.75f // Resize at 75% load #define BIGCACHE_MIN_SIZE 524288 // 512KB minimum for caching // Phase 6.11: Expanded size classes (4 → 8 classes, finer granularity to reduce internal fragmentation) #define BIGCACHE_NUM_CLASSES 8 // Number of size classes (Phase 6.11: increased from 4) #define BIGCACHE_CLASS_512KB 524288 // 512KB size class (NEW) #define BIGCACHE_CLASS_1MB 1048576 // 1MB size class #define BIGCACHE_CLASS_2MB 2097152 // 2MB size class #define BIGCACHE_CLASS_3MB 3145728 // 3MB size class (NEW: reduces fragmentation) #define BIGCACHE_CLASS_4MB 4194304 // 4MB size class #define BIGCACHE_CLASS_6MB 6291456 // 6MB size class (NEW) #define BIGCACHE_CLASS_8MB 8388608 // 8MB size class #define BIGCACHE_CLASS_16MB 16777216 // 16MB size class (NEW) // BigCache API (Box Interface) // Try to get cached block for this site // Returns: 1 if hit (out_ptr set), 0 if miss int hak_bigcache_try_get(size_t size, uintptr_t site, void** out_ptr); // Try to put freed block into cache // Returns: 1 if cached, 0 if rejected (full/not cacheable) int hak_bigcache_put(void* ptr, size_t class_bytes, uintptr_t site); // Initialize BigCache (called from hak_init) void hak_bigcache_init(void); // Cleanup BigCache (called from hak_shutdown) void hak_bigcache_shutdown(void); // Stats (for debugging) void hak_bigcache_print_stats(void); // Set free callback (for proper cleanup on eviction) typedef void (*hak_bigcache_free_fn_t)(void* ptr, size_t size); void hak_bigcache_set_free_callback(hak_bigcache_free_fn_t fn); #ifdef __cplusplus } #endif