cache-miss-analyzer

Dynamic-Way LRU — a dynamic allocation approach


The Dynamic-Way LRU (Least Recently Used) cache is a memory caching mechanism that dynamically allocates and evicts cache blocks based on access patterns. Unlike traditional set-associative caches that pre-allocate all blocks with valid field all set to false, this approach only creates cache blocks when needed, ensuring efficient memory usage while maintaining LRU-based eviction.


Features


Implementation Details




Step-by-Step Explanation

Initial State

Empty Cache Set: Before any memory accesses, the set only has dummy head and dummy tail.

0


First Access: A1115550

Miss! A1115550 is not in the set.

Insert it at the front of the list.

0


Second Access: A1115551

Miss! A1115551 is also missing.

Insert it at the front, shifting A1115550 back.

0


Third Access: A1115550

Hit! A1115550 is in the set.

Move it to the front.

0


Filling Up the Set (Set is Full)

More blocks (A1115552, A1115553) are accessed and added until the set is full (4-way associativity).

0

The set is now full, next miss will trigger LRU eviction.


Access A1115560 (Eviction required)

Miss! Because A1115560 is not in the set.

The set is full => Evict LRU block (A1115551).

Insert A1115560 at the front.

0


Another Hit – A1115550

Hit! A1115550 is in the set.

Move it to the front (MRU).

0


Time Complexity Analysis

Lookup (Hit/Miss Checking)


Insert New Block (On Miss)

Overall: O(1) + O(1) = O(1).


Move Block to Head (On Hit)

Overall: O(1) + O(1) + O(1) = O(1).


Eviction (When the set is full)

Overall: O(1) + O(1) + O(1) + O(1) = O(1).


Summary

Operation Complexity
Lookup O(1)
Insert O(1)
Move to Head O(1)
Eviction O(1)


Overall Complexity: O(1).



Getting Started

Prerequisites

Building and Running

Clone the repository

git clone https://github.com/mellivorandy/cache-miss-analyzer.git


From the project root, run:

cargo build


To execute the program with custom arguments, use the following command:

cargo run -p dynamic_way_lru -- <trace_file_name> <cache_size> <block_size> <set_degree>


In this project structure, the trace.txt file is located in cache-miss-analyzer/data, change the path if the trace file is moved or new trace files are added.


Note: If the file path remains unchanged, use the path as given. Simply copy and paste the following command into your terminal:

Example command

cargo run -p dynamic_way_lru -- ./data/trace.txt 128 4 1



Test

A [cfg(test)] test module is included, referencing a trace.txt file for unit tests. To run them:

cargo test -p dynamic_way_lru -- --nocapture

This prints the non-empty sets.



Acknowledgments

I sincerely appreciate the incredible work behind Mermaid.js, an open-source diagramming tool that makes visualizing complex ideas effortless. Huge thanks to the developers and contributors who maintain and improve this fantastic project!