sklears_compose/resource_management/
memory_manager.rs1use super::resource_types::{MemoryAllocation, MemoryProtection, MemoryType};
7use sklears_core::error::Result as SklResult;
8use std::collections::HashMap;
9
10#[derive(Debug)]
12pub struct MemoryResourceManager {
13 pools: HashMap<String, MemoryPool>,
15 allocations: HashMap<String, MemoryAllocation>,
17 config: MemoryManagerConfig,
19}
20
21#[derive(Debug, Clone)]
23pub struct MemoryPool {
24 pub id: String,
26 pub total_size: u64,
28 pub available_size: u64,
30 pub memory_type: MemoryType,
32 pub numa_node: Option<usize>,
34}
35
36#[derive(Debug, Clone)]
38pub struct MemoryManagerConfig {
39 pub numa_aware: bool,
41 pub default_memory_type: MemoryType,
43 pub enable_huge_pages: bool,
45}
46
47impl Default for MemoryResourceManager {
48 fn default() -> Self {
49 Self::new()
50 }
51}
52
53impl MemoryResourceManager {
54 #[must_use]
56 pub fn new() -> Self {
57 Self {
58 pools: HashMap::new(),
59 allocations: HashMap::new(),
60 config: MemoryManagerConfig {
61 numa_aware: true,
62 default_memory_type: MemoryType::System,
63 enable_huge_pages: false,
64 },
65 }
66 }
67
68 pub fn allocate_memory(
70 &mut self,
71 size: u64,
72 memory_type: MemoryType,
73 ) -> SklResult<MemoryAllocation> {
74 Ok(MemoryAllocation {
75 size,
76 memory_type,
77 numa_node: Some(0),
78 virtual_address: None,
79 huge_pages: self.config.enable_huge_pages,
80 protection: MemoryProtection {
81 read: true,
82 write: true,
83 execute: false,
84 },
85 })
86 }
87
88 pub fn release_memory(&mut self, allocation: &MemoryAllocation) -> SklResult<()> {
90 Ok(())
92 }
93}