This commit introduces a comprehensive tracing mechanism for allocation failures within the Adaptive Cache Engine (ACE) component. This feature allows for precise identification of the root cause for Out-Of-Memory (OOM) issues related to ACE allocations. Key changes include: - **ACE Tracing Implementation**: - Added environment variable to enable/disable detailed logging of allocation failures. - Instrumented , , and to distinguish between "Threshold" (size class mismatch), "Exhaustion" (pool depletion), and "MapFail" (OS memory allocation failure). - **Build System Fixes**: - Corrected to ensure is properly linked into , resolving an error. - **LD_PRELOAD Wrapper Adjustments**: - Investigated and understood the wrapper's behavior under , particularly its interaction with and checks. - Enabled debugging flags for environment to prevent unintended fallbacks to 's for non-tiny allocations, allowing comprehensive testing of the allocator. - **Debugging & Verification**: - Introduced temporary verbose logging to pinpoint execution flow issues within interception and routing. These temporary logs have been removed. - Created to facilitate testing of the tracing features. This feature will significantly aid in diagnosing and resolving allocation-related OOM issues in by providing clear insights into the failure pathways.
113 lines
4.2 KiB
C
113 lines
4.2 KiB
C
// hakmem_config.h - Mode-based Configuration System
|
|
// Purpose: Centralize configuration and provide simple presets
|
|
|
|
#ifndef HAKMEM_CONFIG_H
|
|
#define HAKMEM_CONFIG_H
|
|
|
|
#include <stddef.h> // for size_t
|
|
#include "hakmem_features.h"
|
|
|
|
// ===========================================================================
|
|
// Configuration Modes
|
|
// ===========================================================================
|
|
|
|
typedef enum {
|
|
HAKMEM_MODE_MINIMAL = 0, // Baseline: malloc/mmap only
|
|
HAKMEM_MODE_FAST, // Production: pool fast-path + FROZEN learning
|
|
HAKMEM_MODE_BALANCED, // Default: BigCache + ELO FROZEN + Batch
|
|
HAKMEM_MODE_LEARNING, // Development: ELO LEARN + adaptive
|
|
HAKMEM_MODE_RESEARCH, // Debug: All features + verbose logging
|
|
} HakemMode;
|
|
|
|
// ===========================================================================
|
|
// Free Policy (from Phase 6.4 P1)
|
|
// ===========================================================================
|
|
|
|
typedef enum {
|
|
FREE_POLICY_BATCH, // Default: BigCache miss → batch
|
|
FREE_POLICY_KEEP, // Keep VA mapped, no madvise (HOT strategy)
|
|
FREE_POLICY_ADAPTIVE // Adaptive: Hot/Warm/Cold based on size
|
|
} FreePolicy;
|
|
|
|
// ===========================================================================
|
|
// THP Policy (from Phase 6.4 P4)
|
|
// ===========================================================================
|
|
|
|
typedef enum {
|
|
THP_POLICY_OFF, // No THP (MADV_NOHUGEPAGE for all)
|
|
THP_POLICY_AUTO, // Auto: >=2MB → MADV_HUGEPAGE, <2MB → MADV_NOHUGEPAGE
|
|
THP_POLICY_ON // Force THP for all (MADV_HUGEPAGE for all >= 1MB)
|
|
} THPPolicy;
|
|
|
|
// ===========================================================================
|
|
// Evolution Phase (from Phase 6.5)
|
|
// ===========================================================================
|
|
|
|
typedef enum {
|
|
EVO_PHASE_LEARN, // Learning mode: collect data, select strategies
|
|
EVO_PHASE_FROZEN, // Frozen mode: use confirmed strategy, no learning
|
|
EVO_PHASE_CANARY, // Canary mode: test new candidate, roll back if bad
|
|
} EvoPhase;
|
|
|
|
// ===========================================================================
|
|
// Global Configuration
|
|
// ===========================================================================
|
|
|
|
typedef struct {
|
|
// Mode
|
|
HakemMode mode;
|
|
const char* mode_name; // For logging
|
|
|
|
// Features (bitflags)
|
|
HakemFeatureSet features;
|
|
|
|
// Policies
|
|
FreePolicy free_policy;
|
|
THPPolicy thp_policy;
|
|
EvoPhase evo_phase;
|
|
|
|
// Parameters
|
|
int elo_frozen_strategy; // Strategy ID for FROZEN mode (0-11)
|
|
size_t batch_threshold; // Minimum size for batch madvise
|
|
|
|
// Debug
|
|
int verbose; // 0=off, 1=minimal, 2=verbose
|
|
int ace_trace; // 0=off, 1=on (log OOM failures)
|
|
} HakemConfig;
|
|
|
|
// ===========================================================================
|
|
// Global Instance
|
|
// ===========================================================================
|
|
|
|
extern HakemConfig g_hakem_config;
|
|
|
|
// ===========================================================================
|
|
// Initialization
|
|
// ===========================================================================
|
|
|
|
// Initialize configuration from environment variables
|
|
// Priority: HAKMEM_MODE > individual env vars > defaults
|
|
void hak_config_init(void);
|
|
|
|
// Apply a mode preset
|
|
void hak_config_apply_mode(HakemMode mode);
|
|
|
|
// Print current configuration (for debugging)
|
|
void hak_config_print(void);
|
|
|
|
// ===========================================================================
|
|
// Mode Presets (Implementation in hakmem_config.c)
|
|
// ===========================================================================
|
|
|
|
// Mode name strings
|
|
const char* hak_mode_name(HakemMode mode);
|
|
|
|
// Check if a specific feature is enabled
|
|
#define HAK_ENABLED_ALLOC(f) hak_has_feature_alloc(&g_hakem_config.features, (f))
|
|
#define HAK_ENABLED_CACHE(f) hak_has_feature_cache(&g_hakem_config.features, (f))
|
|
#define HAK_ENABLED_LEARNING(f) hak_has_feature_learning(&g_hakem_config.features, (f))
|
|
#define HAK_ENABLED_MEMORY(f) hak_has_feature_memory(&g_hakem_config.features, (f))
|
|
#define HAK_ENABLED_DEBUG(f) hak_has_feature_debug(&g_hakem_config.features, (f))
|
|
|
|
#endif // HAKMEM_CONFIG_H
|