This commit implements the first phase of Tiny Pool redesign based on
ChatGPT architecture review. The goal is to eliminate Header/Next pointer
conflicts by moving class_idx lookup out-of-band (to SuperSlab metadata).
## P0.1: C0(8B) class upgraded to 16B
- Size table changed: {16,32,64,128,256,512,1024,2048} (8 classes)
- LUT updated: 1..16 → class 0, 17..32 → class 1, etc.
- tiny_next_off: C0 now uses offset 1 (header preserved)
- Eliminates edge cases for 8B allocations
## P0.3: Slab reuse guard Box (tls_slab_reuse_guard_box.h)
- New Box for draining TLS SLL before slab reuse
- ENV gate: HAKMEM_TINY_SLAB_REUSE_GUARD=1
- Prevents stale pointers when slabs are recycled
- Follows Box theory: single responsibility, minimal API
## P1.1: SuperSlab class_map addition
- Added uint8_t class_map[SLABS_PER_SUPERSLAB_MAX] to SuperSlab
- Maps slab_idx → class_idx for out-of-band lookup
- Initialized to 255 (UNASSIGNED) on SuperSlab creation
- Set correctly on slab initialization in all backends
## P1.2: Free fast path uses class_map
- ENV gate: HAKMEM_TINY_USE_CLASS_MAP=1
- Free path can now get class_idx from class_map instead of Header
- Falls back to Header read if class_map returns invalid value
- Fixed Legacy Backend dynamic slab initialization bug
## Documentation added
- HAKMEM_ARCHITECTURE_OVERVIEW.md: 4-layer architecture analysis
- TLS_SLL_ARCHITECTURE_INVESTIGATION.md: Root cause analysis
- PTR_LIFECYCLE_TRACE_AND_ROOT_CAUSE_ANALYSIS.md: Pointer tracking
- TINY_REDESIGN_CHECKLIST.md: Implementation roadmap (P0-P3)
## Test results
- Baseline: 70% success rate (30% crash - pre-existing issue)
- class_map enabled: 70% success rate (same as baseline)
- Performance: ~30.5M ops/s (unchanged)
## Next steps (P1.3, P2, P3)
- P1.3: Add meta->active for accurate TLS/freelist sync
- P2: TLS SLL redesign with Box-based counting
- P3: Complete Header out-of-band migration
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
59 lines
1.7 KiB
C
59 lines
1.7 KiB
C
#pragma once
|
|
|
|
/*
|
|
* box/tiny_next_ptr_box.h
|
|
*
|
|
* Tiny next-pointer Box API (thin wrapper over tiny_nextptr.h)
|
|
*
|
|
* このヘッダは Phase E1-CORRECT で確定した next オフセット仕様に従い、
|
|
* すべての tiny freelist / TLS / fast-cache / refill / SLL が経由すべき
|
|
* 「唯一の Box API」を提供する。
|
|
*
|
|
* 仕様は tiny_nextptr.h と完全一致:
|
|
*
|
|
* HAKMEM_TINY_HEADER_CLASSIDX != 0:
|
|
* - Class 0-6: next_off = 1 (headerを保持)
|
|
* - Class 7: next_off = 0 (free中は header を潰す)
|
|
*
|
|
* HAKMEM_TINY_HEADER_CLASSIDX == 0:
|
|
* - 全クラス: next_off = 0
|
|
*
|
|
* 呼び出し規約:
|
|
* - base: 「内部 box 基底 (header位置または従来base)」
|
|
* - class_idx: size class index (0-7)
|
|
*
|
|
* 禁止事項:
|
|
* - ここを通さずに next オフセットを手計算すること
|
|
* - 直接 *(void**) で next を読む/書くこと
|
|
*/
|
|
|
|
#include <stdint.h>
|
|
#include "hakmem_tiny_config.h"
|
|
#include "tiny_nextptr.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
// Box API: write next pointer
|
|
static inline void tiny_next_write(int class_idx, void *base, void *next_value) {
|
|
tiny_next_store(base, class_idx, next_value);
|
|
}
|
|
|
|
// Box API: read next pointer
|
|
static inline void *tiny_next_read(int class_idx, const void *base) {
|
|
return tiny_next_load(base, class_idx);
|
|
}
|
|
|
|
/*
|
|
* Greppable macros:
|
|
* - 既存コードは TINY_NEXT_READ/WRITE か tiny_next_read/write を使う。
|
|
* - これらから tiny_nextptr.h 実装へ一元的に到達する。
|
|
*/
|
|
#define TINY_NEXT_WRITE(cls_, base_, next_) tiny_next_write((cls_), (base_), (next_))
|
|
#define TINY_NEXT_READ(cls_, base_) tiny_next_read((cls_), (base_))
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|