OS 4th
OS 4th
Aditi Samadhiya
Assistant Professor, MITS Gwalior
PhD Scholar, ABV IIITM Gwalior
Memory Management
• Module of OS which manages the memory.
• Memory is the important part of the computer that is used to store the
data. Its management is critical to the computer system because the
amount of main memory available in a computer system is very
limited. At any time, many processes are competing for it.
• Moreover, to increase performance, several processes are executed
simultaneously. For this, we must keep several processes in the main
memory, so it is even more important to manage them effectively.
Function of Memory Management
1. Memory allocation:-
• When a process comes from new state to ready state or from hard
disk to main memory. Then the allocation of process in main memory
is decided by memory management.
2. Memory deallocation:-
• When a process completes its execution then the space it occupied
should be deallocated by memory deallocation.
3. Memory Protection:-
• Protection is needed so that process can access its own area not
other process area.
Goals of Memory Management
• Minimum wastage and Maximum utilization of space.
• Ability to run larger programs with limited space.
Memory Management Techniques
Contiguous Non-Contiguous
Entire process should be stored in Process can not stored on
Consecutive location. Consecutive location.
1. Fixed Partition 1. Paging
2. Variable Partition 2. Segmentation
Contiguous Memory Management
• Entire process should be stored on consecutive location.
• In a Contiguous memory management scheme, each program occupies
a single contiguous block of storage locations, i.e., a set of memory
locations with consecutive addresses.
Fixed Partitioning
• The main memory is divided into fixed no. of partition and each
partition can be used to accommodate maximum one process.
• The main memory is divided into several fixed-sized partitions in a
fixed partition memory management scheme or static partitioning.
• These partitions can be of the same size or different sizes. Each
partition can hold a single process.
• The number of partitions determines the degree of multiprogramming,
i.e., the maximum number of processes in memory. These partitions
are made at the time of system generation and remain fixed after that.
Fixed Partitioning: Allocate P1 to this
partition
OS
150KB
200KB
100KB
60KB
Partition allocation policy
• When a new process arrive, then that process should get space where
and in which partition is decided by the operating system and
memory management techniques.
1. First Fit
2. Best Fit
3. Worst Fit
4. Next Fit
Internal Fragmentation
• If extra space is allocated to a process more than required space.
Hence, wastage of that extra space is known as Internal
Fragmentation.
Fixed Partitioning
• Advantages of Fixed Partitioning memory management schemes:
• Simple to implement.
• Easy to manage and design.
• Disadvantages of Fixed Partitioning memory management
schemes:
• This scheme suffers from internal fragmentation.
• The number of partitions is specified at the time of system generation.
Variable Partition Contiguous memory
management technique
• Main memory is not divided into partition initially.
• When a new process arrives, a new partition is created of same size
and the process is allocated into that partition.
• Hence, no any internal fragmentation.
Variable Partition
OS OS OS OS
P1 P1 P1
P2 P2
P3
P3
We have-
Number of locations possible with 22 bits = 222 locations
It is given that the size of one location = 2 bytes
• If the referred page is not present in the main memory, then there will
be a miss and the concept is called Page miss or page fault.
• The CPU has to access the missed page from the secondary memory.
If the number of page fault is very high then the effective access time
of the system will become very high.
Page Replacement Policies
• In case of page fault, OS brings faulted page from secondary memory
to main memory by using page replacement algorithm (if needed)
and update page table.
Page Replacement Policies
1. First In First Out (FIFO)
2. Optimal Policy
3. Least Recently Used (LRU)
First In First Out (FIFO)
Disadvantages
• Poor performance
• Suffers from Belady’s Anomaly.
Optimal Policy
• Replace page which is not (never) going to be referred in near future.
• Assume:
1. No. of frames = 4 (all empty initially)
2. Page reference sequence = 1,2,3,4,1,2,5,1,2,3,4,5
3. Find out the number of page fault ?
Optimal Policy
Optimal Policy
Advantages
• Easy to implement
• Highly efficient
Disadvantages
• Requires future knowledge of the program
• Time-consuming
Least Recently Used (LRU)
• Replace that page which CPU has not used since longest time.
• Assume:
1. No. of frames = 3 (all empty initially)
2. Page reference sequence = 1,2,3,4,1,2,5,1,2,3,4,5
3. Find out the number of page fault ?
Least Recently Used (LRU)
Advantages
• Efficient for practical usage
• Doesn’t suffer from Belady’s Anomaly
Disadvantages
• Complex implementation
• Expensive
Question
• No. of frames = 5 (all empty initially)
• Page reference sequence = 3,8,2,3,9,1,6,3,8,9,3,6,2,1,3
• Find out the page faults using LRU policies ?