Unit 2 Chap - 3

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Chapter 3- Memory Management

Q.1 Explain Swapping with example.


Ans: Swapping-
1. Swapping is exchanging data between the hard disk and the RAM without splitting a process.
2. A process must be loaded into RAM in order to execute.
3. If there is not enough memory available to keep all running processes in RAM at the same time,
then some processes which are not currently using the CPU are stored on Hard disk.

Example-

a. Only A in memory
b. Process B is swapped in from hard disk to memory
c. Process C is swapped in from hard disk to memory.
d. A goes in waiting state. So swapped out to hard disk.
e. D swapped in.
f. B goes in waiting state. So swapped out to hard disk.
g. A has come out of waiting state and ready to execute again. So swapped in again to RAM

Characteristics-
1. Variable partitions
2. Number, location and size of partitions vary dynamically.
Memory Compaction-
Swapping creates multiple holes in memory. Combine all holes together to form big one by moving all
the processes downwards.

Q. 2 Explain the concept of base and limit register in memory management.


1. Memory abstraction- User doesn’t have to deal with actual physical memory addresses.
Abstraction layer hides memory hierarchy and provides users with illusion of easily accessible memory
known as Virtual Memory.
2. Address space- Each process has its own set of addresses that always start from zero. known as
address space.The addresses are different for each program. Address space is a logical address/Virtual
address of a process.
3. Logical address-
Location which is seen by process. Starts from 0 for each process.
4. Physical address- Actual RAM location seen by OS.
5. Base and Limit Registers- In order to execute the processes, they must be brought into physical
memory from virtual memory. MMU uses base and limit registers to convert logical address into
actual physical address.
Base Register- Contains beginning RAM address of a process.
Limit Register- Contains length of a program.
The mapping is done as shown in diagram below.

Q. 3 What is paging in memory management? Explain with diagram.


1. Each process has its own address space called as Logical/ virtual address space.
2. In other words, processes are stored in Virtual address space.
3. Virtual Address space is divided into fixed size small units called pages.
4. Physical address space(RAM) is divided into small fix sized units call frames.
5. Size of Page= Size of frame
i.e. each frame can accommodate 1 page
6. Page table- In order run execute pages, they must be brought into physical memory. Page table
Maps pages from virtual memory into frames in RAM.
It is a table maintained by OS to indicate which page is mapped into which frame.

Page Fault-
No space in physical memory for new page. In order to add new page, one page must be removed
from RAM. Which page must be removed to make room for new page is decided by Page replacement
Algorithms.
Q. 4 Explain optimal page replacement algorithm with example.
1. Replace the page that won’t be needed for longest time in the future.
2. Knowledge of future is required i.e. whole sequence has to be known in advance.
3. Not realizable in practice as algorithm the page on the basis of future use.
4. Has lowest page fault rates.
5. Example- Consider a page sequence as given below-

6. Pages 2,3,4 are initially brought into main memory causing page fault. Next 2 page is to be added,
which is already there in main memory, so page hit.
7. In order to add page 1, replace the page 2 as it is not needed for long time in future.
8. In above case, total page faults= 6, total hits=4

Q. 5 Explain FIFO page replacement algorithm with example.


1. The simplest page replacement algorithm and works on basis of first in first out.
2. It removes the pages out in the order in which they are brought in.
3. This algorithm chooses oldest page for the replacement.
4. A queue is maintained in order to hold pages.
5. Example- Consider sequence given below-

6. Pages 4,7,3 are initially brought into main memory causing page fault.
7. In order to add page0, replace the page 4 as it has come first into the RAM.
8. Next page 7 will be replaced as it is the oldest page in RAM.
9. Total page Faults=11 , total page hits= 1
Q.6 Write a short note on second chance page replacement algorithm
1. It is modification in FIFO.
2. This algorithm uses additional bit called as Reference bit (R). If page in main memory is referenced
again, reference bit is incremented by 1.
3. Before replacing the page, reference bit is checked,
 If R=0 ---page is unused and old, replace it
 If R=1 ---do not replace the page, a second chance is given to that page
4. After page gets second chance, its reference bit is made zero.
5. Example- Consider the page sequence given below
5. Initially bring page 2 in main memory causing page fault. R=0 for page 2 as it is referenced single
time.
6. Then bring page 3 in main memory causing page fault. R=0 as it is referenced single time.
7. Now page 2 is already in RAM and is referenced again, so make R=1 for page 2.
8. Bring in page 1 with R=0.
9. In order to add 5, page 2 is supposed to be replaced as per FIFO policy. But page 2 has second
chance (R=0), so it cannot be replaced. So page 2 will remain in RAM with R=0. Then page 3 will be
removed as per FIFO policy.
10. Total page faults=7 , total page hits= 5
Q.7 Write a short note on LRU page replacement algorithm.
1. Removes the page that has not been used for longest time.
2. In order to add new page, this algorithm replaces the page that was used far back in past.
3. This algorithm looks backward in time, while optimal algorithm looks forward in time.
4. Example- Consider following sequence-

5. Pages 4,7,3 are initially brought into 3 frames of main memory causing page fault.
6. Next, page 2 is already in memory so it will lead to page hit.
7. In order to add page 1, algorithm checks 3 distinct pages in the past and removes the page that is
far away (i.e. 3rd page). Out of pages 2,4,3 , page 3 is far away in past. So algorithm will remove page 3
and will add page 1 at the place of page 3.
8. Total page faults-8, total page hits- 2
Q.8 Explain clock page replacement algorithm with neat diagram.
1. Similar to second chance page replacement algorithm, only difference here is, frames are arranged
clockwise i.e. in circular manner as shown in diagram below.
2. The hand of clock points to the oldest page.
3. This algorithm uses additional bit called as Reference bit (R). If page in main memory is referenced
again, reference bit is incremented by 1.
4. When page fault occurs, page pointed by hand is inspected.
5. Before replacing the page, reference bit is checked,
 If R=0 ---page is unused and old, replace it. Then advance the hand by 1 position.
 If R=1 ---do not replace the page, a second chance is given to that page. After page gets
second chance, its reference bit is made zero and then advance the hand by 1 position.
Q.9 Explain NRU page replacement algorithm.
1. Each page has reference bit R and modified bit M.
2. R is set when page is referenced(read/written)
3. M is set when page is modified (i.e. written).
4. Pages are divided into 4 categories-
 Class 0- not referenced, not modified
 Class 1- not referenced, modified
 Class 2- referenced, not modified
 Class 3- referenced, modified

5. Removes the page that has not been used recently. Class 0 is of lowest priority while class 3 is of
highest priority.
6. In case of page fault, first replace pages of class 0, then class 1 or class 2.
7. R=1 and M=1 indicates recently used pages.

Q.10 Explain Working set page replacement algorithm.


1. Working set is the set of pages which is currently being used by a process.
2. On the occasion of a page fault, a page is located which is not in the working set and then it is
removed.
3. When there is a page fault entire page table is scanned to find a page for removal.
4. R is the referenced bit and t is the number of clock ticks.
 if R = 1, shows that the page in use during page fault and will not be removed. A second
chance is given to a page.
 If R = 0 , Age is calculated by: (Current virtual time – Time of last use)
If Age > t, then the page is not in working set and is removed.
If Age ≤ t, then the page is in the working set and is not removed.

Q.11 Explain Working set clock page replacement algorithm.


1. Working set clock PRA. Pages are put in a circular list just like in a clock.
Working set is the set of pages which is currently being used by a process.
2. On the occasion of a page fault, a page is located which is not in the working set and then it is
removed.
3. For an entry if R = 1, page is not removed. R bit is set to 0 and clock hand is moved to next page.
4. If R = 0 and Age is calculated by: (Current virtual time – Time of last use)
If Age > t, then the page is not in working set and is replaced by a new page.
If Age ≤ t, then the page is in the working set and is not removed. Clock hand is moved to next page.

Q.12 Explain design issues with paging.


1. Local Vs Global Allocation Policies-
i. Local-
Considers the pages allocated for that particular process.
If page fault occurs, replace the page of the same process by using PRA.
ii. Global-
Consider all pages in memory.
If page fault occurs, replace any page from main memory using PRA.
2. Load Control-
If virtual memory is too much larger than main memory available, thrashing may occur.
Thrashing- State in which CPU performs ‘productive’ work less and ‘swapping’ more.
Solution :
Reduce number of processes competing for memory
reconsider degree of multiprogramming
3. Page Size-
Advantages of small page size-
better fit for various data structures, code sections
less unused space in memory, less internal fragmentation
Disadvantages of small page size-
programs need many pages, larger page tables.
4. Separate Data and instruction space and shared pages
Separate space for program and data. By separate Instruction(program) and data pages, sharing can
be done.
Advantage- Several users can run same program at the time. But data of each process is different.
Better to share the program pages, rather than creating multiple copies of the same in main memory.
Q.13 Explain segmentation concept with neat diagram.
1. Segmentation is a Memory management scheme that supports user’s view of program.
2. In order to bring process from Virtual memory to RAM, it is spitted segment wise.
2. A program is divided into different logical units, each unit is known as segment. A program is a
collection of Segments.
3. A segment is a logical unit such as-
 Main function
 User defined functions
 Symbol table- variables, arrays, pointers, other data structures
 Stack
 Subroutines
4. Virtual memory is divided into variable sized partitions, each partition serve a specific function
known as segment.
5. Segment Table- Entity which maps segments from Virtual memory to physical memory.
6. Two registers are used for mapping-
 Base- starting physical address of a segment in main memory
 Limit- Length of a segment

You might also like