Professional Documents
Culture Documents
Unit4 DrCSYadav
Unit4 DrCSYadav
Unit4 DrCSYadav
Greater Noida
KCS 401
Operating System
Unit 4
Dr
Memory Management System
Dr. C S Yadav
B. Tech 4th Semester Prof. & Head, CSE
•Memory Allocation
•Contiguous
•Fixed Partition
•Variable partition
•Non Contiguous
•Paging
•Segmentation
•Segmentation with paging
•Virtual Memory
•Demand Paging
•Global and local page replacement
•Page replacement algorithms
•FIFO
•LRU
•OPTIMAL
•Thrashing
• To understand the virtual memory concepts and evaluate the performance of virtual
memory with the help of effective memory access time.
• To understand the demand paging concept and calculate number of page fault using
page replacement algorithms such as FIFO, LRU, and Optimal Page Replacement
algorithm.
OPERATING SYSTEM(KCS-401)
CODE PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
KCS401.4 3 2 2 3 1 2 2 - 2 - 2 3
KCS401.4 2 2 1 2
Course Topics
Outcome Module 1 Module 2 Module 3 Module 4
KCS401.4 3 2 2 2 2 1
Fixed Partition
Contiguous
Dynamic Partition
Memory
Allocation Paging
Non
Segmentation
Contiguous
Segmentation
with paging
Dr C S Yadav Unit 4 KCS 401 OS 9
18 April 2022
Memory Allocation(CO4)
Topic objective: To understand the contiguous memory allocation and its type.
In this allocation, a memory resident program occupies a single continuous block of
physical memory.
The physical memory is partitioned into block of different sizes for accommodating
the programs. This partitioning is of two types:
1. Fixed partitioning
2. Variable partitioning
Topic objective: Analyze the fixed partition scheme from implementation point of
view.
• The implementation is very easy.
• The processing overheads are low
Topic objective: Analyze the fixed partition from the point of memory
utilization
• The degree of multiprogramming is fixed, since the number of
partition is fixed.
• Suffers from internal fragmentation
External fragmentation refers to the large number of small chunks of free memory
that may be scattered all over the physical memory and individually each of the
chunks may not be big enough to accommodate even the small program.
However, if joined together, the total free space, thus resulted, may be big enough
to accommodate some more programs that may be waiting for loading.
Compaction is a technique, by which the resident programs are re-located in such a
way that the small chunks of free are made contiguous to each other and clubbed
together into a single free partition, that may be big enough to accommodate Some
more programs. But the compaction has very high processing overheads.
• Worst Fit
Topic objective: To analyze the merits and demerits of Best fit allocation strategy.
It refers to the allocation of the smallest available free partition that may be big
enough to accommodate the program being loaded. This algorithms also works for
both fixed partition and variable partition.
Advantage: The memory loss, on account of fragmentation will be lesser than in the
case of first fit.
Disadvantage: Search time will be larger, as compared to first fit.
Topic objective: To analyze the merits and demerits of worst fit allocation strategy.
It refers to the allocation of the largest partition out of the ones which are
available, which may be bigger enough to accommodate the program.
The sprit behind this scheme is that the balance space, left in the allocated
partition, after loading program, may be big enough to load another small program;
and in that eventually, memory loss due to fragmentation may be lower than first
fit. Search time in this scheme would be of the same order as in the case of Best Fit.
Disadvantage: Search time is larger than first fit. It is same as in the case of Best Fit.
By mistake if used along with fixed partition, the results will be suicidal.
Topic objective: To implement security for protecting the data from address space.
Topic Objective: To understand the paging mechanism and how logical address is
translated into physical address in this mechanism
It permits physical address space of a process to be non-contiguous.
The logical address space of a process is divided into blocks of fixed size called
Pages.
Also, the physical memory is divided into blocks of fixed sizes called Frames.
For a ‘m’ bit processor, the logical address will be m bits long.
Let the page size be 2n bytes.
Then lower order n bits of a logical address (L) will represent page
offset(d) and the higher order m-n bits will represent the page number
(p).
Then page number p=L/2n
And page offset d=L%2n
Let f be the frame number that holds the page referenced by logical address (L).
Then f can be obtained by indexing into page table, by using page number p as
index
f=page-table[p].
Corresponding physical address (P)=f*2n + d
This physical address is fed to MMU to access the memory location, referenced by
logical address L.
Due to higher cost, it may not be cost effective to have entire page table in TLB, but
a subset of page table, that may be currently active, can be moved to TLB.
Each entry of TLB would contain Page no. of a page and the Frame no. where the
page is stored in RAM
If match not found for the page no., it indicates TLB miss. Then, the frame no. is
accessed from the page table. Also, the page table entry is moved to TLB, so that
for further references to that page, its frame no. can be accessed from TLB itself.
If TLB is full, then some replacement algorithm can be used to replace one of the
existing entries in the TLB.
Topic objective: To compute the effective memory access time of cache memory.
=0.9*(100+20) + (1-0.9)*(2*100+20)
=0.9*120+0.1*220=108+22=130 ns
Topic Objective: To explain the translation of logical address into physical address
using IPT
The size of IPT is related to the size of the physical memory, not the size of logical
address space. Since, IPT is not process specific and it does not need switching
during context switching of the processes. IPT contains process id along with page
no. for each frame in the physical memory. IPT is system-wise not per process.
Each entry in the TLB would comprise Page number, process-id and its
corresponding frame number. The associative memory would permit
matching of a process-id and page number pair simultaneously with all
the entries in TLB. The desired frame number can then be obtained
from the matching entry.
Topic Objective: To explain the mechanism of Hashed Page Table with the help of
following diagram
Topic objective: Translation of logical address into physical address using Hashed
Page Table.
i=p%M;
The index value i is used to index into the page table. Each entry in the page table is
a pointer to a linked list.
Topic Objective: To explain the mechanism of multi-level paging with the help of
following diagram
Topic Objective: To explain the steps for translating logical address into physical
address in multi-level paging scheme.
The page table is divided into multiple levels. For example, in a two level page
table, a logical address would comprise of the following fields:
(a)Page number p1, for indexing into outer page table.
(b)Page number p2, for indexing into inner page table.
(c)Offset or displacement d that is used to index into the selected frame, to obtain
the desired operand
In this, the logical space is divided into a number of segments of varying sizes
and each segment is divided into a number of pages, each of a fixed size.
https://docs.google.com/forms/d/e/1FAIpQLSdZ26DWe4bdxawhdBJPrLqSp7EKpV7s0uXjj2yM8SiM8_Bd4g/viewf
orm?usp=sf_link
When a process is swapped-in, the pager loads a set of its pages, which
may be predicted to be initially needed by the process into the physical
memory.
When a process is swapped-in, this bit is set to invalid for all the entries in
the page table. When page is loaded into RAM, its frame number is entered
and page validity bit is set to valid.
Thus if bit is valid, it indicates that the page is legally from the logical address
space of the process and is currently in the RAM.
If it is set to invalid, it indicates that either the page does not belong to the
logical address space of the process or it is still not loaded into RAM.
Pure Demand Paging: All the pages are placed in secondary storage and on
demand basis, it is loaded into main memory at execution or run time. At the
outset, main memory is empty.
Topic objective: To understand the concept of modified and dirty bit in the implementation of Virtual
Memory Concepts.
➢It is used to reduce one disk access.
➢If write operation is performed on the page after loading, then page is modified
or dirty.
➢If page is dirty, first write the dirty page into disk and bring the requested page
into main memory.
➢If the page is clean, no write operation is performed on the page simply replace
the page with requested page.
Topic Objective: To understand and Page Replacement Concepts and its types.
Whenever, a process experiences a page fault, if no free frame are available, then
the OS gets a currently occupied frame released and allocates the released frame
to the page faulting process, for accommodating the new page. If the victim page
belongs to the page faulting process itself, it is called local page replacement; else it
is called global page replacement. Global page replacement does not focus on the
performance of individual processes. It rather focuses on the system performance.
Page number = Quotient (Logical Address/Page Size), if logical address =0745 and page size
=100 bytes, then page no=0745/100=7
Topic Objective: To explain the merit and demerit of FIFO Page Replacement Algorithm.
Limitation: This algorithm does not take into account the current usages of pages and may
often eject some pages that may be currently active. Such pages would need to be moved
in frames again, in near future.
Also, if the system has global page replacement, then the program having largest number
of allocated pages would have higher page fault rate, since the probability of oldest page,
belonging to this program would be very high. This phenomena is called Belady’s Anomaly
and it defies intuition.
7 7 7 2 2 2 2 4 4 4 0 0 0 0 0 0 0 7 7 7
No. of Frames
0 0 0 0 3 3 3 2 2 2 2 2 1 1 1 1 1 0 0
1 1 1 1 0 0 0 3 3 3 3 3 2 2 2 2 2 1
Status F F F F H F F F F F F H H F F H H F F F
Topic Objective: To explain the advantages and disadvantages of LRU Page Replacement Algorithm.
Advantage: While selecting a resident page for replacement, it takes into consideration the current usage of a
page. This algorithm is free from Belady’s Anomaly.
Limitations: The algorithm has a lot of processing overheads, which are needed to keep track of least recently
used
No. of Frames 3 7 7 7 2 2 2 2 4 4 4 0 0 0 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 3 3 3 3 3 3 0 0 0 0 0
1 1 1 3 3 3 2 2 2 2 2 2 2 2 2 7 7 7
Status F F F F H F H F F F F H H F H F H F H H
Topic Objective: To compare Optimal Page Replacement Algorithm with FIFO and LRU.
Optimal algorithm appears to be best in term of number of page faults, but it is not feasible to implement this
algorithm since the algorithm requires the knowledge of future. Out of FIFO and LRU, the LRU is better, since it
takes into consideration the current usage of a page whenever a resident page is considered for replacement.
The page, which has been least recently used is chosen for replacement.
No. of Frames 3 7 7 7 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 7 7
0 0 0 0 0 0 4 4 4 0 0 0 0 0 0 0 0 0 0
1 1 1 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1
Status F F F F H F H F H H F H H F H H H F H H
Topic objective: Removal of thrashing with the help of working set model.
Topic objective: To understand the locality of reference of a process and its type.
At any time, during its execution, a process will be accessing only a small subset of
logical address space. This subset of the logical address space is called its current
locality of references. The current locality keeps shifting. It also keeps varying in size.
Whenever, a page forming part of the current locality is not found in the memory, it
will cause a page fault. So when a process moves from one locality to another, it will
get the new pages into memory through page faulting.
Topic Objective: To remove the thrashing with the concept of Page Fault
Frequency.
At any time, during its execution, a process will be accessing only a small
subset of logical address space. This subset of the logical address space is
called its current locality of references. The current locality keeps shifting. It
also keeps varying in size. Whenever, a page forming part of the current
locality is not found in the memory, it will cause a page fault. So when a
process moves from one locality to another, it will get the new pages into
memory through page faulting.
• https://www.youtube.com/watch?v=LLhgnIYpQaI
• https://www.youtube.com/playlist?list=PLmXKhU9FNesSFvj6gASuWmQd23Ul5omtD
• https://www.youtube.com/watch?v=xAvC-MJ_Sz8
• https://nptel.ac.in/courses/106108101
• Name the common strategies to select a free hole from a set of available
holes.
• Explain Compaction.
• Name the various page replacement algorithms used for page replacement.