Os - Lecture - 07 - Memory MNGNT 2
Os - Lecture - 07 - Memory MNGNT 2
Ralph Tambala
MUST . CSIT
Lecture 7 1 / 19
Outline
1 Overview
4 Belady’s Anomaly
5 Additional Info
Lecture 7 2 / 19
Overview
Overview
Lecture 7 3 / 19
Virtual Memory Management
The code and data required to run programs should ideally be kept in
main memory, where it can be executed fast by the CPU. However,
while running large programs or multiple programs at once, the
system’s RAM may become full. In practice, entire program rarely
used. Some of the code rarely used include error handling code,
unusual routines, and large data structures.
Loading the program partially in memory can be beneficial in several
ways:
◦ Program no longer constrained by limits of physical memory.
◦ Each program takes less memory while running resulting to more
programs running at the same time resulting to increased CPU
utilization and throughput.
◦ Less I/O needed to load or swap programs into memory resulting to
each user program running faster.
Lecture 7 4 / 19
Virtual Memory Management
To get around this issue, some data stored in memory that isn’t being
actively used can be temporarily moved to virtual memory. Virtual
memory is a section of volatile memory created temporarily on the
secondary storage.
This frees up RAM space, which can then be used to store data that
the system will need to access soon. Virtual memory offers user an
illusion of having a very big main memory.
One of the most used technique in memory management is using
virtual memory with paging;
◦ virtual space of process divided into fixed-size pages
◦ virtual address composed of page number and page offset
◦ physical memory divided into fixed-size frames
◦ page in virtual space fits into frame in physical memory
Lecture 7 5 / 19
Virtual Memory Management
Lecture 7 6 / 19
Virtual Memory Management
Lecture 7 7 / 19
Virtual Memory Management
Lecture 7 10 / 19
Page Replacement Algorithm FIFO
FIFO
The oldest page in physical memory is the one selected for
replacement
Very simple to implement
◦ keep a list
◦ victims are chosen from the tail
◦ new pages in are placed at the head
Example: Assume a system has 4 frames and no pages loaded yet in
memory. (* = page fault)
FIFO
Issues
Lecture 7 12 / 19
Page Replacement Algorithm LRU
LRU
LRU’s basic idea is to replace the page in memory that has not been
accessed for the longest time
Example: Example: Assume a system has 4 frames and no pages
loaded yet in memory. (* = page fault)
Lecture 7 13 / 19
Page Replacement Algorithm LRU
LRU
Issues
Lecture 7 14 / 19
Page Replacement Algorithm OPT
OPT
OPT has the lowest page-fault rate of all algorithms. OPT is also
known as Belady’s MIN.
OPT replaces the page that will not be used for the longest period of
time.
Example: Assume a system has 4 frames and no pages loaded yet in
memory. (* = page fault)
OPT
Issues
Lecture 7 16 / 19
Belady’s Anomaly
Lecture 7 17 / 19
Belady’s Anomaly
Assuming a system that has no pages loaded in the memory and uses the
FIFO page replacement algorithm. Consider the following reference string:
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
1 If the system has 3 frames using FIFO page replacement algorithm,
how many page faults will it yield? What will be the fault rate?
2 If the system has 4 frames using FIFO page replacement algorithm,
how many page faults will it yield? What will be the fault rate?
OPT and LRU do not suffer Belady’s Anomaly because these algorithms
assign a priority to a page (for replacement) that is independent of the
number of page frames.
Lecture 7 18 / 19
Additional Info
Additional Tasks
Consider the reference string given on slide 18. Do (1) and (2) this
time using LRU. What do you observe?
Prescribed textbooks are more detailed... Read them.
Lecture 7 19 / 19