// tiny_route_box.h - Box: Tiny Front Routing Policy // // Purpose: // Decide, per Tiny class, whether allocation should go through Tiny front // or directly to the Pool/backend. This keeps routing policy in a single, // cheap table lookup, without getenv() or complex logic in the hot path. // // Box Theory: // - Single Responsibility: // Only decides "Tiny vs Pool vs Tiny+Fallback" per class. // - Clear Boundary: // Front Gate / Alloc Gatekeeper calls tiny_route_get(class_idx) once. // Tiny Fast Path and Pool backend remain unchanged. // - Reversible / A/B: // Profiles are selected via HAKMEM_TINY_PROFILE ENV at init time. // Hot path is stable; routing can be tuned without touching fast code. #ifndef TINY_ROUTE_BOX_H #define TINY_ROUTE_BOX_H #include // Routing policy per Tiny class. typedef enum { ROUTE_TINY_ONLY = 0, // Tiny front only (no fallback; failure bubbles up) ROUTE_TINY_FIRST = 1, // Try Tiny front, then fallback to Pool backend ROUTE_POOL_ONLY = 2, // Skip Tiny entirely, use Pool/backend only } TinyRoutePolicy; // Global routing table for Tiny classes (0..7). // Initialized once from ENV: HAKMEM_TINY_PROFILE. extern uint8_t g_tiny_route[8]; // Initialize routing table from ENV profile. // Profiles: // "hot" C0-C3=TINY_ONLY, C4-C6=TINY_FIRST, C7=POOL_ONLY // "conservative" 全クラス TINY_FIRST(デフォルト) // "off" 全クラス POOL_ONLY(Tiny 無効) // "full" 全クラス TINY_ONLY(microbench 用) void tiny_route_init(void); // Hot path helper: return routing policy for a given class. // Uses simple array lookup; class_idx is masked to [0,7] defensively. static inline TinyRoutePolicy tiny_route_get(int class_idx) { return (TinyRoutePolicy)g_tiny_route[class_idx & 7]; } #endif // TINY_ROUTE_BOX_H