Files
hakmem/core/box/smallobject_v6_env_box.h
Moe Charm (CI) df216b6901 Phase V6-HDR-3: SmallSegmentV6 実割り当て & RegionIdBox Registration
実装内容:
1. SmallSegmentV6のmmap割り当ては既に v6-0で実装済み
2. small_heap_ctx_v6() で segment 取得時に region_id_register_v6_segment() 呼び出し
3. region_id_v6.c に TLS スコープのセグメント登録ロジック実装:
   - 4つの static __thread 変数でセグメント情報をキャッシュ
   - region_id_register_v6_segment(): セグメント base/end を TLS に記録
   - region_id_lookup_v6(): TLS segment の range check を最初に実行
   - TLS cache 更新で O(1) lookup 実現
4. region_id_v6_box.h に SmallSegmentV6 type include & function 宣言追加
5. small_v6_region_observe_validate() に region_id_observe_lookup() 呼び出し追加

効果:
- HeaderlessデザインでRegionIdBoxが正式にSMALL_V6分類を返せるように
- TLS-scopedな簡潔な登録メカニズム (マルチスレッド対応)
- Fast path: TLS segment range check -> page_meta lookup
- Fall back path: 従来の small_page_meta_v6_of() による動的検出
- Latency: O(1) TLS cache hit rate がv6 alloc/free の大部分をカバー

🤖 Generated with Claude Code

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-11 23:51:48 +09:00

92 lines
3.6 KiB
C

// smallobject_v6_env_box.h - SmallObject v6 ENV Control Box (Headerless Mode)
//
// Phase V6-HDR-2: Additional ENV control for headerless mode
// - Uses tiny_route_env_box.h for v6_enabled and class_enabled
// - Adds headerless-specific ENV gates
#ifndef HAKMEM_SMALLOBJECT_V6_ENV_BOX_H
#define HAKMEM_SMALLOBJECT_V6_ENV_BOX_H
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include "tiny_route_env_box.h" // For small_heap_v6_enabled, small_heap_v6_class_enabled
#ifndef likely
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#endif
// ============================================================================
// ENV: HAKMEM_SMALL_HEAP_V6_HEADERLESS
// ============================================================================
// Enable headerless mode for v6. Default OFF.
// When ON:
// - free: use RegionIdBox lookup instead of header
// - alloc: skip header write (rely on carve-time header)
#define V6_HEADERLESS_UNINIT (-1)
#define V6_HEADERLESS_OFF 0
#define V6_HEADERLESS_ON 1
static int g_small_heap_v6_headerless = V6_HEADERLESS_UNINIT;
static inline bool small_heap_v6_headerless_enabled(void) {
if (unlikely(g_small_heap_v6_headerless == V6_HEADERLESS_UNINIT)) {
const char* env = getenv("HAKMEM_SMALL_HEAP_V6_HEADERLESS");
g_small_heap_v6_headerless = (env && env[0] == '1') ? V6_HEADERLESS_ON : V6_HEADERLESS_OFF;
}
return g_small_heap_v6_headerless == V6_HEADERLESS_ON;
}
// ============================================================================
// ENV: HAKMEM_SMALL_V6_REGION_OBSERVE (moved from smallobject_core_v6.c)
// ============================================================================
// Enable OBSERVE mode for class_idx validation. Default OFF.
#define V6_REGION_OBS_UNINIT (-1)
#define V6_REGION_OBS_OFF 0
#define V6_REGION_OBS_ON 1
static int g_small_v6_region_observe_env = V6_REGION_OBS_UNINIT;
static inline bool small_v6_region_observe_enabled(void) {
if (unlikely(g_small_v6_region_observe_env == V6_REGION_OBS_UNINIT)) {
const char* env = getenv("HAKMEM_SMALL_V6_REGION_OBSERVE");
g_small_v6_region_observe_env = (env && env[0] == '1') ? V6_REGION_OBS_ON : V6_REGION_OBS_OFF;
}
return g_small_v6_region_observe_env == V6_REGION_OBS_ON;
}
// ============================================================================
// Combined Gate: v6 headerless route enabled for class
// ============================================================================
/// Check if v6 headerless route is enabled for a given class
/// Uses small_heap_v6_enabled() and small_heap_v6_class_enabled() from tiny_route_env_box.h
/// @param class_idx: class index (4=C4, 5=C5, 6=C6)
/// @return: true if v6 headerless free/alloc should be used
static inline bool small_v6_headerless_route_enabled(uint8_t class_idx) {
return small_heap_v6_enabled() &&
small_heap_v6_headerless_enabled() &&
small_heap_v6_class_enabled((uint32_t)class_idx);
}
// ============================================================================
// Debug: Dump ENV state
// ============================================================================
static inline void small_v6_env_dump(void) {
// Force init
(void)small_heap_v6_enabled();
(void)small_heap_v6_headerless_enabled();
(void)small_v6_region_observe_enabled();
fprintf(stderr, "[V6_ENV] enabled=%d headerless=%d observe=%d\n",
small_heap_v6_enabled() ? 1 : 0,
g_small_heap_v6_headerless == V6_HEADERLESS_ON,
g_small_v6_region_observe_env == V6_REGION_OBS_ON);
}
#endif // HAKMEM_SMALLOBJECT_V6_ENV_BOX_H