Skip to main content

oxigdal_core/memory/
mod.rs

1//! Advanced Memory Optimization for Geospatial Data
2//!
3//! This module provides comprehensive memory management features optimized for
4//! geospatial workloads, including:
5//!
6//! - Custom allocators (slab, buddy) for efficient tile allocation
7//! - Memory-mapped I/O with read-ahead and write-behind
8//! - Zero-copy data transfers between operations
9//! - Arena allocators for batch processing
10//! - Memory pools for buffer reuse
11//! - NUMA-aware allocation for multi-socket systems
12//! - Huge pages support for large datasets
13//!
14//! # Performance Targets
15//!
16//! - 50% reduction in memory usage for large datasets
17//! - 2-3x faster allocation for small objects
18//! - Zero-copy transfers where possible
19//! - NUMA local access > 90%
20//!
21//! # Example
22//!
23//! ```
24//! use oxigdal_core::memory::{Pool, PoolConfig};
25//! use oxigdal_core::error::Result;
26//!
27//! # fn main() -> Result<()> {
28//! // Create a memory pool for 4KB buffers
29//! let config = PoolConfig::new()
30//!     .with_size_class(4096, 100);
31//! let pool = Pool::with_config(config)?;
32//!
33//! // Allocate a buffer from the pool
34//! let buffer = pool.allocate(4096)?;
35//! # Ok(())
36//! # }
37//! ```
38
39pub mod allocator;
40pub mod arena;
41#[cfg(unix)]
42pub mod hugepages;
43#[cfg(unix)]
44pub mod mmap;
45#[cfg(unix)]
46pub mod numa;
47pub mod pool;
48pub mod zero_copy;
49
50// Re-export commonly used types
51pub use allocator::{
52    Allocator, AllocatorStats, BuddyAllocator, SlabAllocator, ThreadLocalAllocator,
53};
54pub use arena::{Arena, ArenaPool, ArenaStats};
55#[cfg(unix)]
56pub use hugepages::{HugePageAllocator, HugePageConfig, HugePageSize, HugePageStats};
57#[cfg(unix)]
58pub use mmap::{MemoryMap, MemoryMapConfig, MemoryMapMode};
59#[cfg(unix)]
60pub use numa::{NumaAllocator, NumaConfig, NumaNode, NumaStats};
61pub use pool::{Pool, PoolConfig, PoolStats};
62pub use zero_copy::{SharedBuffer, ZeroCopyBuffer, ZeroCopyConfig};
63
64/// Memory alignment for SIMD operations (64 bytes for AVX-512)
65pub const SIMD_ALIGNMENT: usize = 64;
66
67/// Memory alignment for GPU transfers (256 bytes)
68pub const GPU_ALIGNMENT: usize = 256;
69
70/// Default page size (4KB)
71pub const PAGE_SIZE: usize = 4096;
72
73/// Huge page size (2MB on most systems)
74pub const HUGE_PAGE_SIZE: usize = 2 * 1024 * 1024;
75
76/// Maximum pool size before compaction (1GB)
77pub const MAX_POOL_SIZE: usize = 1024 * 1024 * 1024;
78
79#[cfg(test)]
80mod tests {
81    use super::*;
82
83    #[test]
84    fn test_constants() {
85        assert_eq!(SIMD_ALIGNMENT, 64);
86        assert_eq!(GPU_ALIGNMENT, 256);
87        assert_eq!(PAGE_SIZE, 4096);
88        assert_eq!(HUGE_PAGE_SIZE, 2 * 1024 * 1024);
89    }
90}