Priority 1-3のBox Modulesを実装し、安全なpre-warming APIを提供。
既存の複雑なprewarmコードを1行のBox API呼び出しに置き換え。
## 新規Box Modules
1. **Box Capacity Manager** (capacity_box.h/c)
- TLS SLL容量の一元管理
- adaptive_sizing初期化保証
- Double-free バグ防止
2. **Box Carve-And-Push** (carve_push_box.h/c)
- アトミックなblock carve + TLS SLL push
- All-or-nothing semantics
- Rollback保証(partial failure防止)
3. **Box Prewarm** (prewarm_box.h/c)
- 安全なTLS cache pre-warming
- 初期化依存性を隠蔽
- シンプルなAPI (1関数呼び出し)
## コード簡略化
hakmem_tiny_init.inc: 20行 → 1行
```c
// BEFORE: 複雑なP0分岐とエラー処理
adaptive_sizing_init();
if (prewarm > 0) {
#if HAKMEM_TINY_P0_BATCH_REFILL
int taken = sll_refill_batch_from_ss(5, prewarm);
#else
int taken = sll_refill_small_from_ss(5, prewarm);
#endif
}
// AFTER: Box API 1行
int taken = box_prewarm_tls(5, prewarm);
```
## シンボルExport修正
hakmem_tiny.c: 5つのシンボルをstatic → non-static
- g_tls_slabs[] (TLS slab配列)
- g_sll_multiplier (SLL容量乗数)
- g_sll_cap_override[] (容量オーバーライド)
- superslab_refill() (SuperSlab再充填)
- ss_active_add() (アクティブカウンタ)
## ビルドシステム
Makefile: TINY_BENCH_OBJS_BASEに3つのBox modules追加
- core/box/capacity_box.o
- core/box/carve_push_box.o
- core/box/prewarm_box.o
## 動作確認
✅ Debug build成功
✅ Box Prewarm API動作確認
[PREWARM] class=5 requested=128 taken=32
## 次のステップ
- Box Refill Manager (Priority 4)
- Box SuperSlab Allocator (Priority 5)
- Release build修正(tiny_debug_ring_record)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
52 lines
1.6 KiB
C
52 lines
1.6 KiB
C
// carve_push_box.h - Box Carve-And-Push
|
|
// Priority 2 Box: Atomic Block Carving and TLS SLL Push
|
|
//
|
|
// Purpose:
|
|
// - Prevent rollback bugs (root cause of 20-carved-but-16-pushed issue)
|
|
// - Atomic operation: carve + header + push (all-or-nothing)
|
|
// - Eliminate partial failures that leave orphaned blocks
|
|
//
|
|
// Design:
|
|
// - Wraps trc_linear_carve() + tls_sll_push()
|
|
// - Rollback on any failure
|
|
// - Active counter management built-in
|
|
// - Clear error reporting
|
|
|
|
#ifndef HAKMEM_BOX_CARVE_PUSH_H
|
|
#define HAKMEM_BOX_CARVE_PUSH_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
// ============================================================================
|
|
// Box Carve-Push API
|
|
// ============================================================================
|
|
|
|
// Carve N blocks from current TLS slab and atomically push to TLS SLL
|
|
//
|
|
// Guarantees:
|
|
// - All-or-nothing: either all N blocks are pushed, or none
|
|
// - No orphaned blocks (carved but not pushed)
|
|
// - Headers written correctly before push
|
|
// - Active counters updated atomically
|
|
//
|
|
// Returns: actual count pushed
|
|
// - On success: want (all blocks pushed)
|
|
// - On failure: 0 (rolled back, no blocks pushed)
|
|
//
|
|
// Failure cases:
|
|
// - No SuperSlab available
|
|
// - Slab exhausted (capacity reached)
|
|
// - TLS SLL capacity exceeded
|
|
// - Invalid class_idx
|
|
//
|
|
// Thread-safe: uses TLS
|
|
uint32_t box_carve_and_push(int class_idx, uint32_t want);
|
|
|
|
// Variant: carve and push with freelist fallback
|
|
// If slab is exhausted, tries to pop from freelist first
|
|
// Same guarantees as box_carve_and_push()
|
|
uint32_t box_carve_and_push_with_freelist(int class_idx, uint32_t want);
|
|
|
|
#endif // HAKMEM_BOX_CARVE_PUSH_H
|