MAI is a library that transparently intercepts memory allocation functions in any applications to provide fallback mechanisms when standard allocations fail. When a program runs out of heap memory, MAI automatically falls back to using memory-mapped files, ensuring the application continues running even under memory pressure.
- Intercepts standard memory functions (
malloc
,calloc
,realloc
,aligned_alloc
,posix_memalign
,free
) - Provides seamless mmap-based fallback when heap allocations fail
- Maintains memory usage statistics
- Configurable mmap directory via environment variables
- Thread-safe implementation
MAI is perfect for applications that need to handle large memory allocations or operate in memory-constrained environments without crashing.
mkdir build
cd build
cmake --install-prefix=$HOME ..
make
LD_PRELOAD=libmai.so ./target_application_here
MAI_MMAP_PATH=./ # Directory to store the mmap file. The default is `./`, the current directory.