Phase v7-5b: C5+C6 multi-class expansion (+4.3% improvement)

- Add C5 (256B blocks) support alongside C6 (512B blocks)
- Same segment shared between C5/C6 (page_meta.class_idx distinguishes)
- SMALL_V7_CLASS_SUPPORTED() macro for class validation
- Extend small_v7_block_size() for C5 (switch statement)

A/B Result: C6-only v7 avg 7.64M ops/s → C5+C6 v7 avg 7.97M ops/s (+4.3%)
Criteria: C6 protected , C5 net positive , TLS bloat none 

ENV: HAKMEM_SMALL_HEAP_V7_CLASSES=0x60 (bit5+bit6)

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Moe Charm (CI)
2025-12-12 05:11:02 +09:00
parent 17ceed619c
commit d5aa3110c6
5 changed files with 146 additions and 20 deletions

View File

@ -1,14 +1,18 @@
// smallobject_hotbox_v7_box.h - SmallObject HotBox v7 (Phase v7-5a: Hot path極限最適化)
// smallobject_hotbox_v7_box.h - SmallObject HotBox v7 (Phase v7-5b: C5+C6 Multi-class)
//
// Role:
// - SmallObject v7 fast path for alloc/free
// - C6-only implementation (512B blocks, 64KiB pages, 2MiB segments)
// - C5+C6 implementation (256B/512B blocks, 64KiB pages, 2MiB segments)
// - Uses SmallHeapCtx_v7 + SmallSegment_v7 + ColdIface_v7
//
// v7-5a optimizations:
// - Stats (alloc_count, free_count, live_current) removed from hot path
// - Global atomic stats gated by ENV (HAKMEM_V7_HOT_STATS)
// - Header write kept (required due to intrusive freelist overlapping block[0])
//
// v7-5b additions:
// - C5 support (256B blocks) with minimal TLS overhead
// - Same segment shared between C5 and C6 (page_meta.class_idx distinguishes)
#pragma once
@ -67,7 +71,7 @@ static inline void small_v7_log_class_mismatch(void* ptr, uint8_t hint, uint8_t
// Alloc Fast Path
// ============================================================================
// small_heap_alloc_fast_v7() - v7 alloc (C6-only, v7-5a: Hot path極限最適化)
// small_heap_alloc_fast_v7() - v7 alloc (v7-5b: C5+C6 multi-class)
//
// Flow:
// 1. Get TLS context
@ -80,9 +84,11 @@ static inline void small_v7_log_class_mismatch(void* ptr, uint8_t hint, uint8_t
// - Per-page stats (alloc_count, live_current) removed from hot path
// - Global atomic stats gated by ENV (HAKMEM_V7_HOT_STATS)
//
// v7-5b: C5+C6 support (same code path, different block sizes)
//
static inline void* small_heap_alloc_fast_v7(size_t size, uint8_t class_idx) {
// v7-2: Only C6 is implemented
if (unlikely(class_idx != SMALL_V7_C6_CLASS_IDX)) {
// v7-5b: C5 or C6 supported
if (unlikely(!SMALL_V7_CLASS_SUPPORTED(class_idx))) {
return NULL; // Unsupported class -> front falls back
}
@ -152,7 +158,7 @@ static inline void* small_heap_alloc_fast_v7(size_t size, uint8_t class_idx) {
// Free Fast Path
// ============================================================================
// small_heap_free_fast_v7() - v7 free (C6-only, v7-5a: Hot path極限最適化)
// small_heap_free_fast_v7() - v7 free (v7-5b: C5+C6 multi-class)
//
// Flow:
// 1. TLS segment hint hit (skip RegionIdBox)
@ -162,6 +168,8 @@ static inline void* small_heap_alloc_fast_v7(size_t size, uint8_t class_idx) {
// - Stats (free_count, live_current) removed from hot path
// - Global atomic stats gated by ENV
//
// v7-5b: C5+C6 support (page->class_idx determines actual class)
//
// @param ptr: USER pointer to free
// @param class_idx_hint: Class index hint from front/header (may be ignored)
// @return: true if handled by v7, false if not v7-managed (front should fallback)
@ -194,8 +202,8 @@ static inline bool small_heap_free_fast_v7(void* ptr, uint8_t class_idx_hint) {
SmallPageMeta_v7* page = &seg->page_meta[page_idx];
// Validate page is in use and C6-only
if (unlikely(page->capacity == 0 || page->class_idx != SMALL_V7_C6_CLASS_IDX)) {
// v7-5b: Validate page is in use and C5 or C6
if (unlikely(page->capacity == 0 || !SMALL_V7_CLASS_SUPPORTED(page->class_idx))) {
return false;
}
@ -245,8 +253,8 @@ regionid_fallback:
SmallPageMeta_v7* page = &seg->page_meta[page_idx];
// Validate page is in use and C6-only
if (unlikely(page->capacity == 0 || page->class_idx != SMALL_V7_C6_CLASS_IDX)) {
// v7-5b: Validate page is in use and C5 or C6
if (unlikely(page->capacity == 0 || !SMALL_V7_CLASS_SUPPORTED(page->class_idx))) {
return false;
}