refactor: Guard SuperSlab expansion debug logs + Update CURRENT_TASK
## Changes
### 1. Debug Log Cleanup (Release Build Optimization)
**Files Modified:**
- `core/tiny_superslab_alloc.inc.h:183-234`
- `core/hakmem_tiny_superslab.c:567-618`
**Problem:**
- SuperSlab expansion logs flooded output (268+ lines per benchmark run)
- Massive I/O overhead masked true performance in benchmarks
- Production builds should not spam stderr
**Solution:**
- Guard all expansion logs with `#if !defined(NDEBUG) || defined(HAKMEM_SUPERSLAB_VERBOSE)`
- Debug builds: Logs enabled by default
- Release builds: Logs disabled (clean output)
- Can re-enable with `-DHAKMEM_SUPERSLAB_VERBOSE` for debugging
**Guarded Messages:**
- "SuperSlab chunk exhausted for class X, expanding..."
- "Successfully expanded SuperSlabHead for class X"
- "CRITICAL: Failed to expand SuperSlabHead..." (OOM)
- "Expanded SuperSlabHead for class X: N chunks now"
**Impact:**
- Release builds: Clean benchmark output (no log spam)
- Debug builds: Full visibility into expansion behavior
- Performance: No I/O overhead in production benchmarks
### 2. CURRENT_TASK.md Update
**New Focus:** ACE Investigation for Mid-Large Performance Recovery
**Context:**
- ✅ 100% stability achieved (commit 616070cf7)
- ✅ Tiny Hot Path: **First time beating BOTH System and mimalloc** (+48.5% vs System)
- 🔴 Critical issue: Mid-Large MT collapsed (-88% vs System)
- Root cause: ACE disabled → all allocations go to mmap (slow)
**Next Task:**
Task Agent to investigate ACE mechanism (Ultrathink mode):
1. Why is ACE disabled?
2. How does ACE improve Mid-Large performance?
3. Can we re-enable ACE to recover +171% advantage?
4. Implementation plan and risk assessment
**Benchmark Results:**
Comprehensive results saved to: `benchmarks/results/comprehensive_20251108_214317/`
---
## Testing
Verified clean build output:
```bash
make clean && make HEADER_CLASSIDX=1 AGGRESSIVE_INLINE=1 PREWARM_TLS=1 larson_hakmem
./larson_hakmem 1 1 128 1024 1 12345 1
# No expansion log spam in release build
```
🎉 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
314
CURRENT_TASK.md
314
CURRENT_TASK.md
@ -1,253 +1,159 @@
|
|||||||
# Current Task: Phase 7 Task 5 - Comprehensive Benchmark Validation
|
# Current Task: ACE Investigation - Mid-Large Performance Recovery
|
||||||
|
|
||||||
**Date**: 2025-11-08
|
**Date**: 2025-11-08
|
||||||
**Status**: 🔄 IN PROGRESS
|
**Status**: 🔄 IN PROGRESS
|
||||||
**Priority**: HIGH
|
**Priority**: CRITICAL
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🎉 Phase 7 Tasks 1-3: COMPLETE!
|
## 🎉 Recent Achievements
|
||||||
|
|
||||||
**Achievement**: **+180-280% Performance Improvement!** 🚀
|
### 100% Stability Fix (Commit 616070cf7)
|
||||||
|
- ✅ **50/50 consecutive 4T runs passed**
|
||||||
|
- ✅ Bitmap semantics corrected (0xFFFFFFFF = full)
|
||||||
|
- ✅ Race condition fixed with mutex protection
|
||||||
|
- ✅ User requirement MET: "5%でもクラッシュおこったら使えない" → **0% crash rate**
|
||||||
|
|
||||||
**Results (Quick Tests)**:
|
### Comprehensive Benchmark Results (2025-11-08)
|
||||||
- Random Mixed 128B: **59M ops/s** (92% of System) ✅
|
Located at: `benchmarks/results/comprehensive_20251108_214317/`
|
||||||
- Random Mixed 256B: **70M ops/s** (90% of System) ✅
|
|
||||||
- Random Mixed 512B: **68M ops/s** (85% of System) ✅
|
|
||||||
- Random Mixed 1024B: **65M ops/s** (146% of System!) 🏆
|
|
||||||
- Larson 1T: **2.68M ops/s** (stable) ✅
|
|
||||||
|
|
||||||
**Improvement vs Phase 6**: **+180-280%** 🚀
|
**Performance Summary:**
|
||||||
|
|
||||||
詳細: [`PHASE7_TASK3_RESULTS.md`](PHASE7_TASK3_RESULTS.md)
|
| Category | HAKMEM | vs System | vs mimalloc | Status |
|
||||||
|
|----------|--------|-----------|-------------|--------|
|
||||||
|
| **Tiny Hot Path** | 218.65 M/s | **+48.5%** 🏆 | **+23.0%** 🏆 | **HUGE WIN** |
|
||||||
|
| Random Mixed 128B | 16.92 M/s | 34% | 28% | Good (+3-4x from Phase 6) |
|
||||||
|
| Random Mixed 256B | 17.59 M/s | 42% | 32% | Good |
|
||||||
|
| Random Mixed 512B | 15.61 M/s | 42% | 33% | Good |
|
||||||
|
| Random Mixed 2048B | 11.14 M/s | 50% | 65% | Competitive |
|
||||||
|
| Random Mixed 4096B | 8.13 M/s | 61% | 66% | Competitive |
|
||||||
|
| Larson 1T | 3.92 M/s | 28% | - | Needs work |
|
||||||
|
| Larson 4T | 7.55 M/s | 45% | - | Needs work |
|
||||||
|
| **Mid-Large MT** | 1.05 M/s | **-88%** 🔴 | **-86%** 🔴 | **CRITICAL ISSUE** |
|
||||||
|
|
||||||
|
**Key Findings:**
|
||||||
|
1. ✅ **First time beating BOTH System and mimalloc** (Tiny Hot Path)
|
||||||
|
2. ✅ **100% stability** - All benchmarks passed without crashes
|
||||||
|
3. 🔴 **Critical regression**: Mid-Large MT performance collapsed (-88%)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Objective: Task 5 - Comprehensive Validation
|
## Objective: Investigate ACE for Mid-Large Performance Recovery
|
||||||
|
|
||||||
包括的ベンチマークスイートを実行して、Phase 7 の改善を検証し、本番環境デプロイのベースラインを確立する。
|
**Problem:**
|
||||||
|
- Mid-Large MT: 1.05M ops/s (was +171% in docs, now -88%)
|
||||||
|
- Root cause (from Task Agent report):
|
||||||
|
- ACE disabled → all mid allocations go to mmap (slow)
|
||||||
|
- This used to be HAKMEM's strength
|
||||||
|
|
||||||
|
**Goal:**
|
||||||
|
- Understand why ACE is disabled
|
||||||
|
- Determine if re-enabling ACE can recover performance
|
||||||
|
- If yes, implement ACE enablement
|
||||||
|
- If no, find alternative optimization
|
||||||
|
|
||||||
|
**Note:** HAKX is legacy code, ignore it. Focus on ACE mechanism.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Task Breakdown
|
## Task for Task Agent (Ultrathink Required)
|
||||||
|
|
||||||
### 1. 包括的ベンチマークスイート実行 (HIGH Priority)
|
### Investigation Scope
|
||||||
|
|
||||||
**Build Phase 7 最適化版**:
|
1. **ACE Current State**
|
||||||
```bash
|
- Why is ACE disabled?
|
||||||
make clean
|
- What does ACE do? (Adaptive Cache Engine)
|
||||||
make HEADER_CLASSIDX=1 AGGRESSIVE_INLINE=1 PREWARM_TLS=1 \
|
- How does it help Mid-Large allocations?
|
||||||
bench_comprehensive_hakmem \
|
|
||||||
bench_fragment_stress_hakmem \
|
|
||||||
larson_hakmem \
|
|
||||||
bench_random_mixed_hakmem
|
|
||||||
```
|
|
||||||
|
|
||||||
**実行するベンチマーク**:
|
2. **Code Analysis**
|
||||||
|
- Find ACE enablement flags
|
||||||
|
- Find ACE initialization code
|
||||||
|
- Find ACE allocation path
|
||||||
|
- Understand ACE vs mmap decision
|
||||||
|
|
||||||
#### 1.1 Comprehensive Benchmark (21 patterns × 4 sizes)
|
3. **Root Cause**
|
||||||
```bash
|
- Why does disabling ACE cause -88% regression?
|
||||||
./bench_comprehensive_hakmem
|
- What is the overhead of mmap for every allocation?
|
||||||
# 実行時間: ~5分
|
- Can we fix this by re-enabling ACE?
|
||||||
# カバー範囲: LIFO, FIFO, Random, Interleaved, Long/Short-lived, Mixed
|
|
||||||
# サイズ: 16B, 32B, 64B, 128B
|
|
||||||
```
|
|
||||||
|
|
||||||
**期待結果**:
|
4. **Proposed Solution**
|
||||||
- Phase 6: -61.3% (52.59 M/s vs 135.94 M/s)
|
- If ACE can be safely re-enabled: How?
|
||||||
- Phase 7: **85-92%** (目標達成!)
|
- If ACE has bugs: What needs fixing?
|
||||||
|
- Alternative optimizations if ACE is not viable
|
||||||
|
|
||||||
#### 1.2 Fragmentation Stress Test
|
5. **Implementation Plan**
|
||||||
```bash
|
- Step-by-step plan to recover Mid-Large performance
|
||||||
./bench_fragment_stress_hakmem 50 2000
|
- Estimated effort (days)
|
||||||
# 実行時間: ~2分
|
- Risk assessment
|
||||||
# テスト: 50ラウンド, 2000スロット, 混合サイズ
|
|
||||||
```
|
|
||||||
|
|
||||||
**期待結果**:
|
|
||||||
- Phase 6: -75.0% (4.68 M/s vs 18.43 M/s)
|
|
||||||
- Phase 7: **大幅改善** (TLS キャッシュ事前ウォームで)
|
|
||||||
|
|
||||||
#### 1.3 Larson Multi-Thread Stress
|
|
||||||
```bash
|
|
||||||
# 1 thread (ベースライン)
|
|
||||||
./larson_hakmem 1 1 128 1024 1 12345 1
|
|
||||||
# 期待: 2.68M ops/s ✅
|
|
||||||
|
|
||||||
# 2 threads
|
|
||||||
./larson_hakmem 2 8 128 1024 1 12345 2
|
|
||||||
|
|
||||||
# 4 threads
|
|
||||||
./larson_hakmem 4 8 128 1024 1 12345 4
|
|
||||||
|
|
||||||
# 8 threads (ストレス)
|
|
||||||
./larson_hakmem 8 8 128 1024 1 12345 8
|
|
||||||
```
|
|
||||||
|
|
||||||
**期待結果**:
|
|
||||||
- 1T: 2.68M ops/s (安定)
|
|
||||||
- 4T: スケール確認 (デグレなし)
|
|
||||||
|
|
||||||
#### 1.4 Random Mixed (各サイズ)
|
|
||||||
```bash
|
|
||||||
# Tiny range
|
|
||||||
./bench_random_mixed_hakmem 100000 16 1234567
|
|
||||||
./bench_random_mixed_hakmem 100000 32 1234567
|
|
||||||
./bench_random_mixed_hakmem 100000 64 1234567
|
|
||||||
./bench_random_mixed_hakmem 100000 128 1234567
|
|
||||||
./bench_random_mixed_hakmem 100000 256 1234567
|
|
||||||
./bench_random_mixed_hakmem 100000 512 1234567
|
|
||||||
./bench_random_mixed_hakmem 100000 1024 1234567
|
|
||||||
|
|
||||||
# Mid range (mid_mt territory)
|
|
||||||
./bench_random_mixed_hakmem 100000 2048 1234567
|
|
||||||
./bench_random_mixed_hakmem 100000 4096 1234567
|
|
||||||
./bench_random_mixed_hakmem 100000 8192 1234567
|
|
||||||
./bench_random_mixed_hakmem 100000 16384 1234567
|
|
||||||
```
|
|
||||||
|
|
||||||
**期待結果**:
|
|
||||||
- Tiny (≤1KB): **85-92% of System**
|
|
||||||
- Mid (1-8KB): **146% of System** (1024B)
|
|
||||||
- Mid-Large (8-32KB): **+87% vs System** (既存 mid_mt)
|
|
||||||
|
|
||||||
#### 1.5 長時間実行(安定性確認)
|
|
||||||
```bash
|
|
||||||
# 10倍長時間実行で安定結果
|
|
||||||
./bench_random_mixed_hakmem 1000000 128 1234567
|
|
||||||
./bench_random_mixed_hakmem 1000000 256 1234567
|
|
||||||
./bench_random_mixed_hakmem 1000000 1024 1234567
|
|
||||||
```
|
|
||||||
|
|
||||||
**期待結果**:
|
|
||||||
- 分散 ≤10% (安定性確認)
|
|
||||||
- 平均値がクイックテストと一致
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### 2. System malloc との比較
|
## Success Criteria
|
||||||
|
|
||||||
**System malloc 版をビルド**:
|
✅ **Understand ACE mechanism and current state**
|
||||||
|
✅ **Identify why Mid-Large performance collapsed**
|
||||||
|
✅ **Propose concrete solution with implementation plan**
|
||||||
|
✅ **Return detailed analysis report**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Context for Task Agent
|
||||||
|
|
||||||
|
**Current Build Flags:**
|
||||||
```bash
|
```bash
|
||||||
make bench_comprehensive_system \
|
make HEADER_CLASSIDX=1 AGGRESSIVE_INLINE=1 PREWARM_TLS=1
|
||||||
bench_fragment_stress_system \
|
|
||||||
bench_random_mixed_system
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**並行比較実行**:
|
**Relevant Files to Check:**
|
||||||
```bash
|
- `core/hakmem_ace*.c` - ACE implementation
|
||||||
# 両方実行して比較
|
- `core/hakmem_mid_mt.c` - Mid-Large allocator
|
||||||
./bench_comprehensive_hakmem > results_hakmem.txt
|
- `core/hakmem_learner.c` - Learning mechanism
|
||||||
./bench_comprehensive_system > results_system.txt
|
- Build flags in Makefile
|
||||||
|
|
||||||
# 比較レポート生成
|
**Benchmark to Verify:**
|
||||||
diff -y results_hakmem.txt results_system.txt
|
```bash
|
||||||
|
# Mid-Large MT (currently broken)
|
||||||
|
./bench_mid_large_mt_hakmem
|
||||||
|
# Expected: Should improve significantly with ACE
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### 3. Phase 6 からの性能後退チェック
|
## Deliverables
|
||||||
|
|
||||||
**Phase 6 ベースライン**:
|
1. **ACE Analysis Report** (markdown)
|
||||||
- Tiny: 21M ops/s (31% of System)
|
- ACE mechanism explanation
|
||||||
- Mid-Large: 97M ops/s (+87% vs System)
|
- Current state diagnosis
|
||||||
|
- Root cause of -88% regression
|
||||||
|
- Proposed solution
|
||||||
|
|
||||||
**Phase 7 期待値**:
|
2. **Implementation Plan**
|
||||||
- Tiny: 59M ops/s (92% of System) ← **+181%** 🚀
|
- Concrete steps to fix
|
||||||
- Mid-Large: 97M ops/s (変化なし) ← 影響なし ✅
|
- Code changes needed
|
||||||
|
- Testing strategy
|
||||||
|
|
||||||
**確認項目**:
|
3. **Risk Assessment**
|
||||||
- ✅ Tiny が大幅改善
|
- Stability impact
|
||||||
- ✅ Mid-Large が維持
|
- Performance trade-offs
|
||||||
- ✅ クラッシュなし
|
- Alternative approaches
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### 4. 成果物
|
## Timeline
|
||||||
|
|
||||||
**包括的レポート作成**:
|
- **Investigation**: Task Agent (Ultrathink mode)
|
||||||
- `PHASE7_COMPREHENSIVE_BENCHMARK_RESULTS.md`
|
- **Report Review**: 30 min
|
||||||
- 全ベンチマーク結果
|
- **Implementation**: 1-2 days (depends on findings)
|
||||||
- 比較表 (HAKMEM vs System)
|
- **Validation**: Re-run benchmarks
|
||||||
- 性能グラフ (可能なら)
|
|
||||||
- 安定性分析 (分散、外れ値)
|
|
||||||
- 本番環境準備度評価
|
|
||||||
|
|
||||||
**ドキュメント更新**:
|
|
||||||
- `CLAUDE.md` - 包括的結果セクション追加
|
|
||||||
- `README.md` - 性能主張を更新
|
|
||||||
- `benchmarks/results/` - 詳細結果をアーカイブ
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 成功基準
|
## Notes
|
||||||
|
|
||||||
✅ **全ベンチマーククラッシュなく完了**
|
- Debug logs now properly guarded with `HAKMEM_SUPERSLAB_VERBOSE`
|
||||||
✅ **Tiny 性能: 85-92% of System** (目標: 40-55%)
|
- Can be enabled with `-DHAKMEM_SUPERSLAB_VERBOSE` for debugging
|
||||||
✅ **Mid-Large 性能: 維持または改善**
|
- Release builds will be clean (no log spam)
|
||||||
✅ **マルチスレッド安定性: 後退なし**
|
|
||||||
✅ **フラグメンテーションストレス: 許容可能な性能**
|
|
||||||
✅ **包括的レポート生成完了**
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## タイムライン
|
**Status**: Ready to launch Task Agent investigation 🚀
|
||||||
|
|
||||||
- **ベンチマーク実行**: 1-2時間 (自動化)
|
|
||||||
- **分析とレポート**: 2-3時間
|
|
||||||
- **合計**: 4-5時間
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 検証後の次のステップ
|
|
||||||
|
|
||||||
**ベンチマーク合格の場合**:
|
|
||||||
1. Task 6-9 (本番環境強化) に進む
|
|
||||||
2. Task 4 (PGO) を検討 (最終 +3-5% ブースト)
|
|
||||||
3. 本番環境デプロイ準備
|
|
||||||
|
|
||||||
**問題発見の場合**:
|
|
||||||
1. 性能後退を調査
|
|
||||||
2. 修正して再テスト
|
|
||||||
3. 既知の制限をドキュメント化
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 備考
|
|
||||||
|
|
||||||
- `HAKMEM_LOG=1` で詳細な初期化ログ
|
|
||||||
- `valgrind --tool=massif` でメモリ使用量監視
|
|
||||||
- `valgrind --leak-check=full` でメモリリークチェック
|
|
||||||
- `perf record -g` でホットパスプロファイル
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 📋 実行コマンドまとめ
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# ビルド
|
|
||||||
make clean
|
|
||||||
make HEADER_CLASSIDX=1 AGGRESSIVE_INLINE=1 PREWARM_TLS=1 \
|
|
||||||
bench_comprehensive_hakmem larson_hakmem bench_random_mixed_hakmem
|
|
||||||
|
|
||||||
# クイック検証 (5分)
|
|
||||||
./bench_comprehensive_hakmem
|
|
||||||
./larson_hakmem 1 1 128 1024 1 12345 1
|
|
||||||
./bench_random_mixed_hakmem 100000 128 1234567
|
|
||||||
|
|
||||||
# 完全検証 (1-2時間)
|
|
||||||
for size in 16 32 64 128 256 512 1024 2048 4096 8192; do
|
|
||||||
echo "=== Size: $size ==="
|
|
||||||
./bench_random_mixed_hakmem 100000 $size 1234567
|
|
||||||
done
|
|
||||||
|
|
||||||
./larson_hakmem 4 8 128 1024 1 12345 4
|
|
||||||
./bench_fragment_stress_hakmem 50 2000
|
|
||||||
|
|
||||||
# レポート生成
|
|
||||||
# (結果を PHASE7_COMPREHENSIVE_BENCHMARK_RESULTS.md にまとめる)
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Status**: Task Agent に自動ベンチマーク実行を委譲する準備完了 🤖
|
|
||||||
|
|||||||
@ -564,11 +564,13 @@ int expand_superslab_head(SuperSlabHead* head) {
|
|||||||
// Allocate new chunk via existing superslab_allocate
|
// Allocate new chunk via existing superslab_allocate
|
||||||
SuperSlab* new_chunk = superslab_allocate(head->class_idx);
|
SuperSlab* new_chunk = superslab_allocate(head->class_idx);
|
||||||
if (!new_chunk) {
|
if (!new_chunk) {
|
||||||
|
#if !defined(NDEBUG) || defined(HAKMEM_SUPERSLAB_VERBOSE)
|
||||||
extern __thread int g_hakmem_lock_depth;
|
extern __thread int g_hakmem_lock_depth;
|
||||||
g_hakmem_lock_depth++;
|
g_hakmem_lock_depth++;
|
||||||
fprintf(stderr, "[HAKMEM] CRITICAL: Failed to allocate new chunk for class %d (system OOM)\n",
|
fprintf(stderr, "[HAKMEM] CRITICAL: Failed to allocate new chunk for class %d (system OOM)\n",
|
||||||
head->class_idx);
|
head->class_idx);
|
||||||
g_hakmem_lock_depth--;
|
g_hakmem_lock_depth--;
|
||||||
|
#endif
|
||||||
return -1; // True OOM (system out of memory)
|
return -1; // True OOM (system out of memory)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -607,11 +609,13 @@ int expand_superslab_head(SuperSlabHead* head) {
|
|||||||
|
|
||||||
pthread_mutex_unlock(&head->expansion_lock);
|
pthread_mutex_unlock(&head->expansion_lock);
|
||||||
|
|
||||||
|
#if !defined(NDEBUG) || defined(HAKMEM_SUPERSLAB_VERBOSE)
|
||||||
extern __thread int g_hakmem_lock_depth;
|
extern __thread int g_hakmem_lock_depth;
|
||||||
g_hakmem_lock_depth++;
|
g_hakmem_lock_depth++;
|
||||||
fprintf(stderr, "[HAKMEM] Expanded SuperSlabHead for class %d: %zu chunks now (bitmap=0x%08x)\n",
|
fprintf(stderr, "[HAKMEM] Expanded SuperSlabHead for class %d: %zu chunks now (bitmap=0x%08x)\n",
|
||||||
head->class_idx, new_count, new_chunk->slab_bitmap);
|
head->class_idx, new_count, new_chunk->slab_bitmap);
|
||||||
g_hakmem_lock_depth--;
|
g_hakmem_lock_depth--;
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -180,11 +180,13 @@ static SuperSlab* superslab_refill(int class_idx) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Current chunk exhausted (all slabs occupied), try to expand
|
// Current chunk exhausted (all slabs occupied), try to expand
|
||||||
|
#if !defined(NDEBUG) || defined(HAKMEM_SUPERSLAB_VERBOSE)
|
||||||
extern __thread int g_hakmem_lock_depth;
|
extern __thread int g_hakmem_lock_depth;
|
||||||
g_hakmem_lock_depth++;
|
g_hakmem_lock_depth++;
|
||||||
fprintf(stderr, "[HAKMEM] SuperSlab chunk exhausted for class %d (bitmap=0x%08x), expanding...\n",
|
fprintf(stderr, "[HAKMEM] SuperSlab chunk exhausted for class %d (bitmap=0x%08x), expanding...\n",
|
||||||
class_idx, current_chunk->slab_bitmap);
|
class_idx, current_chunk->slab_bitmap);
|
||||||
g_hakmem_lock_depth--;
|
g_hakmem_lock_depth--;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Protect expansion with global lock (race condition fix)
|
// Protect expansion with global lock (race condition fix)
|
||||||
static pthread_mutex_t expand_lock = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t expand_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
@ -199,15 +201,19 @@ static SuperSlab* superslab_refill(int class_idx) {
|
|||||||
// Still exhausted, expand now
|
// Still exhausted, expand now
|
||||||
if (expand_superslab_head(head) < 0) {
|
if (expand_superslab_head(head) < 0) {
|
||||||
pthread_mutex_unlock(&expand_lock);
|
pthread_mutex_unlock(&expand_lock);
|
||||||
|
#if !defined(NDEBUG) || defined(HAKMEM_SUPERSLAB_VERBOSE)
|
||||||
g_hakmem_lock_depth++;
|
g_hakmem_lock_depth++;
|
||||||
fprintf(stderr, "[HAKMEM] CRITICAL: Failed to expand SuperSlabHead for class %d (system OOM)\n", class_idx);
|
fprintf(stderr, "[HAKMEM] CRITICAL: Failed to expand SuperSlabHead for class %d (system OOM)\n", class_idx);
|
||||||
g_hakmem_lock_depth--;
|
g_hakmem_lock_depth--;
|
||||||
|
#endif
|
||||||
return NULL; // True system OOM
|
return NULL; // True system OOM
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(NDEBUG) || defined(HAKMEM_SUPERSLAB_VERBOSE)
|
||||||
g_hakmem_lock_depth++;
|
g_hakmem_lock_depth++;
|
||||||
fprintf(stderr, "[HAKMEM] Successfully expanded SuperSlabHead for class %d\n", class_idx);
|
fprintf(stderr, "[HAKMEM] Successfully expanded SuperSlabHead for class %d\n", class_idx);
|
||||||
g_hakmem_lock_depth--;
|
g_hakmem_lock_depth--;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update current_chunk and tls->ss to point to (potentially new) chunk
|
// Update current_chunk and tls->ss to point to (potentially new) chunk
|
||||||
@ -219,9 +225,11 @@ static SuperSlab* superslab_refill(int class_idx) {
|
|||||||
full_mask = (ss_slabs_capacity(current_chunk) >= 32) ? 0xFFFFFFFF :
|
full_mask = (ss_slabs_capacity(current_chunk) >= 32) ? 0xFFFFFFFF :
|
||||||
((1U << ss_slabs_capacity(current_chunk)) - 1);
|
((1U << ss_slabs_capacity(current_chunk)) - 1);
|
||||||
if (!current_chunk || current_chunk->slab_bitmap == full_mask) {
|
if (!current_chunk || current_chunk->slab_bitmap == full_mask) {
|
||||||
|
#if !defined(NDEBUG) || defined(HAKMEM_SUPERSLAB_VERBOSE)
|
||||||
g_hakmem_lock_depth++;
|
g_hakmem_lock_depth++;
|
||||||
fprintf(stderr, "[HAKMEM] CRITICAL: Chunk still has no free slabs for class %d after expansion\n", class_idx);
|
fprintf(stderr, "[HAKMEM] CRITICAL: Chunk still has no free slabs for class %d after expansion\n", class_idx);
|
||||||
g_hakmem_lock_depth--;
|
g_hakmem_lock_depth--;
|
||||||
|
#endif
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user