11396OS Expt No-09
11396OS Expt No-09
College Computer
Engineering Department
Program: Sem IV
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-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.)
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.
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.
PART B
(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)
Program code in C.
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.