Files
hakmem/core/box/slab_carve_box.h

173 lines
6.0 KiB
C
Raw Normal View History

Modularize Warm Pool with 3 Box Refactorings - Phase B-3a Complete Objective: Clean up warm pool implementation by extracting inline boxes for statistics, carving, and prefill logic. Achieved full modularity with zero performance regression using aggressive inline optimization. Changes: 1. **Legacy Code Removal** (Phase 0) - Removed unused static __thread prefill_attempt_count variable - Cleaned up duplicate comments - Simplified carve failure handling 2. **Warm Pool Statistics Box** (Phase 1) - New file: core/box/warm_pool_stats_box.h - Inline APIs: warm_pool_record_hit/miss/prefilled() - All statistics recording externalized - Integrated into unified_cache.c - Performance: 0 cost (inlined to direct memory write) 3. **Slab Carving Box** (Phase 2) - New file: core/box/slab_carve_box.h - Inline API: slab_carve_from_ss() - Extracted unified_cache_carve_from_ss() function - Now reusable by other refill paths (P0, etc.) - Performance: 100% inlined, O(slabs) scan unchanged 4. **Warm Pool Prefill Box** (Phase 3) - New file: core/box/warm_pool_prefill_box.h - Inline API: warm_pool_do_prefill() - Extracted prefill loop with configurable budget - WARM_POOL_PREFILL_BUDGET = 3 (tunable) - Cold path optimization (only on empty pool) - Performance: Cold path cost (non-critical) Architecture: - core/front/tiny_unified_cache.c now 40+ lines shorter - Logic distributed to 3 well-defined boxes - Each box has single responsibility (SRP) - Inline compilation preserves hot path performance - LTO (-flto) enables cross-file inlining Performance Results: - 1M allocations: 4.099M ops/s (maintained) - 5M allocations: 4.046M ops/s (maintained) - 55.6% warm pool hit rate (unchanged) - Zero regression on throughput - All three boxes fully inlined by compiler Code Quality Improvements: ✅ Removed legacy unused variables ✅ Separated concerns into specialized boxes ✅ Improved readability and maintainability ✅ Preserved performance via aggressive inline ✅ Enabled future reuse (carve box for P0) Testing: ✅ Compilation: No errors ✅ Functionality: 1M and 5M allocation tests pass ✅ Performance: Baseline maintained ✅ Statistics: Output identical to pre-refactor Next Phase: Consider similar modularization for: - Registry scanning (registry_scan_box.h) - TLS management (tls_management_box.h) - Cache operations (unified_cache_policy_box.h) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 23:39:02 +09:00
// slab_carve_box.h - Slab Carving Box
// Purpose: Unified API for carving blocks from SuperSlabs
// Used by: Warm pool hot path, normal refill path, P0 batch refill
// License: MIT
// Date: 2025-12-04
#ifndef HAK_SLAB_CARVE_BOX_H
#define HAK_SLAB_CARVE_BOX_H
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <stdatomic.h>
Modularize Warm Pool with 3 Box Refactorings - Phase B-3a Complete Objective: Clean up warm pool implementation by extracting inline boxes for statistics, carving, and prefill logic. Achieved full modularity with zero performance regression using aggressive inline optimization. Changes: 1. **Legacy Code Removal** (Phase 0) - Removed unused static __thread prefill_attempt_count variable - Cleaned up duplicate comments - Simplified carve failure handling 2. **Warm Pool Statistics Box** (Phase 1) - New file: core/box/warm_pool_stats_box.h - Inline APIs: warm_pool_record_hit/miss/prefilled() - All statistics recording externalized - Integrated into unified_cache.c - Performance: 0 cost (inlined to direct memory write) 3. **Slab Carving Box** (Phase 2) - New file: core/box/slab_carve_box.h - Inline API: slab_carve_from_ss() - Extracted unified_cache_carve_from_ss() function - Now reusable by other refill paths (P0, etc.) - Performance: 100% inlined, O(slabs) scan unchanged 4. **Warm Pool Prefill Box** (Phase 3) - New file: core/box/warm_pool_prefill_box.h - Inline API: warm_pool_do_prefill() - Extracted prefill loop with configurable budget - WARM_POOL_PREFILL_BUDGET = 3 (tunable) - Cold path optimization (only on empty pool) - Performance: Cold path cost (non-critical) Architecture: - core/front/tiny_unified_cache.c now 40+ lines shorter - Logic distributed to 3 well-defined boxes - Each box has single responsibility (SRP) - Inline compilation preserves hot path performance - LTO (-flto) enables cross-file inlining Performance Results: - 1M allocations: 4.099M ops/s (maintained) - 5M allocations: 4.046M ops/s (maintained) - 55.6% warm pool hit rate (unchanged) - Zero regression on throughput - All three boxes fully inlined by compiler Code Quality Improvements: ✅ Removed legacy unused variables ✅ Separated concerns into specialized boxes ✅ Improved readability and maintainability ✅ Preserved performance via aggressive inline ✅ Enabled future reuse (carve box for P0) Testing: ✅ Compilation: No errors ✅ Functionality: 1M and 5M allocation tests pass ✅ Performance: Baseline maintained ✅ Statistics: Output identical to pre-refactor Next Phase: Consider similar modularization for: - Registry scanning (registry_scan_box.h) - TLS management (tls_management_box.h) - Cache operations (unified_cache_policy_box.h) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 23:39:02 +09:00
#include "../hakmem_tiny_config.h"
#include "../hakmem_tiny_superslab.h"
#include "../superslab/superslab_inline.h"
#include "../tiny_box_geometry.h"
#include "../box/tiny_next_ptr_box.h"
#include "../box/pagefault_telemetry_box.h"
#include "c7_meta_used_counter_box.h"
Modularize Warm Pool with 3 Box Refactorings - Phase B-3a Complete Objective: Clean up warm pool implementation by extracting inline boxes for statistics, carving, and prefill logic. Achieved full modularity with zero performance regression using aggressive inline optimization. Changes: 1. **Legacy Code Removal** (Phase 0) - Removed unused static __thread prefill_attempt_count variable - Cleaned up duplicate comments - Simplified carve failure handling 2. **Warm Pool Statistics Box** (Phase 1) - New file: core/box/warm_pool_stats_box.h - Inline APIs: warm_pool_record_hit/miss/prefilled() - All statistics recording externalized - Integrated into unified_cache.c - Performance: 0 cost (inlined to direct memory write) 3. **Slab Carving Box** (Phase 2) - New file: core/box/slab_carve_box.h - Inline API: slab_carve_from_ss() - Extracted unified_cache_carve_from_ss() function - Now reusable by other refill paths (P0, etc.) - Performance: 100% inlined, O(slabs) scan unchanged 4. **Warm Pool Prefill Box** (Phase 3) - New file: core/box/warm_pool_prefill_box.h - Inline API: warm_pool_do_prefill() - Extracted prefill loop with configurable budget - WARM_POOL_PREFILL_BUDGET = 3 (tunable) - Cold path optimization (only on empty pool) - Performance: Cold path cost (non-critical) Architecture: - core/front/tiny_unified_cache.c now 40+ lines shorter - Logic distributed to 3 well-defined boxes - Each box has single responsibility (SRP) - Inline compilation preserves hot path performance - LTO (-flto) enables cross-file inlining Performance Results: - 1M allocations: 4.099M ops/s (maintained) - 5M allocations: 4.046M ops/s (maintained) - 55.6% warm pool hit rate (unchanged) - Zero regression on throughput - All three boxes fully inlined by compiler Code Quality Improvements: ✅ Removed legacy unused variables ✅ Separated concerns into specialized boxes ✅ Improved readability and maintainability ✅ Preserved performance via aggressive inline ✅ Enabled future reuse (carve box for P0) Testing: ✅ Compilation: No errors ✅ Functionality: 1M and 5M allocation tests pass ✅ Performance: Baseline maintained ✅ Statistics: Output identical to pre-refactor Next Phase: Consider similar modularization for: - Registry scanning (registry_scan_box.h) - TLS management (tls_management_box.h) - Cache operations (unified_cache_policy_box.h) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 23:39:02 +09:00
// ============================================================================
// Slab Carving API (Inline for Hot Path)
// ============================================================================
// Try to carve blocks directly from a SuperSlab
// Returns: Number of blocks produced (0 if carve failed)
//
// Parameters:
// class_idx - Allocation class (determines block size)
// ss - Target SuperSlab to carve from
// out - Output buffer for carved blocks
// max_blocks - Maximum blocks to carve
//
// Algorithm:
// 1. Validate SuperSlab magic
// 2. Scan all slabs in SuperSlab for class match
// 3. For each matching slab:
// a. Try freelist first (if available)
// b. Fall back to linear carve (if capacity available)
// c. Stop when max_blocks reached
// 4. Return total blocks carved
//
// Performance: O(slabs_in_ss) linear scan, typically 3-4 iterations
//
static inline int slab_carve_from_ss(int class_idx, SuperSlab* ss,
void** out, int max_blocks) {
if (!ss || ss->magic != SUPERSLAB_MAGIC) return 0;
// Find an available slab in this SuperSlab
int cap = ss_slabs_capacity(ss);
#if HAKMEM_BUILD_RELEASE
static _Atomic int rel_c7_meta_logged = 0;
TinySlabMeta* rel_c7_meta = NULL;
int rel_c7_meta_idx = -1;
#else
static __thread int dbg_c7_meta_logged = 0;
TinySlabMeta* dbg_c7_meta = NULL;
int dbg_c7_meta_idx = -1;
#endif
Modularize Warm Pool with 3 Box Refactorings - Phase B-3a Complete Objective: Clean up warm pool implementation by extracting inline boxes for statistics, carving, and prefill logic. Achieved full modularity with zero performance regression using aggressive inline optimization. Changes: 1. **Legacy Code Removal** (Phase 0) - Removed unused static __thread prefill_attempt_count variable - Cleaned up duplicate comments - Simplified carve failure handling 2. **Warm Pool Statistics Box** (Phase 1) - New file: core/box/warm_pool_stats_box.h - Inline APIs: warm_pool_record_hit/miss/prefilled() - All statistics recording externalized - Integrated into unified_cache.c - Performance: 0 cost (inlined to direct memory write) 3. **Slab Carving Box** (Phase 2) - New file: core/box/slab_carve_box.h - Inline API: slab_carve_from_ss() - Extracted unified_cache_carve_from_ss() function - Now reusable by other refill paths (P0, etc.) - Performance: 100% inlined, O(slabs) scan unchanged 4. **Warm Pool Prefill Box** (Phase 3) - New file: core/box/warm_pool_prefill_box.h - Inline API: warm_pool_do_prefill() - Extracted prefill loop with configurable budget - WARM_POOL_PREFILL_BUDGET = 3 (tunable) - Cold path optimization (only on empty pool) - Performance: Cold path cost (non-critical) Architecture: - core/front/tiny_unified_cache.c now 40+ lines shorter - Logic distributed to 3 well-defined boxes - Each box has single responsibility (SRP) - Inline compilation preserves hot path performance - LTO (-flto) enables cross-file inlining Performance Results: - 1M allocations: 4.099M ops/s (maintained) - 5M allocations: 4.046M ops/s (maintained) - 55.6% warm pool hit rate (unchanged) - Zero regression on throughput - All three boxes fully inlined by compiler Code Quality Improvements: ✅ Removed legacy unused variables ✅ Separated concerns into specialized boxes ✅ Improved readability and maintainability ✅ Preserved performance via aggressive inline ✅ Enabled future reuse (carve box for P0) Testing: ✅ Compilation: No errors ✅ Functionality: 1M and 5M allocation tests pass ✅ Performance: Baseline maintained ✅ Statistics: Output identical to pre-refactor Next Phase: Consider similar modularization for: - Registry scanning (registry_scan_box.h) - TLS management (tls_management_box.h) - Cache operations (unified_cache_policy_box.h) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 23:39:02 +09:00
for (int slab_idx = 0; slab_idx < cap; slab_idx++) {
TinySlabMeta* meta = &ss->slabs[slab_idx];
// Check if this slab matches our class and has capacity
if (meta->class_idx != (uint8_t)class_idx) continue;
#if HAKMEM_BUILD_RELEASE
if (class_idx == 7 && atomic_load_explicit(&rel_c7_meta_logged, memory_order_relaxed) == 0 && !rel_c7_meta) {
rel_c7_meta = meta;
rel_c7_meta_idx = slab_idx;
}
#else
if (class_idx == 7 && dbg_c7_meta_logged == 0 && !dbg_c7_meta) {
dbg_c7_meta = meta;
dbg_c7_meta_idx = slab_idx;
}
#endif
Modularize Warm Pool with 3 Box Refactorings - Phase B-3a Complete Objective: Clean up warm pool implementation by extracting inline boxes for statistics, carving, and prefill logic. Achieved full modularity with zero performance regression using aggressive inline optimization. Changes: 1. **Legacy Code Removal** (Phase 0) - Removed unused static __thread prefill_attempt_count variable - Cleaned up duplicate comments - Simplified carve failure handling 2. **Warm Pool Statistics Box** (Phase 1) - New file: core/box/warm_pool_stats_box.h - Inline APIs: warm_pool_record_hit/miss/prefilled() - All statistics recording externalized - Integrated into unified_cache.c - Performance: 0 cost (inlined to direct memory write) 3. **Slab Carving Box** (Phase 2) - New file: core/box/slab_carve_box.h - Inline API: slab_carve_from_ss() - Extracted unified_cache_carve_from_ss() function - Now reusable by other refill paths (P0, etc.) - Performance: 100% inlined, O(slabs) scan unchanged 4. **Warm Pool Prefill Box** (Phase 3) - New file: core/box/warm_pool_prefill_box.h - Inline API: warm_pool_do_prefill() - Extracted prefill loop with configurable budget - WARM_POOL_PREFILL_BUDGET = 3 (tunable) - Cold path optimization (only on empty pool) - Performance: Cold path cost (non-critical) Architecture: - core/front/tiny_unified_cache.c now 40+ lines shorter - Logic distributed to 3 well-defined boxes - Each box has single responsibility (SRP) - Inline compilation preserves hot path performance - LTO (-flto) enables cross-file inlining Performance Results: - 1M allocations: 4.099M ops/s (maintained) - 5M allocations: 4.046M ops/s (maintained) - 55.6% warm pool hit rate (unchanged) - Zero regression on throughput - All three boxes fully inlined by compiler Code Quality Improvements: ✅ Removed legacy unused variables ✅ Separated concerns into specialized boxes ✅ Improved readability and maintainability ✅ Preserved performance via aggressive inline ✅ Enabled future reuse (carve box for P0) Testing: ✅ Compilation: No errors ✅ Functionality: 1M and 5M allocation tests pass ✅ Performance: Baseline maintained ✅ Statistics: Output identical to pre-refactor Next Phase: Consider similar modularization for: - Registry scanning (registry_scan_box.h) - TLS management (tls_management_box.h) - Cache operations (unified_cache_policy_box.h) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 23:39:02 +09:00
if (meta->used >= meta->capacity && !meta->freelist) continue;
// Carve blocks from this slab
size_t bs = tiny_stride_for_class(class_idx);
uint8_t* base = tiny_slab_base_for_geometry(ss, slab_idx);
int produced = 0;
while (produced < max_blocks) {
void* p = NULL;
if (meta->freelist) {
// Pop from freelist
p = meta->freelist;
void* next_node = tiny_next_read(class_idx, p);
#if HAKMEM_TINY_HEADER_CLASSIDX
*(uint8_t*)p = (uint8_t)(0xa0 | (class_idx & 0x0f));
__atomic_thread_fence(__ATOMIC_RELEASE);
#endif
meta->freelist = next_node;
meta->used++;
c7_meta_used_note(class_idx, C7_META_USED_SRC_FRONT);
Modularize Warm Pool with 3 Box Refactorings - Phase B-3a Complete Objective: Clean up warm pool implementation by extracting inline boxes for statistics, carving, and prefill logic. Achieved full modularity with zero performance regression using aggressive inline optimization. Changes: 1. **Legacy Code Removal** (Phase 0) - Removed unused static __thread prefill_attempt_count variable - Cleaned up duplicate comments - Simplified carve failure handling 2. **Warm Pool Statistics Box** (Phase 1) - New file: core/box/warm_pool_stats_box.h - Inline APIs: warm_pool_record_hit/miss/prefilled() - All statistics recording externalized - Integrated into unified_cache.c - Performance: 0 cost (inlined to direct memory write) 3. **Slab Carving Box** (Phase 2) - New file: core/box/slab_carve_box.h - Inline API: slab_carve_from_ss() - Extracted unified_cache_carve_from_ss() function - Now reusable by other refill paths (P0, etc.) - Performance: 100% inlined, O(slabs) scan unchanged 4. **Warm Pool Prefill Box** (Phase 3) - New file: core/box/warm_pool_prefill_box.h - Inline API: warm_pool_do_prefill() - Extracted prefill loop with configurable budget - WARM_POOL_PREFILL_BUDGET = 3 (tunable) - Cold path optimization (only on empty pool) - Performance: Cold path cost (non-critical) Architecture: - core/front/tiny_unified_cache.c now 40+ lines shorter - Logic distributed to 3 well-defined boxes - Each box has single responsibility (SRP) - Inline compilation preserves hot path performance - LTO (-flto) enables cross-file inlining Performance Results: - 1M allocations: 4.099M ops/s (maintained) - 5M allocations: 4.046M ops/s (maintained) - 55.6% warm pool hit rate (unchanged) - Zero regression on throughput - All three boxes fully inlined by compiler Code Quality Improvements: ✅ Removed legacy unused variables ✅ Separated concerns into specialized boxes ✅ Improved readability and maintainability ✅ Preserved performance via aggressive inline ✅ Enabled future reuse (carve box for P0) Testing: ✅ Compilation: No errors ✅ Functionality: 1M and 5M allocation tests pass ✅ Performance: Baseline maintained ✅ Statistics: Output identical to pre-refactor Next Phase: Consider similar modularization for: - Registry scanning (registry_scan_box.h) - TLS management (tls_management_box.h) - Cache operations (unified_cache_policy_box.h) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 23:39:02 +09:00
} else if (meta->carved < meta->capacity) {
// Linear carve
p = (void*)(base + ((size_t)meta->carved * bs));
#if HAKMEM_TINY_HEADER_CLASSIDX
*(uint8_t*)p = (uint8_t)(0xa0 | (class_idx & 0x0f));
#endif
meta->carved++;
meta->used++;
c7_meta_used_note(class_idx, C7_META_USED_SRC_FRONT);
Modularize Warm Pool with 3 Box Refactorings - Phase B-3a Complete Objective: Clean up warm pool implementation by extracting inline boxes for statistics, carving, and prefill logic. Achieved full modularity with zero performance regression using aggressive inline optimization. Changes: 1. **Legacy Code Removal** (Phase 0) - Removed unused static __thread prefill_attempt_count variable - Cleaned up duplicate comments - Simplified carve failure handling 2. **Warm Pool Statistics Box** (Phase 1) - New file: core/box/warm_pool_stats_box.h - Inline APIs: warm_pool_record_hit/miss/prefilled() - All statistics recording externalized - Integrated into unified_cache.c - Performance: 0 cost (inlined to direct memory write) 3. **Slab Carving Box** (Phase 2) - New file: core/box/slab_carve_box.h - Inline API: slab_carve_from_ss() - Extracted unified_cache_carve_from_ss() function - Now reusable by other refill paths (P0, etc.) - Performance: 100% inlined, O(slabs) scan unchanged 4. **Warm Pool Prefill Box** (Phase 3) - New file: core/box/warm_pool_prefill_box.h - Inline API: warm_pool_do_prefill() - Extracted prefill loop with configurable budget - WARM_POOL_PREFILL_BUDGET = 3 (tunable) - Cold path optimization (only on empty pool) - Performance: Cold path cost (non-critical) Architecture: - core/front/tiny_unified_cache.c now 40+ lines shorter - Logic distributed to 3 well-defined boxes - Each box has single responsibility (SRP) - Inline compilation preserves hot path performance - LTO (-flto) enables cross-file inlining Performance Results: - 1M allocations: 4.099M ops/s (maintained) - 5M allocations: 4.046M ops/s (maintained) - 55.6% warm pool hit rate (unchanged) - Zero regression on throughput - All three boxes fully inlined by compiler Code Quality Improvements: ✅ Removed legacy unused variables ✅ Separated concerns into specialized boxes ✅ Improved readability and maintainability ✅ Preserved performance via aggressive inline ✅ Enabled future reuse (carve box for P0) Testing: ✅ Compilation: No errors ✅ Functionality: 1M and 5M allocation tests pass ✅ Performance: Baseline maintained ✅ Statistics: Output identical to pre-refactor Next Phase: Consider similar modularization for: - Registry scanning (registry_scan_box.h) - TLS management (tls_management_box.h) - Cache operations (unified_cache_policy_box.h) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 23:39:02 +09:00
} else {
break; // This slab exhausted
}
if (p) {
pagefault_telemetry_touch(class_idx, p);
out[produced++] = p;
}
}
if (produced > 0) return produced;
// If this slab had no freelist and no carved capacity, continue to next
}
#if !HAKMEM_BUILD_RELEASE
static __thread int dbg_c7_slab_carve_zero_logs = 0;
if (class_idx == 7 && dbg_c7_slab_carve_zero_logs < 10) {
fprintf(stderr, "[C7_SLAB_CARVE_ZERO] ss=%p no blocks carved\n", (void*)ss);
dbg_c7_slab_carve_zero_logs++;
}
#endif
#if HAKMEM_BUILD_RELEASE
if (class_idx == 7 &&
atomic_load_explicit(&rel_c7_meta_logged, memory_order_relaxed) == 0 &&
rel_c7_meta) {
size_t bs = tiny_stride_for_class(class_idx);
fprintf(stderr,
"[REL_C7_CARVE_META] ss=%p slab=%d cls=%u used=%u cap=%u carved=%u freelist=%p stride=%zu slabs_cap=%d\n",
(void*)ss,
rel_c7_meta_idx,
(unsigned)rel_c7_meta->class_idx,
(unsigned)rel_c7_meta->used,
(unsigned)rel_c7_meta->capacity,
(unsigned)rel_c7_meta->carved,
rel_c7_meta->freelist,
bs,
cap);
atomic_store_explicit(&rel_c7_meta_logged, 1, memory_order_relaxed);
}
#else
if (class_idx == 7 && dbg_c7_meta_logged == 0 && dbg_c7_meta) {
size_t bs = tiny_stride_for_class(class_idx);
fprintf(stderr,
"[DBG_C7_CARVE_META] ss=%p slab=%d cls=%u used=%u cap=%u carved=%u freelist=%p stride=%zu slabs_cap=%d\n",
(void*)ss,
dbg_c7_meta_idx,
(unsigned)dbg_c7_meta->class_idx,
(unsigned)dbg_c7_meta->used,
(unsigned)dbg_c7_meta->capacity,
(unsigned)dbg_c7_meta->carved,
dbg_c7_meta->freelist,
bs,
cap);
dbg_c7_meta_logged = 1;
}
#endif
Modularize Warm Pool with 3 Box Refactorings - Phase B-3a Complete Objective: Clean up warm pool implementation by extracting inline boxes for statistics, carving, and prefill logic. Achieved full modularity with zero performance regression using aggressive inline optimization. Changes: 1. **Legacy Code Removal** (Phase 0) - Removed unused static __thread prefill_attempt_count variable - Cleaned up duplicate comments - Simplified carve failure handling 2. **Warm Pool Statistics Box** (Phase 1) - New file: core/box/warm_pool_stats_box.h - Inline APIs: warm_pool_record_hit/miss/prefilled() - All statistics recording externalized - Integrated into unified_cache.c - Performance: 0 cost (inlined to direct memory write) 3. **Slab Carving Box** (Phase 2) - New file: core/box/slab_carve_box.h - Inline API: slab_carve_from_ss() - Extracted unified_cache_carve_from_ss() function - Now reusable by other refill paths (P0, etc.) - Performance: 100% inlined, O(slabs) scan unchanged 4. **Warm Pool Prefill Box** (Phase 3) - New file: core/box/warm_pool_prefill_box.h - Inline API: warm_pool_do_prefill() - Extracted prefill loop with configurable budget - WARM_POOL_PREFILL_BUDGET = 3 (tunable) - Cold path optimization (only on empty pool) - Performance: Cold path cost (non-critical) Architecture: - core/front/tiny_unified_cache.c now 40+ lines shorter - Logic distributed to 3 well-defined boxes - Each box has single responsibility (SRP) - Inline compilation preserves hot path performance - LTO (-flto) enables cross-file inlining Performance Results: - 1M allocations: 4.099M ops/s (maintained) - 5M allocations: 4.046M ops/s (maintained) - 55.6% warm pool hit rate (unchanged) - Zero regression on throughput - All three boxes fully inlined by compiler Code Quality Improvements: ✅ Removed legacy unused variables ✅ Separated concerns into specialized boxes ✅ Improved readability and maintainability ✅ Preserved performance via aggressive inline ✅ Enabled future reuse (carve box for P0) Testing: ✅ Compilation: No errors ✅ Functionality: 1M and 5M allocation tests pass ✅ Performance: Baseline maintained ✅ Statistics: Output identical to pre-refactor Next Phase: Consider similar modularization for: - Registry scanning (registry_scan_box.h) - TLS management (tls_management_box.h) - Cache operations (unified_cache_policy_box.h) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 23:39:02 +09:00
return 0; // No slab in this SuperSlab had available capacity
}
#endif // HAK_SLAB_CARVE_BOX_H