TieringConfig allows you to tier cold tree levels to memory-mapped data files after checkpoints, reducing memory usage for large trees while maintaining hot data in memory for fast access.
Definition
Defined insrc/storage/checkpoint.rs:58
Fields
Controls the memory/disk boundary:
- Levels ≥
pin_above_level: Kept in memory (hot data) - Levels <
pin_above_level: mmap’d from disk files after checkpoint (cold data)
0- Keep everything in memory (no mmap)usize::MAX- mmap all levels (default, minimum memory)
0-2- Keep top 2 levels in memory (recent inserts hot)3-5- Moderate tieringusize::MAX- Maximum memory savings
How Tiering Works
Tree Level Structure
In an n-ary tree with branching factor N:- Level 0: Leaf level (largest, coldest)
- Level 1: First parent level
- Level 2+: Higher parent levels
- Top level: Root (smallest, hottest)
Higher level numbers = closer to root = smaller size = hotter access patterns.Level 0 (leaves) is the largest and least frequently accessed.
Memory vs Mmap
After a checkpoint:pin_above_level are remapped to mmap’d files.
Usage Examples
Default: Maximize Memory Savings
Keep Everything in Memory
Hybrid: Hot Levels in Memory
Memory Usage Examples
Each chunk is 128 hashes × 32 bytes = 4 KiB.Level sizes decrease by factor of N at each level.
N=4, MAX_DEPTH=16, 1B Leaves
Approximate level sizes:pin_above_level | Memory Usage | mmap’d Size | Profile |
|---|---|---|---|
0 | ~43 GiB | 0 | All memory |
1 | ~11 GiB | ~32 GiB | Hot path in memory |
2 | ~3 GiB | ~40 GiB | Balanced |
3 | ~700 MiB | ~42 GiB | Minimal memory |
usize::MAX | <100 MiB | ~43 GiB | Maximum savings |
N=8, MAX_DEPTH=10, 1B Leaves
Approximate level sizes:Performance Characteristics
Read Performance
| Data Location | Access Latency | Throughput |
|---|---|---|
| In-memory | ~10-50ns | Maximum |
| mmap (hot page cache) | ~100-500ns | High |
| mmap (cold, SSD) | ~10-100µs | Medium |
| mmap (cold, HDD) | ~5-10ms | Low |
Write Performance
Writes always go to in-memory WAL buffer first, so tiering doesn’t affect write latency. Impact is only on checkpoint operations.Choosing pin_above_level
Small Trees (<100M leaves)
Recommendation:
pin_above_level = 0Keep everything in memory. Memory usage is reasonable and performance is maximized.Medium Trees (100M-1B leaves)
Recommendation:
pin_above_level = 2Balance memory and performance. Top levels hot, bottom levels cold.Large Trees (>1B leaves)
Recommendation:
pin_above_level = 3 or usize::MAXMinimize memory usage. Rely on OS page cache for frequently accessed data.Proof Generation Workload
Recommendation:
pin_above_level = 1 or 2Proof generation reads from all levels. Keeping upper levels hot improves latency.Monitoring Memory Usage
Monitor actual memory usage with OS tools:Caveats
Default Value
Shard Files
After checkpointing, data files are organized as:Related
- CheckpointPolicy - When tiering remapping occurs
- RotorTreeConfig - Full configuration structure
- Tree Structure - Understanding tree levels
- Performance Tuning - Optimization strategies
