ruvector_memopt/core/
config.rs

1//! Configuration for the memory optimizer
2
3use serde::{Deserialize, Serialize};
4use std::path::PathBuf;
5
6/// Main optimizer configuration
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct OptimizerConfig {
9    /// Memory pressure threshold to trigger optimization (0-100)
10    pub pressure_threshold: u32,
11    
12    /// Critical threshold for aggressive optimization
13    pub critical_threshold: u32,
14    
15    /// Minimum interval between optimizations (seconds)
16    pub min_interval_secs: u64,
17    
18    /// Enable neural decision making
19    pub neural_enabled: bool,
20    
21    /// Path to neural model data
22    pub model_path: PathBuf,
23    
24    /// Processes to never trim
25    pub protected_processes: Vec<String>,
26    
27    /// Enable startup optimization mode
28    pub startup_mode: bool,
29    
30    /// Aggressive mode clears system caches (requires admin)
31    pub aggressive_mode: bool,
32    
33    /// Enable learning from optimization results
34    pub learning_enabled: bool,
35    
36    /// EWC lambda for forgetting prevention
37    pub ewc_lambda: f32,
38    
39    /// Benchmark mode - log detailed metrics
40    pub benchmark_mode: bool,
41}
42
43impl Default for OptimizerConfig {
44    fn default() -> Self {
45        Self {
46            pressure_threshold: 80,
47            critical_threshold: 95,
48            min_interval_secs: 30,
49            neural_enabled: true,
50            model_path: PathBuf::from("./data/neural"),
51            protected_processes: vec![
52                "System".into(),
53                "csrss.exe".into(),
54                "smss.exe".into(),
55                "lsass.exe".into(),
56                "services.exe".into(),
57            ],
58            startup_mode: false,
59            aggressive_mode: false,
60            learning_enabled: true,
61            ewc_lambda: 0.4,
62            benchmark_mode: false,
63        }
64    }
65}
66
67impl OptimizerConfig {
68    /// Load config from TOML file
69    pub fn load(path: &std::path::Path) -> Result<Self, Box<dyn std::error::Error>> {
70        let content = std::fs::read_to_string(path)?;
71        let config: Self = toml::from_str(&content)?;
72        Ok(config)
73    }
74    
75    /// Save config to TOML file
76    pub fn save(&self, path: &std::path::Path) -> Result<(), Box<dyn std::error::Error>> {
77        let content = toml::to_string_pretty(self)?;
78        std::fs::write(path, content)?;
79        Ok(())
80    }
81}