0% found this document useful (0 votes)
7 views5 pages

11396OS Expt No-09

The document is a lab manual for the Operating System course at Terna Engineering College, detailing Experiment No-09 focused on memory management and virtual memory concepts. It includes instructions for students to write C programs demonstrating demand paging and page replacement policies such as FIFO and LRU. Additionally, it outlines prerequisites, expected outcomes, and theoretical concepts related to demand paging and page fault handling.

Uploaded by

vcodes08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

11396OS Expt No-09

The document is a lab manual for the Operating System course at Terna Engineering College, detailing Experiment No-09 focused on memory management and virtual memory concepts. It includes instructions for students to write C programs demonstrating demand paging and page replacement policies such as FIFO and LRU. Additionally, it outlines prerequisites, expected outcomes, and theoretical concepts related to demand paging and page fault handling.

Uploaded by

vcodes08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Terna Engineering

College Computer
Engineering Department
Program: Sem IV

Course: Operating System Lab

Facult
y: LAB
Manual
PART A
(PART A : TO BE REFFERED BY
STUDENTS)

Experiment No-09

PART A
(PART A: TO BE REFFERED BY STUDENTS)

A.1 Memory Management: VirtualMemory


a. Write a program to demonstrate the concept of demand paging for simulation of Virtual
Memoryimplementation
b. Write a program in C to demonstrate the concept of page replacement policiesfor
handling page faults eg: FIFO, LRUetc.

A-2 Prerequisite
Knowledge about C/C++ programming language.
A.3 Outcome
A.4 Theory:

Demand Paging

 The basic idea behind demand paging is that when a process is swapped in,
its pages are not swapped in all at once. Rather they are swapped in only
when the process needs them. ( on demand. ) This is termed a lazy swapper,
although a pager is a more accurateterm.
Figure 9.4 - Transfer of a paged memory to contiguous disk space

9.2.1 BasicConcepts

 The basic idea behind paging is that when a process is swapped in, the pager
only loads into memory those pages that it expects the process to need ( right
away.)
 Pages that are not loaded into memory are marked as invalid in the page
table, using the invalid bit. ( The rest of the page table entry may either be
blank or contain information about where to find the swapped-out page on the
hard drive.)
 If the process only ever accesses pages that are loaded in memory ( memory
resident pages ), then the process runs exactly as if all the pages wereloaded
in tomemory.

Figure 9.5 - Page table when some pages are not in main memory.
 On the other hand, if a page is needed that was not originally loaded up,then
a page fault trap is generated, which must be handled in a series ofsteps:
1. The memory address requested is first checked, to make sure it wasa
valid memoryrequest.
2. If the reference was invalid, the process is terminated. Otherwise,the
page must be pagedin.
3. A free frame is located, possibly from a free-framelist.
4. A disk operation is scheduled to bring in the necessary page fromdisk.
( This will usually block the process on an I/O wait, allowing some
other process to use the CPU in the meantime.)
5. When the I/O operation is complete, the process's page table isupdated
with the new frame number, and the invalid bit is changed to indicate
that this is now a valid pagereference.
6. The instruction that caused the page fault must now be restarted from
the beginning, ( as soon as this process gets another turn on the CPU.)

Figure 9.6 - Steps in handling a page fault

 In an extreme case, NO pages are swapped in for a process until they are
requested by page faults. This is known as pure demandpaging.
 In theory each instruction could generate multiple page faults. In practicethis
is very rare, due to locality of reference, covered in section9.6.1.
 The hardware necessary to support virtual memory is the same as for paging
and swapping: A page table and secondarymemory.
 A crucial part of the process is that the instruction must be restarted from
scratch once the desired page has been made available in memory. Formost
simple instructions this is not a major difficulty. However there are some
architectures that allow a single instruction to modify a fairly large block of
data, ( which may span a page boundary ), and if some of the data gets
modified before the page fault occurs, this could cause problems. One
solution is to access both ends of the block before executing theinstruction,
guaranteeing that the necessary pages get paged in before the instruction
begins.

⮚ First In First Out:


This is the simplest page replacement algorithm. It associates with each page
the Time when that page was brought into memory. When a page must be
replaced, the oldest page is chosen. Notice that it is not strictly necessary to
record the time when a page is brought in. We can create a FIFO queue to
hold all pages in memory. We replace the page at the head of the queue.
When a page is brought into memory, we insert it at the tail of thequeue.
Example: page frames = 3
Ref. String:
7 0 1 2 0 3 0 4 2 3 0 3
2
7 7 7 2 2 2 4 4 4 0
Frame-1
0 0 0 3 3 3 2 2 2
Frame-2
1 1 1 0 0 0 3 3
Frame-3

Fig. No.1 FIFO

Initially all 3 frames are empty. The first 3 references (7,0,1) cause page
faults and are brought into these empty frames. The next ref.(2) replaces page 7,
because page 7 was brought in first. Since 0 is the next reference and 0 is already
in memory, we have no fault for this ref. The first ref to 3 results in replacement
of page 0, since it is now first in line. Because of this replacement, the next ref.
to 0, will fault. Page 1 is then replaced by page 0. This process continues as
shown in above figno.1.

⮚ Least Recently Used:


LRU associates with each page the Time of that page’s last use. When a page
must be replaced, the LRU chooses the page that has not been used for the
longest period of time. We can think of this strategy as the optimal page
replacement algorithm looking backward in time, rather than forward.

Example: page frames = 3


Ref. String:
7 0 1 2 0 3 0 4 2 3 0 3
2
7 7 7 2 2 4 4 4 0
Frame-1
0 0 0 0 0 0 3 3
Frame-2
1 1 3 3 2 2 2
Frame-3

Fig. No.2 LRU

The LRU is explained by above figure no.2.

PART B

(PART B: TO BE COMPLETED BY STUDENTS)

(Students must submit the soft copy as per following segments within
two hours of the practical. The soft copy must be uploaded on the ERP
or emailed to the concerned lab conducting faculties at the end of the
practical in case the there is no ERP access available)

Roll. No. Name:


Class Batch:
Date of Experiment: Date of Submission:
Grade:

B.1 Software Code written bystudent:


(Paste your Search material completed during the 2 hours of practical in the lab here)

Program code in C.

B.2 Input andOutput:


(input and output of the program)

B.3 Conclusion:

B. 4 Question of Curiosity
(To be answered by student based on the practical performed and learning/observations)
1. Which method from LRU or FIFO is better and why?
2. What do u mean by dirty bit or
valid and invalidbit.?
3. What is the use of page table?
Explain withexample.
4. Differentiate between LRU and FIFO.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy