Skip to main content

Cache Replacement Policies: A Complete Guide to LRU, FIFO, and Random Replacement


Cache Replacement Policies: A Complete Guide to LRU, FIFO, and Random Replacement

Modern processors are much faster than main memory (RAM), so computers use cache memory to store frequently accessed data and reduce memory access time. However, cache memory has limited capacity. When the cache becomes full and a new memory block needs to be loaded, the system must decide which existing cache block should be removed to make space for the new one.

This decision is made using a Cache Replacement Policy.

Different replacement policies affect the cache hit rate, miss rate, hardware complexity, and overall system performance. In this article, we'll explore the three most common cache replacement policies—Least Recently Used (LRU), First-In First-Out (FIFO), and Random Replacement—along with their working principles, examples, advantages, disadvantages, and comparisons.

What is a Cache Replacement Policy?

A Cache Replacement Policy is an algorithm used to decide which cache block should be evicted when:

  • The cache set is full.
  • A new memory block must be inserted.
  • No empty cache line is available.

The main objective is to remove the block that is least likely to be needed in the near future, thereby maximizing the cache hit rate and minimizing cache misses.

Definition:
A Cache Replacement Policy is the strategy used to determine which cache block should be removed when inserting a new block into a full cache.

Why Are Replacement Policies Needed?




To compare all policies fairly, we'll use the same example.



1. Least Recently Used (LRU)

LRU assumes that data not used for the longest time is least likely to be used again soon.

Therefore, it removes the least recently accessed block.

Basic Idea

Instead of tracking when a block entered the cache,

LRU tracks when each block was last accessed.

Whenever a block is accessed,

its "recently used" status is updated.

Working Principle

  1. Insert new blocks until the cache is full.
  2. Every access updates the usage order.
  3. When replacement is needed,
    remove the least recently used block.
  4. Insert the new block.



Advantages

  • Very low miss rate.
  • Uses recent program behavior.
  • Excellent performance.
  • Widely used in modern processors.

Disadvantages

  • Hardware implementation is complex.
  • Needs extra bits or counters.
  • Higher hardware cost.

2. FIFO (First-In First-Out)

FIFO replaces the block that has stayed in the cache for the longest time.

It completely ignores whether the block has been recently used.

Basic Idea

The oldest inserted block is removed first.

The replacement order never changes after insertion.

Working Principle

Maintain a queue.

  • New blocks enter at the rear.
  • Oldest block leaves from the front.

Example Walkthrough



Advantages

  • Easy to implement.
  • Requires very little hardware.
  • Suitable for simple cache systems.

Disadvantages

  • Frequently used blocks may be removed.
  • Miss rate is higher than LRU.
  • Does not consider access history.

3. Random Replacement

Random Replacement chooses a cache block randomly for eviction.

No usage information or insertion order is maintained.

Basic Idea

Every cache block has an equal probability of being replaced.

Working Principle

  1. Generate a random cache line.
  2. Remove that block.
  3. Insert the new block.

Example Walkthrough



Advantages

  • Simplest implementation.
  • Very low hardware cost.
  • No bookkeeping required.

Disadvantages

  • Performance is unpredictable.
  • Higher miss rate.
  • May remove frequently used blocks.

Comparison of Replacement Policies



Hardware Complexity

LRU

Requires:

  • Counters
  • Timestamps
  • Linked lists
  • Usage bits

Highest hardware complexity.

FIFO

Requires only:

  • Queue pointer

Very easy implementation.

Random

Requires:

  • Random number generator

Simplest hardware.

Real-World Analogy

Imagine a bookshelf that holds only four books.

LRU

Remove the book you haven't read for the longest time.

This is usually the smartest choice.

FIFO

Remove the book that was placed on the shelf first,

even if you're still reading it.

Random

Close your eyes,

pick any book,

remove it.

Sometimes lucky,

sometimes terrible.

Which Policy Performs Best?

LRU

Works best because programs exhibit Temporal Locality.

Recently used data is likely to be accessed again.

FIFO

Good for simple hardware,

but ignores program behavior.

Random

Useful only when hardware simplicity matters more than performance.

Cache Miss Rate Comparison

Typical trend:

PolicyApproximate Miss Rate
LRULowest
FIFOModerate
RandomHighest

Actual miss rates depend on:

  • Program behavior
  • Cache size
  • Associativity
  • Block size

Practical Applications

LRU

  • Modern CPUs
  • High-performance processors
  • Database caches
  • Web browsers
  • Operating system page caches

FIFO

  • Embedded systems
  • Small processors
  • Low-cost microcontrollers

Random

  • Very small caches
  • Simple hardware designs
  • Experimental cache architectures

Choosing the Right Policy

RequirementBest Policy
Highest performanceLRU
Lowest hardware costRandom
Simple implementationFIFO
Balanced solutionFIFO
Modern processor designLRU

Advantages of Good Replacement Policies

  • Increase cache hit rate.
  • Reduce average memory access time.
  • Improve CPU utilization.
  • Enhance application performance.
  • Reduce memory bandwidth usage.
  • Lower power consumption due to fewer memory accesses.

Limitations

  • LRU requires complex tracking hardware.
  • FIFO can evict useful data.
  • Random replacement is unpredictable.
  • No single policy is optimal for every workload.

Key Points to Remember

  • A replacement policy is needed only when the target cache set is full.
  • LRU replaces the least recently accessed block.
  • FIFO replaces the oldest inserted block.
  • Random replacement evicts a randomly selected block.
  • LRU generally provides the lowest cache miss rate because it exploits temporal locality.
  • FIFO is simple but ignores access patterns.
  • Random is the easiest to implement but often has the poorest performance.
  • The choice of replacement policy affects cache efficiency, hardware complexity, and overall system performance.

Conclusion

Cache replacement policies play a crucial role in determining the efficiency of modern cache memories. When cache space is limited, selecting the right block for eviction can significantly improve the cache hit rate and reduce memory access time. Among the common strategies, LRU generally offers the best performance by exploiting temporal locality, FIFO provides a simple and cost-effective solution, and Random Replacement minimizes hardware complexity at the expense of predictable performance. Understanding these policies is essential for students preparing for Computer Architecture, Operating Systems, GATE, ESE, and VLSI/ASIC interviews, as they form the foundation of efficient cache management in modern processors.

Comments

Popular posts from this blog

Module 1 — SystemVerilog Basics

VLSI Verification  •  SystemVerilog Series Module 1 — SystemVerilog Basics A complete, example-driven walkthrough of SystemVerilog fundamentals: data types, variables vs nets, arrays of every flavor, strings, enums, structs, unions, and typedef — the building blocks every verification engineer needs before UVM. 🧩 Beginner → Intermediate ⏱ ~25 min read 💻 Code Examples Included 📑 Table of Contents Introduction to SystemVerilog Verilog vs SystemVerilog Data Types: 2-State vs 4-State Logic Variables and Nets Arrays: Packed vs Unpacked Dynamic Arrays Queues Associative Arrays Strings Enumerations Structures Unions Typedef 1 Introduction to SystemVerilog SystemVerilog (IEEE 1800) is a unified hardware description and verification language (HDVL). It extends Verilog (IEEE 1364) with powerful constructs for design (interfaces, always_comb/always_ff, enhanced d...

GPU Memory System & Interconnect: How Data Travels Inside a Modern GPU

GPU Memory System & Interconnect: How Data Travels Inside a Modern GPU Modern GPUs deliver incredible computing power by processing thousands of operations simultaneously. While compute cores often receive the spotlight, the real performance of a GPU depends heavily on how efficiently data moves between memory and compute units. A GPU memory system is designed to provide extremely high bandwidth while keeping latency as low as possible. This is achieved through a collection of specialized hardware components working together, including the Memory Controller, HBM/GDDR memory, Crossbar, Network-on-Chip (NoC), DMA Engine, PCIe Interface, and NVLink. In this article, we'll explore each component in detail and understand how they collectively enable high-performance parallel computing. Why Does GPU Memory Matter? Every GPU application—from gaming and graphics rendering to AI model training and scientific simulations—requires continuous movement of enormous amounts of data. For examp...

Clock Domain Crossing (CDC): A Complete Beginner's Guide to Metastability, Synchronizers & Safe Data Transfer

Clock Domain Crossing (CDC): A Complete Beginner's Guide to Metastability, Synchronizers & Safe Data Transfer Modern System-on-Chip (SoC) designs rarely operate with a single clock. Instead, different modules such as CPUs, GPUs, memory controllers, communication interfaces, and peripherals often run at different clock frequencies or even use completely independent clock sources . When data moves from one clock domain to another, timing uncertainty can cause serious problems such as metastability , data corruption , and unpredictable system behaviour . This challenge is known as Clock Domain Crossing (CDC) . CDC is one of the most important topics in ASIC Design , RTL Design , ASIC Verification , FPGA Design , and SoC Architecture . Every modern chip—from smartphones to automotive processors—uses CDC techniques to ensure reliable communication between multiple clock domains. In this article, we'll explore CDC fundamentals, metastability, synchronization techniques, asynchro...

AXI Verification Interview Questions and Real-World Debugging

AMBA Protocol Series · Part 10 of 10 AXI Verification Interview Questions and Real-World Debugging Common protocol violations, how to read them off a waveform, and a curated set of interview questions with concise, correct answers — the capstone of the core 10-day series. AMBA Protocol Series: From APB & AHB to AXI — A Complete Guide for VLSI Engineers This wraps up the core 10-day series. Everything here draws directly on Days 1–9 — if any answer below feels unfamiliar, that's a good signal for which earlier post to revisit. (If you want to go further, see the 20-day extended list at the end of this post.) In This Article Common Protocol Violations Debugging From a Waveform Interview Questions and Answers Series Recap Extending the Series 1. Common Protocol Violations VALID deasserted before handshake — a source drops VALID before READY ever went high (violates the Day 8 stabi...

Cache Basics and Cache Mapping Techniques

  Cache Basics and Cache Mapping Techniques  Modern processors execute billions of instructions every second. However, processor speed has increased much faster than main memory (RAM) speed. This difference, known as the memory wall , creates a performance bottleneck because the CPU often has to wait for data from slower memory. To solve this problem, computer systems use cache memory —a small, high-speed memory located between the CPU and the main memory. In this article, we will understand the fundamentals of cache memory, the principle of locality, cache organization, and the three major cache mapping techniques. What is Cache Memory? Cache memory is a small, high-speed memory that stores copies of frequently accessed data from the main memory. Since accessing cache is much faster than accessing RAM, the CPU first checks whether the required data is available in the cache. If the data is found in the cache, it is called a cache hit . Otherwise, the CPU fetches the dat...

Timing Basics in Static Timing Analysis (STA): Delay Models, Sequential Timing, and Wire Delays

Timing Basics in Static Timing Analysis (STA) Static Timing Analysis (STA) is one of the most important verification techniques used in modern VLSI design. Before a chip is manufactured, engineers must verify that every signal reaches its destination within the required clock period. Even if a design passes functional simulation, it may still fail after fabrication because of timing violations. Unlike simulation, Static Timing Analysis mathematically analyzes every timing path without applying input test vectors. This makes STA significantly faster and capable of analyzing millions of timing paths efficiently. Table of Contents What is Static Timing Analysis? Why STA is Required Propagation Delay Contamination Delay Cell Delay Models Combinational Gate Delay Sequential Timing Setup Time Hold Time Wire Delay RC Delay Model PVT Corners Worked Examples Interview Questions Key Takeaways What is Static Timing Analysis? Static Ti...

Computer Architecture Interview Question Part 1

Skip to content Computer Architecture Interview Series Part 1 · CPU Basics · RISC vs CISC · ISA 50 Most Asked Computer Architecture Interview Questions (Part 1) The foundational round every VLSI, ASIC, and CPU design interview opens with: instruction set architecture, RISC vs CISC trade-offs, Von Neumann vs Harvard design, registers, endianness, and the fetch-decode-execute cycle — explained the way interviewers actually expect you to answer.  40 Questions (Q1–Q40) ⌛ 22 min read  VLSI & Computer Architecture Interviews On this page Foundations of Computer Architecture RISC vs CISC — Core Differences Von Neumann, Harvard & the Semantic Gap Architecture Styles, Endianness & Registers ILP, VLIW, Superscalar & Amdahl's Law Register Files, Microcontrollers & the Fetch Cycle Tip...