BSGMM 4a Os A3 F22 017

You might also like

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

Superior University Lahore

(Computer Science Department)

Operating Systems
Assignment 3

Name: ABDUL MOEID


Roll#:bsgmm-f22-017

Submitted to : SIR AMEER HAMZA


Dated: 5th April 2023

1|Page
i.Explain demand paging and demand segment. And also explain
associate mapping and page fault?
In Demand Paging, a page is loaded from the secondary memory into
the primary memory, only when it is needed. On the other hand,
Segmentation follows a strategy whereby the entire memory space is
divided into discrete segments and each segment is allocated to a
process.
Associative mapping :
A technique of cache mapping that allows mapping of the main memory
block to a freely available cache line.
Here the mapping of the main memory block can be done with any of
the cache block. The memory address has only 2 fields here: word & tag.
Page Fault :
It mainly occurs when any program tries to access the data or the code
that is in the address space of the program, but that data is not currently
located in the RAM of the system.

ii.Explain page replacement algorithms and also describe


different types. And also define global vs local replacement?
In an operating system that uses paging for memory management, a
page replacement algorithm is needed to decide which page needs to be
replaced when a new page comes in.
Types:
1. First In First Out (FIFO):
This is the simplest page replacement algorithm. In this algorithm, the
operating system keeps track of all pages in the memory in a queue, the
oldest page is in the front of the queue. When a page needs to be
replaced page in the front of the queue is selected for removal.
2. Optimal Page replacement:
In this algorithm, pages are replaced which would not be used for the
longest duration of time in the future.

2|Page
3. Least Recently Used:
In this algorithm, page will be replaced which is least recently used.
4. Most Recently Used (MRU): In this algorithm, page will be
replaced which has been used recently. Belady’s anomaly can occur in
this algorithm.
(Bélády’s anomaly is the name given to the phenomenon where
increasing the number of page frames results in an increase in the
number of page faults for a given memory access pattern.)
Local page replacement algorithm selects for replacement some page
that belongs to that process (or a group of processes sharing memory
partition), whereas global replacement algorithm is free to select any
page in memory.

iii.Solve these Reference string: FIFO


7,0,1,2,0,3,0,4,2,3,0,3,0,3,1,7,0,1 using 4 frames
(4 pages can be in memory at a time per process).
F indicates page fault & H indicates page hit.

7 0 1 2 0 3 0 4 2 3 0 3 0 3 1 7 0 1
7 7 7 7 7 3 3 3 3 3 3 3 3 3 3 7 7 7
0 0 0 0 0 0 4 4 4 4 4 4 4 4 4 4 4
1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0
2 2 2 2 2 2 2 2 2 2 2 1 1 1 1
F F F F H F H F H H H H H H F F H H
Page faults = 9
Page hits = 9

3|Page
iv.Solve these Reference string: LRU
7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1 using 5 frames

7 0 1 3 2 0 0 4 2 3 0 3 0 3 2 1 2 0 1 7 0 1
7 7 7 7 7 7 7 4 4 4 4 4 4 4 4 4 4 4 4 7 7 7
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
F F F F H F H F H H H H H H H H H H H F H H
Page faults= 7
Page hits = 15

v.Solve these Reference string: Optimal method


7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1,4,3,6,2,5 using 3 frame

7 0 1 2 0 3 0 4 2 3 0 3 0 3 2 1 2 0
7 7 7 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
0 0 0 0 0 0 4 4 4 0 0 0 0 0 0 0 0
1 1 1 3 3 3 3 3 3 3 3 3 3 1 1 1
F F F F H F H F H H F H H H H F H H

1 7 0 1 4 3 6 2 5
2 7 7 7 7 7 6 6 6
0 0 0 0 4 4 4 2 2
1 1 1 1 1 3 3 3 5
H F H H F F F F F
Page faults= 14
Page hits = 13

4|Page
5|Page

You might also like