Files
hakmem/core/box/tiny_next_ptr_box.h
Moe Charm (CI) a78224123e Fix C0/C7 class confusion: Upgrade C7 stride to 2048B and fix meta->class_idx initialization
Root Cause:
1. C7 stride was 1024B, unable to serve 1024B user requests (need 1025B with header)
2. New SuperSlabs start with meta->class_idx=0 (mmap zero-init)
3. superslab_init_slab() only sets class_idx if meta->class_idx==255
4. Multiple code paths used conditional assignment (if class_idx==255), leaving C7 slabs with class_idx=0
5. This caused C7 blocks to be misidentified as C0, leading to HDR_META_MISMATCH errors

Changes:
1. Upgrade C7 stride: 1024B → 2048B (can now serve 1024B requests)
2. Update blocks_per_slab[7]: 64 → 32 (2048B stride / 64KB slab)
3. Update size-to-class LUT: entries 513-2048 now map to C7
4. Fix superslab_init_slab() fail-safe: only reinitialize if class_idx==255 (not 0)
5. Add explicit class_idx assignment in 6 initialization paths:
   - tiny_superslab_alloc.inc.h: superslab_refill() after init
   - hakmem_tiny_superslab.c: backend_shared after init (main path)
   - ss_unified_backend_box.c: unconditional assignment
   - ss_legacy_backend_box.c: explicit assignment
   - superslab_expansion_box.c: explicit assignment
   - ss_allocation_box.c: fail-safe condition fix

Fix P0 refill bug:
- Update obsolete array access after Phase 3d-B TLS SLL unification
- g_tls_sll_head[cls] → g_tls_sll[cls].head
- g_tls_sll_count[cls] → g_tls_sll[cls].count

Results:
- HDR_META_MISMATCH: eliminated (0 errors in 100K iterations)
- 1024B allocations now routed to C7 (Tiny fast path)
- NXT_MISALIGN warnings remain (legacy 1024B SuperSlabs, separate issue)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 13:44:05 +09:00

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: next_off = 0 (free中は header を潰す)
* - Class 1-7: next_off = 1 (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