1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Allocator configuration.
/// Configuration for the memory allocator.
#[derive(Debug, Clone)]
pub struct MkConfig {
/// Size of the frame arena per thread (default: 16 MB)
pub frame_arena_size: usize,
/// Size classes for the slab allocator
pub slab_size_classes: Vec<usize>,
/// Number of pages to pre-allocate per size class
pub slab_pages_per_class: usize,
/// Page size for slab allocator (default: 64 KB)
pub slab_page_size: usize,
/// Enable memory budgeting
pub enable_budgets: bool,
/// Global memory limit (0 = unlimited)
pub global_memory_limit: usize,
/// Enable debug features (memory poisoning, etc.)
pub debug_mode: bool,
}
impl Default for MkConfig {
fn default() -> Self {
Self {
frame_arena_size: 16 * 1024 * 1024, // 16 MB
slab_size_classes: vec![16, 32, 64, 128, 256, 512, 1024, 2048, 4096],
slab_pages_per_class: 4,
slab_page_size: 64 * 1024, // 64 KB
enable_budgets: false,
global_memory_limit: 0,
debug_mode: cfg!(debug_assertions),
}
}
}
impl MkConfig {
/// Create a minimal config for testing or constrained environments.
pub fn minimal() -> Self {
Self {
frame_arena_size: 1024 * 1024, // 1 MB
slab_size_classes: vec![32, 128, 512, 2048],
slab_pages_per_class: 1,
slab_page_size: 16 * 1024, // 16 KB
enable_budgets: false,
global_memory_limit: 0,
debug_mode: false,
}
}
/// Create a config optimized for high-throughput scenarios.
pub fn high_throughput() -> Self {
Self {
frame_arena_size: 64 * 1024 * 1024, // 64 MB
slab_size_classes: vec![16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192],
slab_pages_per_class: 8,
slab_page_size: 128 * 1024, // 128 KB
enable_budgets: false,
global_memory_limit: 0,
debug_mode: false,
}
}
}