Files
hakmem/core/box/smallobject_hotbox_v5_box.h
Moe Charm (CI) dedfea27d5 Phase v5-0 refactor: ENV統一・マクロ化・構造体最適化
- ENV initialization を sentinel パターンで統一
  - ENV_UNINIT/ENABLED/DISABLED 定数追加
  - __builtin_expect で初期化チェックを最適化
  - small_heap_v5_enabled/class_mask を統一パターンに変更

- ポインタマクロ化(O(1) segment/page 計算)
  - SMALL_SEGMENT_V5_BASE_FROM_PTR: ptr から segment base を mask で計算
  - SMALL_SEGMENT_V5_PAGE_IDX: segment 内の page_idx を shift で計算
  - SMALL_SEGMENT_V5_PAGE_META: page_meta への O(1) access(bounds check付き)
  - SMALL_SEGMENT_V5_VALIDATE_MAGIC: magic 検証
  - SMALL_SEGMENT_V5_VALIDATE_PTR: Fail-Fast validation pipeline

- SmallClassHeapV5 に partial_count 追加
  - partial ページリストのカウンタを追加(refill/retire 最適化用)

- SmallPageMetaV5 の field 再配置(L1 cache 最適化)
  - hot fields (free_list, used, capacity) を先頭に集約
  - metadata (class_idx, flags, page_idx, segment) を後方配置
  - total 24B、offset コメント追加

- route priority ENV 追加
  - HAKMEM_ROUTE_PRIORITY={v4|v5|auto}(default: v4)
  - enum small_route_priority 定義
  - small_route_priority() 関数追加

- segment_size override ENV 追加
  - HAKMEM_SMALL_HEAP_V5_SEGMENT_SIZE(default: 2MiB)
  - power of 2 & >= 64KiB validation

挙動: 完全不変(v5 route は呼ばれない、ENV default OFF)
テスト: Mixed 16–1024B で 43.0–43.8M ops/s(変化なし)、SEGV/assert なし

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

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-11 03:19:18 +09:00

48 lines
1.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// smallobject_hotbox_v5_box.h - SmallObject HotBox v5 型定義Phase v5-0
//
// この段階では型とインターフェース定義のみ。挙動は変わらない。
#ifndef HAKMEM_SMALLOBJECT_HOTBOX_V5_BOX_H
#define HAKMEM_SMALLOBJECT_HOTBOX_V5_BOX_H
#include <stdint.h>
#define NUM_SMALL_CLASSES_V5 8 // C0C7
// SmallPageMetaV5: v5 ページメタデータ
// Hot fields (alloc/free 頻繁アクセス) を先頭に集約L1 cache 最適化)
typedef struct SmallPageMetaV5 {
// Hot fields (alloc/free 頻繁アクセス)
void* free_list; // フリーリスト先頭 (offset 0)
uint16_t used; // 使用中ブロック数 (offset 8)
uint16_t capacity; // このページの総容量 (offset 10)
// Metadata初期化時のみ
uint8_t class_idx; // size class index (offset 12)
uint8_t flags; // reserved (offset 13)
uint16_t page_idx; // segment 内でのページインデックス (offset 14)
void* segment; // SmallSegmentV5* への backpointer (offset 16)
} SmallPageMetaV5; // total 24B
// SmallClassHeapV5: サイズクラス毎のホットヒープ状態
typedef struct SmallClassHeapV5 {
SmallPageMetaV5* current; // 現在のページalloc 中)
SmallPageMetaV5* partial_head; // partial ページリスト
SmallPageMetaV5* full_head; // full ページリスト
uint32_t partial_count; // partial ページ数
} SmallClassHeapV5;
// SmallHeapCtxV5: per-thread ホットヒープコンテキスト
typedef struct SmallHeapCtxV5 {
SmallClassHeapV5 cls[NUM_SMALL_CLASSES_V5];
} SmallHeapCtxV5;
// API
SmallHeapCtxV5* small_heap_ctx_v5(void);
// Fast path将来実装
void* small_alloc_fast_v5(size_t size, uint32_t class_idx);
void small_free_fast_v5(void* ptr, uint32_t class_idx);
#endif // HAKMEM_SMALLOBJECT_HOTBOX_V5_BOX_H