v7-7: Implement Learner for dynamic C5 route switching
- Add SmallLearnerStatsV7 type + API to policy box - Hook ColdIface refill/retire to collect stats (capacity-based) - Implement C5 route switching: if C5 ratio < 30%, switch to MID_V3 - Version-based TLS cache invalidation for policy updates - Evaluation interval: every 100 refills Tested with c6heavy scenario: C5 ratio=12% triggers V7 → MID_V3 switch 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
// smallobject_policy_v7_box.h - SmallObject Policy v7 (Phase v7-4)
|
||||
// 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
|
||||
@ -46,4 +47,58 @@ void small_policy_v7_init_from_env(SmallPolicyV7* policy);
|
||||
/// Get route kind name for debugging
|
||||
const char* small_route_kind_name(SmallRouteKind kind);
|
||||
|
||||
// ============================================================================
|
||||
// Learner Stats (Phase v7-7)
|
||||
// ============================================================================
|
||||
|
||||
/// Per-class stats for Learner
|
||||
typedef struct SmallLearnerClassStatsV7 {
|
||||
uint64_t total_allocs; // Total allocs for this class (all routes)
|
||||
uint64_t v7_allocs; // Allocs via v7 route
|
||||
uint64_t v7_retires; // Page retires from v7
|
||||
uint32_t sample_count; // Number of samples
|
||||
} SmallLearnerClassStatsV7;
|
||||
|
||||
/// Aggregate Learner stats
|
||||
typedef struct SmallLearnerStatsV7 {
|
||||
SmallLearnerClassStatsV7 per_class[8]; // C0-C7
|
||||
uint64_t total_retires; // Total page retires
|
||||
uint64_t eval_count; // Number of evaluations
|
||||
} SmallLearnerStatsV7;
|
||||
|
||||
// ============================================================================
|
||||
// Learner API (Phase v7-7)
|
||||
// ============================================================================
|
||||
|
||||
/// Record a page retire for Learner stats (called from ColdIface)
|
||||
/// @param class_idx: Size class of the retired page
|
||||
/// @param capacity: Capacity of the page (used as traffic proxy)
|
||||
void small_learner_v7_record_retire(uint32_t class_idx, uint64_t capacity);
|
||||
|
||||
/// Record a page refill for Learner stats (called from ColdIface)
|
||||
/// @param class_idx: Size class of the refilled page
|
||||
/// @param capacity: Capacity of the page (used as traffic proxy)
|
||||
void small_learner_v7_record_refill(uint32_t class_idx, uint64_t capacity);
|
||||
|
||||
/// 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
|
||||
);
|
||||
|
||||
/// Get current Learner stats snapshot (for debugging/OBSERVE)
|
||||
const SmallLearnerStatsV7* small_learner_v7_stats_snapshot(void);
|
||||
|
||||
/// Force re-evaluation of policy from current stats
|
||||
void small_learner_v7_evaluate(void);
|
||||
|
||||
/// Learner threshold for C5 route decision (default: 30%)
|
||||
#define SMALL_LEARNER_C5_THRESHOLD_PCT 30
|
||||
|
||||
/// Evaluation interval (every N refills)
|
||||
#define SMALL_LEARNER_EVAL_INTERVAL 100
|
||||
|
||||
#endif // HAKMEM_SMALLOBJECT_POLICY_V7_BOX_H
|
||||
|
||||
Reference in New Issue
Block a user