Parasitic TLS cache: alloc now pops from the TLS freelist filled by free. Implementation: - malloc_tiny_fast(): C6 class-specific TLS pop check before route switch - if (class_idx == 6 && tiny_c6_ultra_free_enabled()) - pop from TinyC6UltraFreeTLS.freelist[--count] - return USER pointer (BASE + 1) - FreePathStats: Added c6_ultra_alloc_hit counter for observability Results (Mixed 16-1024B): - OFF: 40.2M ops/s baseline - ON: 42.2M ops/s (+4.9%) stable Per-profile: - Mixed: +4.9% (40.2M → 42.2M) - C6-heavy: +7.6% (40.7M → 43.8M) Free-alloc loop: - free: TLS push (all C6 frees) - alloc: TLS pop (all C6 allocs in steady state) - Cache never fills, no legacy overflow - C6 legacy_by_class reduced from 137K to 0 (100% elimination) Key insight: - Free-only TLS cache fails without alloc integration - Once integrated, creates perfect load-balancing loop - Alloc drains exactly what free fills 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
46 lines
1.3 KiB
C
46 lines
1.3 KiB
C
#ifndef HAKMEM_FREE_PATH_STATS_BOX_H
|
|
#define HAKMEM_FREE_PATH_STATS_BOX_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <stdlib.h>
|
|
|
|
typedef struct FreePathStats {
|
|
uint64_t total_calls;
|
|
|
|
uint64_t c7_ultra_fast;
|
|
uint64_t c6_ultra_free_fast; // Phase 4-2: C6 ULTRA-free
|
|
uint64_t c6_ultra_alloc_hit; // Phase 4-4: C6 ULTRA-alloc (TLS pop)
|
|
uint64_t smallheap_v3_fast;
|
|
uint64_t smallheap_v6_fast;
|
|
uint64_t tiny_heap_v1_fast;
|
|
uint64_t pool_v1_fast;
|
|
uint64_t remote_free;
|
|
uint64_t super_lookup_called;
|
|
uint64_t legacy_fallback;
|
|
|
|
// Phase 4-1: Legacy per-class breakdown
|
|
uint64_t legacy_by_class[8]; // C0-C7 の Legacy fallback 内訳
|
|
} FreePathStats;
|
|
|
|
// ENV gate
|
|
static inline bool free_path_stats_enabled(void) {
|
|
static int g_enabled = -1;
|
|
if (__builtin_expect(g_enabled == -1, 0)) {
|
|
const char* e = getenv("HAKMEM_FREE_PATH_STATS");
|
|
g_enabled = (e && *e && *e != '0') ? 1 : 0;
|
|
}
|
|
return g_enabled;
|
|
}
|
|
|
|
// Global stats instance
|
|
extern FreePathStats g_free_path_stats;
|
|
|
|
// Increment macros (with unlikely guard)
|
|
#define FREE_PATH_STAT_INC(field) \
|
|
do { if (__builtin_expect(free_path_stats_enabled(), 0)) { \
|
|
g_free_path_stats.field++; \
|
|
} } while(0)
|
|
|
|
#endif // HAKMEM_FREE_PATH_STATS_BOX_H
|