--- core/hakmem.c.orig +++ core/hakmem.c @@ -786,6 +786,13 @@ return; } + // DEBUG: Free path statistics + static __thread uint64_t mid_mt_local_free = 0; + static __thread uint64_t mid_mt_registry_free = 0; + static __thread uint64_t tiny_slab_free = 0; + static __thread uint64_t other_free = 0; + static __thread uint64_t total_free = 0; + // OPTIMIZATION: Check Mid Range MT FIRST (for bench_mid_large_mt workload) // This benchmark is 100% Mid MT allocations, so check Mid MT before Tiny // to avoid the 1.1% overhead of hak_tiny_owner_slab() lookup @@ -807,6 +814,15 @@ seg->free_list = ptr; // Update head seg->used_count--; + // DEBUG stats + mid_mt_local_free++; + total_free++; + if (total_free % 100000 == 0) { + fprintf(stderr, "[FREE STATS] Total=%llu MidLocal=%llu (%.1f%%) MidRegistry=%llu (%.1f%%) Tiny=%llu (%.1f%%) Other=%llu (%.1f%%)\n", + total_free, + mid_mt_local_free, 100.0 * mid_mt_local_free / total_free, + mid_mt_registry_free, 100.0 * mid_mt_registry_free / total_free, + tiny_slab_free, 100.0 * tiny_slab_free / total_free, + other_free, 100.0 * other_free / total_free); + } #if HAKMEM_DEBUG_TIMING HKM_TIME_END(HKM_CAT_HAK_FREE, t0); #endif @@ -819,6 +835,15 @@ if (mid_registry_lookup(ptr, &mid_block_size, &mid_class_idx)) { // Found in Mid MT registry - free it mid_mt_free(ptr, mid_block_size); + // DEBUG stats + mid_mt_registry_free++; + total_free++; + if (total_free % 100000 == 0) { + fprintf(stderr, "[FREE STATS] Total=%llu MidLocal=%llu (%.1f%%) MidRegistry=%llu (%.1f%%) Tiny=%llu (%.1f%%) Other=%llu (%.1f%%)\n", + total_free, + mid_mt_local_free, 100.0 * mid_mt_local_free / total_free, + mid_mt_registry_free, 100.0 * mid_mt_registry_free / total_free, + tiny_slab_free, 100.0 * tiny_slab_free / total_free, + other_free, 100.0 * other_free / total_free); + } #if HAKMEM_DEBUG_TIMING HKM_TIME_END(HKM_CAT_HAK_FREE, t0); #endif @@ -838,6 +863,15 @@ TinySlab* tiny_slab = hak_tiny_owner_slab(ptr); if (tiny_slab) { hak_tiny_free(ptr); + // DEBUG stats + tiny_slab_free++; + total_free++; + if (total_free % 100000 == 0) { + fprintf(stderr, "[FREE STATS] Total=%llu MidLocal=%llu (%.1f%%) MidRegistry=%llu (%.1f%%) Tiny=%llu (%.1f%%) Other=%llu (%.1f%%)\n", + total_free, + mid_mt_local_free, 100.0 * mid_mt_local_free / total_free, + mid_mt_registry_free, 100.0 * mid_mt_registry_free / total_free, + tiny_slab_free, 100.0 * tiny_slab_free / total_free, + other_free, 100.0 * other_free / total_free); + } #if HAKMEM_DEBUG_TIMING HKM_TIME_END(HKM_CAT_HAK_FREE, t0); #endif