👎Deprecated since 0.2.0: Use jemalloc feature instead. See buddy_allocator module docs for migration.
Expand description
Buddy Allocator for SochDB Memory Management
§DEPRECATION NOTICE
This module is deprecated and will be removed in a future release.
§Recommendation: Use jemalloc Instead
Enable the jemalloc feature in your Cargo.toml:
sochdb-core = { version = "...", features = ["jemalloc"] }§Why jemalloc is preferred:
- Production-proven: Used by Firefox, Facebook, Redis, RocksDB
- Thread-local caching: Eliminates lock contention on hot paths
- Better fragmentation handling: Size-class based allocation
- Automatic memory return: Returns memory to OS via
madvise - No maintenance burden: Well-tested, battle-hardened code
§Issues with this custom allocator:
- Virtual address tracking only: Does not manage real memory
- Lock contention: RwLock on every allocation
- No memory reclamation: Never returns memory to OS
- Internal fragmentation: Buddy allocation wastes ~50% for small allocs
§Migration Path
If you are using BuddyAllocator or SlabAllocator directly:
ⓘ
// Before (deprecated):
let allocator = BuddyAllocator::new(64 * 1024 * 1024)?;
let addr = allocator.allocate(1024)?;
// After (recommended):
// Simply enable the jemalloc feature and use standard allocation:
let buffer: Vec<u8> = Vec::with_capacity(1024);§Original Documentation
Implements a buddy system allocator for efficient power-of-2 memory block allocation. Key features:
- O(1) allocation and deallocation for available blocks
- Automatic block splitting and merging
- Memory coalescing to reduce fragmentation
- Thread-safe with fine-grained locking
- Support for multiple memory pools
Structs§
- Block
Header Deprecated - Block header stored at the beginning of each block
- Buddy
Allocator Deprecated - Multi-pool buddy allocator
- Buddy
Arena Deprecated - Arena allocator using buddy allocator for backing storage
- Buddy
Stats Deprecated - Statistics for the buddy allocator
- Memory
Pool Deprecated - A single memory pool managed by the buddy allocator
- Slab
Allocator Deprecated - Slab allocator built on top of buddy allocator for fixed-size objects
- Typed
Buddy Allocator Deprecated - A typed buddy allocator for allocating objects of a specific type
Enums§
- Buddy
Error Deprecated - Error types for buddy allocator operations
Constants§
- DEFAULT_
POOL_ SIZE Deprecated - Default pool size (64 MB)
- MAX_
BLOCK_ SIZE Deprecated - Maximum block size (1 GB)
- MIN_
BLOCK_ SIZE Deprecated - Minimum block size (16 bytes)
Functions§
- buddy_
addr Deprecated - Calculate buddy address for a given address and order
- order_
to_ size Deprecated - Calculate the size for a given order
- size_
to_ order Deprecated - Calculate the order (log2) for a given size