diff --git a/core/box/warm_pool_prefill_box.h b/core/box/warm_pool_prefill_box.h index 89769c65..dc3f764a 100644 --- a/core/box/warm_pool_prefill_box.h +++ b/core/box/warm_pool_prefill_box.h @@ -24,7 +24,7 @@ extern SuperSlab* superslab_refill(int class_idx); // Prefill budget: How many additional SuperSlabs to load when pool is empty // - If pool is empty, load PREFILL_BUDGET extra slabs to build working set // - This avoids repeated registry scans on rapid cache misses -// - Set to 2 to balance between prefill lock overhead and pool depletion +// - Phase 2: Keep at 2 (increasing to 4 caused contention regression -1.5%) #define WARM_POOL_PREFILL_BUDGET 2 // ============================================================================ diff --git a/core/front/tiny_warm_pool.h b/core/front/tiny_warm_pool.h index 2df32d86..03b3d75b 100644 --- a/core/front/tiny_warm_pool.h +++ b/core/front/tiny_warm_pool.h @@ -39,10 +39,10 @@ // Maximum warm SuperSlabs per thread per class (tunable) // Trade-off: Working set size vs warm pool effectiveness -// - 4: Original (90% hit rate expected, but broken implementation) -// - 16: Increased to compensate for suboptimal push logic +// - 4: Original (90% hit rate expected, but broken implementation - hardcoded prefill threshold) +// - 12: Optimized capacity with matching prefill threshold (Phase 1) // - Higher values: More memory but better locality -#define TINY_WARM_POOL_MAX_PER_CLASS 16 +#define TINY_WARM_POOL_MAX_PER_CLASS 12 typedef struct { SuperSlab* slabs[TINY_WARM_POOL_MAX_PER_CLASS]; @@ -107,16 +107,16 @@ static inline int tiny_warm_pool_count(int class_idx) { // ============================================================================ // Get warm pool capacity from environment (configurable at runtime) -// ENV: HAKMEM_WARM_POOL_SIZE=N (default: 4) +// ENV: HAKMEM_WARM_POOL_SIZE=N (default: 12) static inline int warm_pool_max_per_class(void) { static int g_max = -1; if (__builtin_expect(g_max == -1, 0)) { const char* env = getenv("HAKMEM_WARM_POOL_SIZE"); if (env && *env) { int v = atoi(env); - // Clamp to valid range [1, 16] + // Clamp to valid range [1, 12] if (v < 1) v = 1; - if (v > 16) v = 16; + if (v > 12) v = 12; g_max = v; } else { g_max = TINY_WARM_POOL_MAX_PER_CLASS; diff --git a/core/hakmem_shared_pool_acquire.c b/core/hakmem_shared_pool_acquire.c index 3b44f948..c74fc91e 100644 --- a/core/hakmem_shared_pool_acquire.c +++ b/core/hakmem_shared_pool_acquire.c @@ -83,7 +83,8 @@ sp_acquire_from_empty_scan(int class_idx, SuperSlab** ss_out, int* slab_idx_out, // WARM POOL PREFILL: Add HOT SuperSlabs to warm pool (if not already primary result) // This is low-cost during registry scan and avoids future expensive scans - if (ss != primary_result && tiny_warm_pool_count(class_idx) < 4) { + // Phase 1: Increase threshold from 4 to 12 to match TINY_WARM_POOL_MAX_PER_CLASS + if (ss != primary_result && tiny_warm_pool_count(class_idx) < 12) { tiny_warm_pool_push(class_idx, ss); // Track prefilled SuperSlabs for metrics g_warm_pool_stats[class_idx].prefilled++;