Operating System Lecture Ten: DR Jamal Altuwaijari
Operating System Lecture Ten: DR Jamal Altuwaijari
Lecture ten
part1
Dr jamal altuwaijari
10. Virtual Memory
Virtual memory is a technique which allows the execution of
processes that may not be completely in memory. The main
advantage of this scheme is that the user programs can be larger than
physical memory.
10.1. Demand Paging
Virtual memory describes a set of techniques that allow us to execute
a program which is not entirely in memory. Demand paging is the
most common virtual memory system. Demand paging is similar to a
paging with swapping where programs reside on a swapping device,
(the backing store) when we want to execute a program we swap it
into memory. Rather than swapping the entire program into memory
we use a lazy swapper, which is never swaps a page unless it is
needed. If the program thies to access a page which was not brought
into memory then a page fault will occur. The procedure is quite
simple as in the figure 10.2.
10.1. Demand Paging
10.2. Performance of Demand Paging:
Demand paging can have a significant effect on the performance of a
c/s. The effective access time for a demand — paged memory = (l-p) X
ma + p * page fault time. Where p the probability of a page fault (o <
p<l). And ma: The memory access time for most c/s now range from
10-200 nanoseconds.
.'. Effective access time for demand-paged memory affected by the
time needed to service a page fault where there are three major
components of the page fault service time:
a. Service the page fault interrupts.
b. Swap in the page.
c. Restart the process.
The following figure 10.2 Show the organization of page table when
some pages are not in main memory.
10.2. Performance of Demand Paging:
10.3 Page Replacement
When any process is executing and a page fault occurs, the l-l/W traps
to O/S which checks its internal tables to see that this is a page fault
not an illegal memory access. The O/S determines where the desired
page is residing on the disk but then finds there are no free frames on
the free-frame list, all memory in use, so we need to use the page
replacement.
Page Replacement: It means if no frame is free we find on that is not
currently being used and free it by writing its contents to swap space
and changing the page table and all other tables to indicate that the
page is no longer in memory see The page—fault service routine Is
new modified to Include Page replaces.
1. Find the location of the Desired page on the disk.
2. Find a free frame:
a. If there is a free frame use it.
b. Otherwise use a page-replacement
Alg.to select a victim frame.
c. Write the victim page to the disk and
Change the P.T.
3. Read the desired page into the free
frame. And Change the P.T.
4. Restart the user process.
10.4. Page— Replacement Algorithms:
There are many different page—replacement algorithms. Every o/s has its
own unique replacement scheme .In general we want the one with the
lowest page-fault rate.
If we trace a process we might record the following address sequence l, 4, l,
6,1,6,16,1.
The above addresses reduced to the page number for simplicity and the
number called the reference string.
To determine the number of page faults for a particular reference string and
page-replacement and the number of frames available where as the number
of frames
Available increase. The number of page faults will decrease in general we
expect a curve
Such as the in the following figure 10.4.
To illustrate the page-replacement algorithms we shall use the reference
1. FIFO Algorithm
The simplest page-replacement algorithms 5 a FIFO when that page
was brought into memory. When the page must replace the oldest
page is chosen. We can create a FIFO queue to hold all pages in
memory, and replace the page at the head of the queue. When a page
is brought into memory we insert it at the tail of the queue.
Example
Consider the: following page reference string use three frames are
initially empty. Show how
The page faults and are brought into these frames using the FIFO
algorithm.
7 0 1 2 0 3 0 4 2 3 0 3 21 2 017 0 1
7 7 7 2 2 2 4 4 4 0 0 0 7 7 7
1 1 1 0 0
0 0 0 3 3 3 2 2 2
3 2 2 2 1
1 1 1 0 0 0 3 3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
The page faults = 15.
The FIFO alg. Is easy to understand and program. But its performance
is not always good. To illustrate the problems that is possible with a
FIFO page replacement. Consider the
Reference string
1,2,3,4,1,2,5,1,2,3,4,5
If draw the curve of page faults versus the number of available
frames, we notice that the number of faults for Four frames (10) is
greater than the number of faults for three frames. This result
is most Unexpected and known as Belays anomaly. It means the page
faults rate may increase as
.The number of free frames increased