0% found this document useful (0 votes)
54 views

Virtual Memory-1

Virtual memory allows processes to have a logical address space larger than physical memory by swapping pages between main memory and secondary storage as needed. When a process attempts to access a page that is not in main memory, a page fault occurs and the OS selects a page using a page replacement algorithm like FIFO, LRU, or OPT to swap out and replace with the requested page from secondary storage. Page replacement algorithms aim to minimize page faults by selecting pages least likely to be used soon. Too many page faults can cause thrashing where the system spends more time swapping pages than executing processes.

Uploaded by

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

Virtual Memory-1

Virtual memory allows processes to have a logical address space larger than physical memory by swapping pages between main memory and secondary storage as needed. When a process attempts to access a page that is not in main memory, a page fault occurs and the OS selects a page using a page replacement algorithm like FIFO, LRU, or OPT to swap out and replace with the requested page from secondary storage. Page replacement algorithms aim to minimize page faults by selecting pages least likely to be used soon. Too many page faults can cause thrashing where the system spends more time swapping pages than executing processes.

Uploaded by

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

Virtual memory

 Virtual memory is a technique that allows the execution of process even when
the logical address space is greater than the available physical memory space.
 For example : if a program size or logical address space is 15MB but the
available memory space is only 12MB, then the 12MB of the program is loaded
in main memory and the remaining 3MB is loaded in secondary memory. When
the 3MB is needed for the execution then swapping process is done. A 3MB of
the program is swap-out to secondary memory so that the requested 3MB is
swap-in to the main memory.
Advantage of virtual memory
 Efficient main memory utilization by allowing partial programs to be loaded
and so more programs could run at the same time.
 Efficient CPU utilization and better throughput.
DEMAND PAGING
 Demand aging is the application of virtual memory. Virtual memory is
commonly implemented by demand paging.
 It is the combination of paging and swapping.
 The criteria of this scheme is “ a page is not loaded in to the main memory from
secondary memory until it is needed” , that is only on demand a page is loaded
in to main memory. This is called demand paging

 For example: if a job size is 24KB and its page and frame size is 4KB then the
logical space is divided into 6 pages but the available memory space is only
12MB , i.e 3 frames are available and the remaining 3 pages are loaded in the
secondary storage device. Whenever these pages are on demand the OS swap-in
those pages in to main memory

PAGE FAULT
When the processor need to execute a particular page and that page is not available
in main memory this situation is said to be ‘page fault’. When the page fault is
happened the page replacement will be needed. Page replacement means select a
victim page in the main memory, replace that page with the required page from the
backing store
PAGE REPLACEMENT ALGORITHM
 Page replacement algorithms are the technique which decides which memory
page to swap out, when a page of memory needs to be allocated.

 Paging happens whenever a page fault occurs. When the page fault is happened
the page replacement will be needed.

 The page replacement means select a victim page in the main memory, replace
that page with the required page from the backing store (disk).

 To select the victim page, Page Replacement Algorithm is used.

 There are many different page replacement algorithms.


 Algorithm is evaluated by running it on a particular reference string and
computing the number of page faults.
 The performance of the Page Replacement Algorithm is measured through the
page fault rate. The algorithm having the least page fault rate is the best one.
 To determine the number of page faults for a particular reference string and
page replacement algorithm, will also depends on the number of page frames
available. As the number of frames available increase, the number of page
faults will decrease.

1)First In First Out (FIFO) algorithm (Time based)

 The simplest page-replacement algorithm is a FIFO algorithm


 Criteria of this algorithm:
“To replace a page the oldest page in main memory is selected for
replacement”
Or
“Replace a page that has been in memory longest.”
 When a page must be replaced, the oldest page is chosen.
 A FIFO replacement algorithm associates with each page the time when that
page was brought into memory.
 Focuses on the length of time a page has been in memory rather than how
much the page is being used
Example:

Optimal Page algorithm (OPT or MIN) ( Belady’s Algorithm) (Time based)

 An optimal page-replacement algorithm has the lowest page-fault rate of all


algorithms
 Criteria of this algorithm:
“Replace a page that will not be used for the longest period of
time.”
 Optimal uses the time when a page is to be used.
 Optimal replacement is much better than a FIFO.
 The optimal page-replacement algorithm is difficult to implement, because it
requires future knowledge of the reference string. Used mainly for
comparison studies

Least Recently Used (LRU) algorithm (Time based)

 This algorithm is easy to implement and replace page by looking backward in time
rather than forward as in optimal
 Criteria of this algorithm:
“Replace a page which has not been used for the longest period of
time in main memory is selected for replacement.”

 LRU replacement associates with each page the time of that page's last use.
o The FIFO algorithm uses the time when a page was brought into
memory;
o The OPT algorithm uses the time when a page is to be used.
o In LRU replace the page that has not been used for the longest period
of time.
Example:

Least frequently Used (LFU) algorithm (count based)

 Criteria of this algorithm:


“Select a page for replacement if the page has not been used often in the
past”
Or
“Replace a page that has the smallest count”
 In this algorithm each page contains a counter. The actively used page has a
large reference count, so need not replace the actively used page.

 Page with the smallest count is the one which will be selected for
replacement.

 This algorithm suffers from the situation in which a page is used heavily
during the initial phase of a process, but then is never used again and
remains in memory because it has the largest reference count.
Most frequently Used (MFU) algorithm (count based)

 Criteria of this algorithm:


“Replace a page that has the maximum frequency count of all
pages”

 MFU replacement algorithm is based on the argument that the page with the
smallest count was probably just brought in and has yet to be used most.
Solution to the LFU problem.
 MFU and LFU are the most expensive algorithms

Clock Page Replacement Algorithm


 This algorithm requires an additional bit with each frame referred as ‘use-
bit’, which is set to ‘1’ when a page is first loaded in memory.
 All the set of victim pages is considered to be in a circular buffer similar to a
clock.
 A pointer is associated with the circular buffer which indicates the next
frame in the buffer. When a page is replaced the pointer moves to the next in
the set.
 When a page is to be replaced the OS scans the buffer to find the first frame
that has its use-bit set to ‘0’.
 During the scan if it encounters a frame with a use-bit ‘1’ it changes that bit
to ‘0’ and move to next.
 If the entire frame has a use-bit’1’ then reset the entire use-bit to’0’
 This algorithm is similar to FIFO policy except in clock wise
Belady’s Anomaly
The general principle is if number of frames increased the page fault rate will be
decreased. But in some cases by increasing the frames the page fault also increase.
This result is most unexpected and is known as “Belady’s Anomaly’
Example consider the string 1,2,3,4,1,2,5,1,2,3,4,6 if we apply the FIFO algorithm
with 3 frames number of page fault is 9 and if we increase the frame to 4 the
number of page fault is 10. This is known as Belady’s Anomaly
THRASHING
If the number of process submitted to the CPU for execution are increased, the
CPU utilization will also increases. But increasing the process continuously at
certain time the CPU utilization falls down sharply. This situation is said to be
‘Thrashing’

You might also like