本実装修正: - tiny_region_id_write_header() を追加: USER pointer を正しく返す - TLS slot からの segment 探索 (page_meta_of) - Page-level allocation で segment 再利用 - 2MiB alignment 保証 (4MiB 確保 + alignment) - free パスの route 修正 (v4 から v5 への fallthrough 削除) 動作確認: - SEGV 消失: alloc/free 基本動作 OK - 性能: ~18-20M ops/s (baseline 43-47M の約 40-45%) - 回帰原因: TLS slot 線形探索 O(n)、find_page O(n) 残タスク: - O(1) segment lookup 最適化 (hash または array 直接参照) - find_page 除去 (segment lookup 成功時) - partial_count/list 管理の最適化 ENV デフォルト OFF なので本線影響なし。 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
51 lines
2.1 KiB
C
51 lines
2.1 KiB
C
// 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 // C0–C7
|
||
|
||
// 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)
|
||
|
||
// Intrusive list field for current/partial/full lists (Phase v5-2)
|
||
struct SmallPageMetaV5* next; // next page in list (offset 24)
|
||
} SmallPageMetaV5; // total 32B
|
||
|
||
// 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(Phase v5-1: C6-only route stub, v1/pool fallback)
|
||
void* small_alloc_fast_v5(size_t size, uint32_t class_idx, SmallHeapCtxV5* ctx);
|
||
void small_free_fast_v5(void* ptr, uint32_t class_idx, SmallHeapCtxV5* ctx);
|
||
|
||
#endif // HAKMEM_SMALLOBJECT_HOTBOX_V5_BOX_H
|