**問題:**
- Larson 4T で 100% SEGV (1T は 2.09M ops/s で完走)
- System/mimalloc は 4T で 33.52M ops/s 正常動作
- SS OFF + Remote OFF でも 4T で SEGV
**根本原因: (Task agent ultrathink 調査結果)**
```
CRASH: mov (%r15),%r13
R15 = 0x6261 ← ASCII "ba" (ゴミ値、未初期化TLS)
```
Worker スレッドの TLS 変数が未初期化:
- `__thread void* g_tls_sll_head[TINY_NUM_CLASSES];` ← 初期化なし
- pthread_create() で生成されたスレッドでゼロ初期化されない
- NULL チェックが通過 (0x6261 != NULL) → dereference → SEGV
**修正内容:**
全 TLS 配列に明示的初期化子 `= {0}` を追加:
1. **core/hakmem_tiny.c:**
- `g_tls_sll_head[TINY_NUM_CLASSES] = {0}`
- `g_tls_sll_count[TINY_NUM_CLASSES] = {0}`
- `g_tls_live_ss[TINY_NUM_CLASSES] = {0}`
- `g_tls_bcur[TINY_NUM_CLASSES] = {0}`
- `g_tls_bend[TINY_NUM_CLASSES] = {0}`
2. **core/tiny_fastcache.c:**
- `g_tiny_fast_cache[TINY_FAST_CLASS_COUNT] = {0}`
- `g_tiny_fast_count[TINY_FAST_CLASS_COUNT] = {0}`
- `g_tiny_fast_free_head[TINY_FAST_CLASS_COUNT] = {0}`
- `g_tiny_fast_free_count[TINY_FAST_CLASS_COUNT] = {0}`
3. **core/hakmem_tiny_magazine.c:**
- `g_tls_mags[TINY_NUM_CLASSES] = {0}`
4. **core/tiny_sticky.c:**
- `g_tls_sticky_ss[TINY_NUM_CLASSES][TINY_STICKY_RING] = {0}`
- `g_tls_sticky_idx[TINY_NUM_CLASSES][TINY_STICKY_RING] = {0}`
- `g_tls_sticky_pos[TINY_NUM_CLASSES] = {0}`
**効果:**
```
Before: 1T: 2.09M ✅ | 4T: SEGV 💀
After: 1T: 2.41M ✅ | 4T: 4.19M ✅ (+15% 1T, SEGV解消)
```
**テスト:**
```bash
# 1 thread: 完走
./larson_hakmem 2 8 128 1024 1 12345 1
→ Throughput = 2,407,597 ops/s ✅
# 4 threads: 完走(以前は SEGV)
./larson_hakmem 2 8 128 1024 1 12345 4
→ Throughput = 4,192,155 ops/s ✅
```
**調査協力:** Task agent (ultrathink mode) による完璧な根本原因特定
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
120 lines
4.7 KiB
C
120 lines
4.7 KiB
C
#ifndef HAKMEM_TINY_STATS_API_H
|
|
#define HAKMEM_TINY_STATS_API_H
|
|
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include <stdatomic.h>
|
|
|
|
// Phase 2, Module 1: Statistics and Debug API
|
|
// Extracted from hakmem_tiny.c (lines 4348-4728)
|
|
// Cold path functions - zero performance impact
|
|
|
|
// Statistics API
|
|
void hak_tiny_get_stats(uint64_t* alloc_count, uint64_t* free_count, uint64_t* slab_count);
|
|
void hak_tiny_print_stats(void);
|
|
|
|
// Memory profiling (toggle with HAKMEM_DEBUG_MEMORY)
|
|
void hak_tiny_print_memory_profile(void);
|
|
|
|
// Debug counters (toggle with HAKMEM_DEBUG_COUNTERS)
|
|
void hak_tiny_ultra_debug_dump(void);
|
|
void hak_tiny_path_debug_dump(void);
|
|
void hak_tiny_debug_counters_dump(void);
|
|
// Immediate dump of all counters (Refill/Publish/Free/Cache)
|
|
void hak_tiny_dump_all_counters_now(void);
|
|
// Enable signal-triggered dump (SIGUSR1). Env: HAKMEM_TINY_SUKESUKE=1
|
|
void hak_tiny_enable_signal_dump(void);
|
|
// Internal: cooperative poll for pending signal-triggered dump
|
|
extern _Atomic int g_tiny_sukesuke_pending;
|
|
extern _Atomic int g_tiny_sukesuke_dumping;
|
|
void hak_tiny_stats_handle_signal(void);
|
|
|
|
static inline __attribute__((always_inline)) void hak_tiny_stats_poll(void) {
|
|
if (__builtin_expect(!atomic_load_explicit(&g_tiny_sukesuke_pending, memory_order_acquire), 1)) {
|
|
return;
|
|
}
|
|
hak_tiny_stats_handle_signal();
|
|
}
|
|
|
|
// SuperSlab adopt/publish debug counters (per class)
|
|
extern unsigned long long g_ss_publish_dbg[];
|
|
extern unsigned long long g_ss_adopt_dbg[];
|
|
// Slab-ring counters (per class)
|
|
extern unsigned long long g_slab_publish_dbg[];
|
|
extern unsigned long long g_slab_adopt_dbg[];
|
|
extern unsigned long long g_slab_requeue_dbg[];
|
|
extern unsigned long long g_slab_miss_dbg[];
|
|
// Refill-stage counters
|
|
extern unsigned long long g_rf_total_calls[];
|
|
extern unsigned long long g_rf_hit_bench[];
|
|
extern unsigned long long g_rf_hit_hot[];
|
|
extern unsigned long long g_rf_hit_mail[];
|
|
extern unsigned long long g_rf_hit_slab[];
|
|
extern unsigned long long g_rf_hit_ss[];
|
|
extern unsigned long long g_rf_hit_reg[];
|
|
extern unsigned long long g_rf_mmap_calls[];
|
|
extern unsigned long long g_rf_time_total_ns[];
|
|
extern unsigned long long g_rf_time_hot_ns[];
|
|
extern unsigned long long g_rf_time_bench_ns[];
|
|
extern unsigned long long g_rf_time_mail_ns[];
|
|
extern unsigned long long g_rf_time_slab_ns[];
|
|
extern unsigned long long g_rf_time_ss_ns[];
|
|
extern unsigned long long g_rf_time_reg_ns[];
|
|
extern unsigned long long g_rf_time_mmap_ns[];
|
|
extern unsigned long long g_pub_mail_hits[];
|
|
extern unsigned long long g_pub_hot_hits[];
|
|
extern unsigned long long g_pub_bench_hits[];
|
|
// Free pipeline visibility
|
|
extern unsigned long long g_free_via_ss_local[];
|
|
extern unsigned long long g_free_via_ss_remote[];
|
|
extern unsigned long long g_free_via_tls_sll[];
|
|
extern unsigned long long g_free_via_mag[];
|
|
|
|
// Front Gate Breakdown (debug counters)
|
|
extern unsigned long long g_front_sfc_hit[];
|
|
extern unsigned long long g_front_sll_hit[];
|
|
extern unsigned long long g_front_quick_hit[];
|
|
extern unsigned long long g_front_mag_hit[];
|
|
|
|
// Free-side trigger counters
|
|
extern unsigned long long g_first_free_transitions[];
|
|
extern unsigned long long g_remote_free_transitions[];
|
|
|
|
// Adopt/Registry gate counters
|
|
extern unsigned long long g_adopt_gate_calls[];
|
|
extern unsigned long long g_adopt_gate_success[];
|
|
extern unsigned long long g_reg_scan_attempts[];
|
|
extern unsigned long long g_reg_scan_hits[];
|
|
extern unsigned long long g_free_via_fast_tls[];
|
|
extern unsigned long long g_free_via_fastcache[];
|
|
extern unsigned long long g_fast_spare_flush[];
|
|
extern unsigned long long g_fast_push_hits[];
|
|
extern unsigned long long g_fast_push_full[];
|
|
extern unsigned long long g_fast_push_disabled[];
|
|
extern unsigned long long g_fast_push_zero_cap[];
|
|
extern unsigned long long g_fast_push_gate_disabled[];
|
|
extern unsigned long long g_fast_push_gate_zero_cap[];
|
|
extern unsigned long long g_fast_spare_attempts[];
|
|
extern unsigned long long g_fast_spare_disabled[];
|
|
extern unsigned long long g_fast_spare_empty[];
|
|
extern unsigned long long g_fast_spare_lookup_fail[];
|
|
extern unsigned long long g_fast_spare_bad_index[];
|
|
extern unsigned long long g_fast_lookup_ss[];
|
|
extern unsigned long long g_fast_lookup_slab[];
|
|
extern unsigned long long g_fast_lookup_none;
|
|
// Publish pipeline visibility
|
|
extern unsigned long long g_pub_notify_calls[];
|
|
extern unsigned long long g_pub_same_empty[];
|
|
extern unsigned long long g_remote_transitions[];
|
|
extern unsigned long long g_mailbox_register_calls[];
|
|
extern unsigned long long g_mailbox_slow_discoveries[];
|
|
extern uint64_t g_ss_cache_hits[];
|
|
extern uint64_t g_ss_cache_misses[];
|
|
extern uint64_t g_ss_cache_puts[];
|
|
extern uint64_t g_ss_cache_drops[];
|
|
extern uint64_t g_ss_cache_precharged[];
|
|
extern uint64_t g_superslabs_reused;
|
|
extern uint64_t g_superslabs_cached;
|
|
|
|
#endif // HAKMEM_TINY_STATS_API_H
|