The Cache Simulator supports multiple cache replacement policies through a pluggable framework.
- Description: Evicts the least recently used block
- Implementation: Maintains access order for each set
- Best for: General-purpose workloads with temporal locality
- Configuration:
"replacementPolicy": "LRU"
- Description: Evicts the oldest block in the set
- Implementation: Tracks installation order
- Best for: Streaming workloads with no reuse
- Configuration:
"replacementPolicy": "FIFO"
- Description: Uses reference bits to track recent usage
- Implementation: Periodically clears reference bits
- Best for: Workloads with mixed access patterns
- Configuration:
"replacementPolicy": "NRU"
- Description: Randomly selects a block for eviction
- Implementation: Uses random number generator
- Best for: Simple implementation, unpredictable workloads
- Configuration:
"replacementPolicy": "Random"
- Description: Approximates LRU using binary tree
- Implementation: Tree-based tracking with fewer bits
- Best for: Hardware-efficient LRU approximation
- Requirement: Associativity must be a power of 2 (2, 4, 8, 16, …)
- Configuration:
"replacementPolicy": "PLRU"
| Policy | Memory Overhead | Complexity | Typical Hit Rate |
|---|---|---|---|
| LRU | High | O(log n) | Highest |
| FIFO | Low | O(1) | Medium |
| NRU | Low | O(1) | High |
| Random | Minimal | O(1) | Low |
| PLRU | Medium | O(log n) | High |
{
"l1": {
"replacementPolicy": "NRU"
},
"l2": {
"replacementPolicy": "LRU"
}
}{
"l1": {
"size": 32768,
"associativity": 4,
"replacementPolicy": "NRU"
},
"l2": {
"size": 262144,
"associativity": 8,
"replacementPolicy": "LRU"
}
}class ReplacementPolicyBase {
public:
virtual void onAccess(int blockIndex) = 0;
virtual void onInstall(int blockIndex) = 0;
virtual int selectVictim(const std::vector<bool>& validBlocks) = 0;
virtual void reset() = 0;
};- Inherit from
ReplacementPolicyBase - Implement required methods
- Register in
ReplacementPolicyFactory - Add configuration support
Performance comparison on typical workloads:
- LRU: 85.2% hit rate
- NRU: 83.7% hit rate
- FIFO: 78.1% hit rate
- Random: 72.3% hit rate
- PLRU: 84.1% hit rate
- LRU: 92.1% hit rate
- NRU: 91.8% hit rate
- FIFO: 89.2% hit rate
- Random: 76.4% hit rate
- PLRU: 91.5% hit rate
- Primary: LRU for highest performance
- Alternative: NRU for good performance with lower overhead
- Primary: FIFO for simplicity
- Alternative: NRU for better performance
- Primary: PLRU for hardware efficiency
- Alternative: NRU for software implementation
- Primary: Random for baseline comparison
- Alternative: Custom policies for specific workloads