Files
hakmem/docs/archive/QUICK_REFERENCE.md
Moe Charm (CI) 67fb15f35f Wrap debug fprintf in !HAKMEM_BUILD_RELEASE guards (Release build optimization)
## Changes

### 1. core/page_arena.c
- Removed init failure message (lines 25-27) - error is handled by returning early
- All other fprintf statements already wrapped in existing #if !HAKMEM_BUILD_RELEASE blocks

### 2. core/hakmem.c
- Wrapped SIGSEGV handler init message (line 72)
- CRITICAL: Kept SIGSEGV/SIGBUS/SIGABRT error messages (lines 62-64) - production needs crash logs

### 3. core/hakmem_shared_pool.c
- Wrapped all debug fprintf statements in #if !HAKMEM_BUILD_RELEASE:
  - Node pool exhaustion warning (line 252)
  - SP_META_CAPACITY_ERROR warning (line 421)
  - SP_FIX_GEOMETRY debug logging (line 745)
  - SP_ACQUIRE_STAGE0.5_EMPTY debug logging (line 865)
  - SP_ACQUIRE_STAGE0_L0 debug logging (line 803)
  - SP_ACQUIRE_STAGE1_LOCKFREE debug logging (line 922)
  - SP_ACQUIRE_STAGE2_LOCKFREE debug logging (line 996)
  - SP_ACQUIRE_STAGE3 debug logging (line 1116)
  - SP_SLOT_RELEASE debug logging (line 1245)
  - SP_SLOT_FREELIST_LOCKFREE debug logging (line 1305)
  - SP_SLOT_COMPLETELY_EMPTY debug logging (line 1316)
- Fixed lock_stats_init() for release builds (lines 60-65) - ensure g_lock_stats_enabled is initialized

## Performance Validation

Before: 51M ops/s (with debug fprintf overhead)
After:  49.1M ops/s (consistent performance, fprintf removed from hot paths)

## Build & Test

```bash
./build.sh larson_hakmem
./out/release/larson_hakmem 1 5 1 1000 100 10000 42
# Result: 49.1M ops/s
```

Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 13:14:18 +09:00

2.0 KiB
Raw Blame History

hakmem Quick Reference - 速引きリファレンス

目的: 5分で理解したい人向けの簡易仕様


🚀 3階層構造

size  1KB     Tiny Pool    (TLS Magazine)
1KB < size < 2MB  ACE Layer   (7固定クラス)  
size  2MB     Big Cache    (mmap)

📊 サイズクラス詳細

Tiny Pool (8クラス)

8B, 16B, 32B, 64B, 128B, 256B, 512B, 1KB

ACE Layer (7クラス) Bridge Classes!

2KB, 4KB, 8KB, 16KB, 32KB, 40KB, 52KB
                           ^^^^^^  ^^^^^^
                         Bridge Classes (Phase 6.21追加)

Big Cache

≥2MB → mmap (BigCache)

使い方

基本モード選択

export HAKMEM_MODE=balanced   # 推奨
export HAKMEM_MODE=minimal    # ベースライン
export HAKMEM_MODE=fast       # 本番用

実行

# LD_PRELOADで全プログラムに適用
LD_PRELOAD=./libhakmem.so ./your_program

# ベンチマーク
./bench_comprehensive_hakmem --scenario tiny

# Bridge Classesテスト
./test_bridge

🏆 ベンチマーク結果

テスト 結果 mimalloc比較
16B LIFO 勝利 +0.8%
16B インターリーブ 勝利 +7%
64B LIFO 勝利 +3%
混合サイズ 勝利 +7.5%

🔧 ビルド

make clean && make libhakmem.so
make test      # 基本確認
make bench     # 性能測定

📁 主要ファイル

hakmem.c          - メイン
hakmem_tiny.c     - 1KB以下
hakmem_pool.c     - 1KB-32KB
hakmem_l25_pool.c - 64KB-1MB
hakmem_bigcache.c - 2MB以上

⚠️ 注意点

  • 学習機能は無効化DYN1/DYN2廃止
  • Call-siteプロファイリング不要(サイズのみ)
  • Bridge Classesが勝利の秘訣

🎯 なぜ速いのか?

  1. TLS Active Slab - スレッド競合排除
  2. Bridge Classes - 32-64KBギャップ解消
  3. 単純なSACS-3 - 複雑な学習削除

以上!🎉