Phase 36-37: TinyHotHeap v2 HotBox redesign and C7 current_page policy fixes

- Redefine TinyHotHeap v2 as per-thread Hot Box with clear boundaries
- Add comprehensive OS statistics tracking for SS allocations
- Implement route-based free handling for TinyHeap v2
- Add C6/C7 debugging and statistics improvements
- Update documentation with implementation guidelines and analysis
- Add new box headers for stats, routing, and front-end management
This commit is contained in:
Moe Charm (CI)
2025-12-08 21:30:21 +09:00
parent 34a8fd69b6
commit 8f18963ad5
37 changed files with 3205 additions and 167 deletions

View File

@ -2,6 +2,9 @@
// 役割:
// - TinyHotHeap v2 の型と API を先行定義するが、現行経路には配線しない。
// - HAKMEM_TINY_HOTHEAP_V2 / HAKMEM_TINY_HOTHEAP_CLASSES で将来の A/B に備える。
// メモ (Phase35):
// - 現状の v2 は C7-only でも v1 より遅く、mixed では大きな回帰が確認されている。
// - 研究用/実験用フラグを明示的に立てたときだけ使用し、デフォルトは OFF とする。
#pragma once
#include <stdint.h>
@ -16,15 +19,15 @@ struct SuperSlab;
struct tiny_heap_page_t; // from tiny_heap_box.h (v1 page型)
typedef struct tiny_hotheap_page_v2 {
void* freelist;
uint16_t used;
uint16_t capacity;
uint16_t slab_idx;
uint8_t _pad;
void* base;
struct TinySlabMeta* meta; // Superslab slab meta
struct SuperSlab* ss; // Owning Superslab (meta/ss_active の整合は v1 が保持)
struct tiny_heap_page_t* lease_page; // v1 側の page 構造体freelist/used の正は常に lease_page
void* freelist;
uint16_t used;
uint16_t capacity;
uint16_t slab_idx;
uint16_t flags; // future use (HOT/PARTIAL/FULL)
void* base;
struct TinySlabMeta* meta; // Superslab slab metaCold 側は v1 が保持)
struct SuperSlab* ss; // Owning SuperslabCold 側は v1 に委譲)
struct tiny_heap_page_t* lease_page; // v1 側の page 構造体freelist/used lease_page と同期させる
struct tiny_hotheap_page_v2* next;
} tiny_hotheap_page_v2;
@ -34,7 +37,7 @@ typedef struct tiny_hotheap_class_v2 {
tiny_hotheap_page_v2* full_pages;
uint16_t stride;
uint16_t _pad;
tiny_hotheap_page_v2 storage_page; // C7 専用の 1 枚だけをまず保持
tiny_hotheap_page_v2 storage_page; // C7 専用の 1 枚だけをまず保持Phase36: reuse when空き
} tiny_hotheap_class_v2;
typedef struct tiny_hotheap_ctx_v2 {
@ -48,6 +51,28 @@ extern __thread tiny_hotheap_ctx_v2* g_tiny_hotheap_ctx_v2;
tiny_hotheap_ctx_v2* tiny_hotheap_v2_tls_get(void);
void* tiny_hotheap_v2_alloc(uint8_t class_idx);
void tiny_hotheap_v2_free(uint8_t class_idx, void* p, void* meta);
void tiny_hotheap_v2_record_route_fallback(void);
void tiny_hotheap_v2_record_free_fallback(void);
typedef struct tiny_hotheap_v2_stats_snapshot {
uint64_t route_hits;
uint64_t alloc_calls;
uint64_t alloc_fast;
uint64_t alloc_lease;
uint64_t alloc_refill;
uint64_t alloc_fallback_v1;
uint64_t alloc_route_fb;
uint64_t free_calls;
uint64_t free_fast;
uint64_t free_fallback_v1;
uint64_t prepare_calls;
uint64_t prepare_with_current_null;
uint64_t prepare_from_partial;
uint64_t free_made_current;
uint64_t page_retired;
} tiny_hotheap_v2_stats_snapshot_t;
void tiny_hotheap_v2_debug_snapshot(tiny_hotheap_v2_stats_snapshot_t* out);
static inline void tiny_hotheap_v2_page_reset(tiny_hotheap_page_v2* page) {
if (!page) return;
@ -55,6 +80,7 @@ static inline void tiny_hotheap_v2_page_reset(tiny_hotheap_page_v2* page) {
page->used = 0;
page->capacity = 0;
page->slab_idx = 0;
page->flags = 0;
page->base = NULL;
page->meta = NULL;
page->ss = NULL;