- Top Links
- PrepInsta Home
- OS Home
- Introduction
- CPU Scheduling
- What is Process?
- Process Lifecyle
- Process Control Block
- Process Scheduling
- Context Switching
- CPU Scheduling
- FCFS Scheduling
- SJF (non-preemptive)
- SJF (Preemptive - SRTF)
- Round Robin
- Priority Scheduling
- Convoy Effect
- Scheduler Vs Dispatcher
- Preemptive Vs non
- Preemptive scheduling
- Non preemptive scheduling
- Process Synchronization
- Deadlock
- Popular Algorithms
- Memory Management
- File System
- Others
- Youtube
- Whatsapp Group
- Telegram Group
- Contact us












LRU in JAVA language


Least Recently Used (LRU) Algorithm
In memory management, page replacement algorithms play a very vital part of keeping the main memory filled with fresh pages. One of the algorithms called Least Recently Used (LRU) page replacement algorithm works on the concept that it replaces those pages first which are the oldest and have been least referred.
LRU in Java Language
To implement this, a counter called an “age bit” is maintained, which keeps track of which page is to be referred and when it is to be referred. It ensures that the page which was least recently used is discarded to make space for the new page. When the page requested by the user is not present in the RAM, then a page fault occurs. When the page requested by the user is already present in the RAM, then page hit occurs. Let us understand LRU with an example.
Example
Reference String = 7 0 1 2 0 3 0 4 2 3
Number of iteration = 10
Page frame = 3
7 | 0 | 1 | 2 | 0 | 3 | 0 | 4 | 2 | 3 |
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
7 | 7 | 7 | 2 | 2 | 2 | 2 | 4 | 4 | 4 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 | |
1 | 1 | 1 | 3 | 3 | 3 | 2 | 2 | ||
F | F | F | F | F | F | F | F |
Number of page fault = 8
Number of page hit = 2
Read Also – LRU in python language
LRU Program in Java
Output
Login/Signup to comment