You are on page 1of 21

Memory Management

 Memory management influences the performance of an OS


 Memory management deals with strategies for managing the

memory so as to get an optimal performance from the Os


 For a computer ,the memory manager addresses the following

questions :
1. When should a program be brought into main memory ?

2. Where does a program sit in the main memory ?

3. What parameters should be considered while placing a program


in a particular location in main memory?
4. What should be done if the main memory is completely
occupied?

12/20/21 1
The function of Memory allocation and management are :
 Allows as many user jobs as possible to be present in

memory
 Prevents the Unauthorized changes to a user jobs memory

region
 Implements allocation and memory addressing as efficiently

as possible

12/20/21 2
Memory Management Techniques
1. Single Contiguous Allocation
2. Fixed partition Memory Allocation
3. Variable partition Memory Allocation
4. Re-locatable partition Allocation
5. Simple paged Allocation
6. Demand paging
7. Simple Segmentation

12/20/21 3
Single Contiguous Allocation

12/20/21 4
12/20/21 5
12/20/21 6
12/20/21 7
Advantages:
 Supports Multiprogramming
 Prevents internal and external fragmentation

Disadvantage:
Re-locating currently executing jobs is an overhead

12/20/21 8
Simple paged allocation
 Another technique to overcome external fragmentation is called
simple paging
 Memory is divided into bytes or words
 Each location in memory has an address and the set of address
available for a program is called its address space

12/20/21 9
 The job’s address space is divided into number of fixed
size memory blocks of the same size is called pages

 The main memory address space is also divided into


blocks or frames of the same size (4k)

 The loading of the job into memory involves transferring


these pages into some memory Frames

12/20/21 10
12/20/21 11
12/20/21 12
Introduction to virtual memory
 Virtual memory is an imaginary memory area that is supported by
some operating systems

 The ability of the OS to allow only part of the job to reside in the
memory during the execution ensures that the size of physical
memory does not impose any restrictions on the size of the job

 This gives every job in memory a feel that they have infinite
memory available for them ,though the fact is that the size of the
secondary memory limits the size of a job

 The actual physical memory onto which the job gets loaded is
called the real memory

12/20/21 13
Example:
 whenever a person goes for a buffet dinner, he/she feels that

there is an infinite amount of food that he/she could consume

 The size of the plate does not impose a restriction on the total
amount of food that he/she could consume

 As and when required the person loads the plate with the
desired amount of food and consumes it

 In reality the total amount of food available in the buffet table


would limit the total amount of food the person can consume

12/20/21 14
Demand paging
 It is a memory management technique
 The pages of a job loaded into memory only

on demand.
 The process of moving pages in and out of

physical memory is called swapping.


 Status field  initial value -0
 Modified field  value is -1
 Ex: word document

12/20/21 15
Page Fault & Replacement
 Demand paging technique could lead to a
scenario where in a job might try to access a
particular page which is not available in main
memory. This would lead to a fault called
page fault.
 The process of removing some pages from

physical memory to accommodate new pages


is called page replacement.

12/20/21 16
Page Replacement Algorithms for
Demand Paging
 FIFO
 LRU – Least Recently Used
 LFU – Least Frequently Used

12/20/21 17
FIFO
 In this algorithm the page which is in memory
for the longest time would be swapped out of
physical memory.
 Ex: 3134241231242313
 Pf-10
 Ex: 1303563
 Ex: 476176127271

12/20/21 18
Advantages & Disadvantages
 The main advantage of the FIFO page replacement algorithm
is its simplicity. It is easy to understand and implement.
 When the number of incoming pages is large, it might not
provide excellent performance.
 When we increase the number of frames or capacity to store
pages in the queue, it should give us less number of page
faults. Sometimes FIFO may behave abnormally, and it may
increase the number of page faults. This behavior of FIFO is
called Belady’s anomaly.
 In FIFO, the system should keep track of all the
frames. Sometimes it results in slow process execution.

12/20/21 19
LRU
 The Least Recently Used (LRU) page
replacement policy replaces the page that has
not been used for the longest period of time. 
 Ex: 3134241231242313
 EX: 70120304230321201701
 Ex: 4761761272

12/20/21 20
LFU
 3134241231242313
 EX: 70120304230321201701
 Ex: 4761761272

12/20/21 21

You might also like