Files
hakmem/core/box/smallobject_policy_v7_box.h
Moe Charm (CI) d54893ea1d Phase 3 C3: Static Routing A/B Test ADOPT (+2.20% Mixed gain)
Step 2 & 3 Complete:
- A/B test (Mixed 10-run): STATIC_ROUTE=0 (38.91M) → =1 (39.77M) = +2.20% avg
  - Median gain: +1.98%
  - Result:  GO (exceeds +1.0% threshold)

- Decision:  ADOPT into MIXED_TINYV3_C7_SAFE preset
  - bench_profile.h line 77: HAKMEM_TINY_STATIC_ROUTE=1 default
  - Learner auto-disables static route when HAKMEM_SMALL_LEARNER_V7_ENABLED=1

Implementation Summary:
- core/box/tiny_static_route_box.{h,c}: Research box (Step 1A)
- core/front/malloc_tiny_fast.h: Route lookup integration (Step 1B, lines 249-256)
- core/bench_profile.h: Bench sync + preset adoption

Cumulative Phase 2-3 Gains:
- B3 (Routing shape): +2.89%
- B4 (Wrapper split): +1.47%
- C3 (Static routing): +2.20%
- Total: ~6.8% (35.2M → ~39.8M ops/s)

Next: Phase 3 C1 (TLS Prefetch, expected +2-4%)

🤖 Generated with Claude Code

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-13 18:46:11 +09:00

66 lines
2.6 KiB
C

// smallobject_policy_v7_box.h - SmallObject Policy v7 (Phase v7-7: Learner integration)
//
// Purpose:
// - Centralized routing policy for ULTRA / v7 / MID_v3 / LEGACY
// - Single source of truth for class → route_kind mapping
// - ENV configuration managed in one place (L3 Policy layer)
// - Learner: dynamic route switching based on workload stats (v7-7)
#ifndef HAKMEM_SMALLOBJECT_POLICY_V7_BOX_H
#define HAKMEM_SMALLOBJECT_POLICY_V7_BOX_H
#include <stdint.h>
#include <stdbool.h>
#include "smallobject_learner_v7_box.h" // For SmallLearnerStatsV7 type
// ============================================================================
// Route Kind Enum (L0/L1/L1' layer selection)
// ============================================================================
typedef enum {
SMALL_ROUTE_ULTRA, // L0: C4-C7 ULTRA (FROZEN)
SMALL_ROUTE_V7, // L1: SmallObject v7 (research box)
SMALL_ROUTE_MID_V3, // L1': MID v3 (257-768B mid/small)
SMALL_ROUTE_MID_V35, // L1': MID v3.5 (v11a-3: Segment/ColdIface/Stats/Learner v2)
SMALL_ROUTE_LEGACY, // L1': TinyHeap v1 / Pool v1 (fallback)
} SmallRouteKind;
// ============================================================================
// Policy Snapshot Structure
// ============================================================================
typedef struct SmallPolicyV7 {
SmallRouteKind route_kind[8]; // C0-C7 routing decision
} SmallPolicyV7;
// ============================================================================
// Policy API
// ============================================================================
/// Get policy snapshot (read-only, TLS cached)
/// Frontend calls this to determine route_kind[class_idx]
const SmallPolicyV7* small_policy_v7_snapshot(void);
/// Bench/helper: invalidate all TLS snapshots by bumping global version.
/// Next call to small_policy_v7_snapshot() will re-read ENV (and apply learner, if enabled).
void small_policy_v7_bump_version(void);
/// Initialize policy from ENV variables (called once at startup)
/// Priority: ULTRA > v7 > MID_v3 > LEGACY
/// @param policy: Policy structure to initialize
void small_policy_v7_init_from_env(SmallPolicyV7* policy);
/// Get route kind name for debugging
const char* small_route_kind_name(SmallRouteKind kind);
/// Update policy from Learner stats (called periodically)
/// Decision rule: if C5 alloc ratio > 30%, route C5 to v7, else MID_v3
/// @param stats: Learner stats to evaluate
/// @param policy_out: Policy to update
void small_policy_v7_update_from_learner(
const SmallLearnerStatsV7* stats,
SmallPolicyV7* policy_out
);
#endif // HAKMEM_SMALLOBJECT_POLICY_V7_BOX_H