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

Virtual Memory

Uploaded by

danielkwantwi7
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)
4 views

Virtual Memory

Uploaded by

danielkwantwi7
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/ 36

VIRTUAL MEMORY

OBJECTIVES:
After studying this unit, you should be able to:
1. Discuss Virtual Memory
2. Explain operations of Virtual Memory
3. Application of Virtual memory
4. Describe Demand Paging in operating
systems
5. Discuss Page Replacement Algorithm
1
Definition

• A computer can address more memory


than the amount physically installed on
the system.
• This extra memory is actually called
virtual memory and it is a section of a
hard disk that's set up to emulate the
computer's RAM.
2
Definition

• The main visible advantage of this


scheme is that programs can be larger
than physical memory.

3
Purpose of Virtual memory

Virtual memory serves two purposes;


• First, it allows us to extend the use of physical
memory by using disk.
• Second, it allows us to have memory
protection, because each virtual address is
translated to a physical address.

4
Purpose of MMU

• Modern microprocessors intended for


general-purpose use, a memory
management unit, or MMU, is built into
the hardware.
• The MMU's job is to translate virtual
addresses into physical addresses. A
basic example is given below
5
Basic Example of MMU

6
Application of Virtual memory

• Virtual memory is commonly


implemented by demand paging.
• It can also be implemented in a
segmentation system.
• Demand segmentation can also be used
to provide virtual memory.

7
Demand Paging

• A demand paging system is quite similar


to a paging system with swapping
where processes reside in secondary
memory and pages are loaded only on
demand, not in advance.

8
Demand Paging

• When a context switch occurs, the operating


system does not copy any of the old program’s
pages out to the disk or any of the new
program’s pages into the main memory
Instead, it just begins executing the new
program after loading the first page and
fetches that program’s pages as they are
referenced.

9
Demand Paging

10
Demand Paging

• While executing a program, if the program


references a page which is not available in the
main memory because it was swapped out a
little ago, the processor treats this invalid
memory reference as a page fault and
transfers control from the program to the
operating system to demand the page back
into the memory.

11
Advantages

Following are the advantages of Demand


Paging:

• Large virtual memory.


• More efficient use of memory.
• There is no limit on degree of
multiprogramming.

12
Disadvantages

• Number of tables and the amount of


processor overhead for handling page
interrupts are greater than in the case of
the simple paged management
techniques.

13
Page Replacement Algorithm

• Page replacement algorithms are the


techniques using which an Operating
System decides which memory pages to
swap out, write to disk when a page of
memory needs to be allocated.

14
Page Replacement Algorithm

• Paging happens whenever a page fault


occurs and a free page cannot be used
for allocation purpose accounting to
reason that pages are not available or
the number of free pages is lower than
required pages.

15
Page Replacement Algorithm

• When the page that was selected for


replacement and was paged out, is
referenced again, it has to read in from
disk, and this requires for I/O
completion.
• This process determines the quality of
the page replacement algorithm: the
lesser the time waiting for page-ins, the
better is the algorithm.
16
Page Replacement Algorithm

• A page replacement algorithm looks at


the limited information about accessing
the pages provided by hardware, and
tries to select which pages should be
replaced to minimize the total number of
page misses, while balancing it with the
costs of primary storage and processor
time of the algorithm itself.
17
Page Replacement Algorithm

• There are many different page


replacement algorithms. We evaluate an
algorithm by running it on a particular
string of memory reference and
computing the number of page faults,

18
Reference String

• The string of memory references is called


reference string.
• Reference strings are generated artificially or
by tracing a given system and recording the
address of each memory reference.
• The latter choice produces a large number of
data, where we note two things.

19
Reference String

• For a given page size, we need to


consider only the page number, not the
entire address.
• If we have a reference to a page p, then
any immediately following references to
page p will never cause a page fault.

20
Reference String

• Page p will be in memory after the first


reference; the immediately following
references will not fault.
• For example, consider the following sequence
of addresses − 123,215,600,1234,76,96
• If page size is 100, then the reference string is
1,2,6,12,0,0

21
First In First Out (FIFO) algorithm

• Oldest page in main memory is the one


which will be selected for replacement.

• Easy to implement, keep a list, replace


pages from the tail and add new pages at
the head.

22
First In First Out (FIFO) algorithm

23
Optimal Page algorithm

• An optimal page-replacement algorithm


has the lowest page-fault rate of all
algorithms.
• An optimal page-replacement algorithm
exists, and has been called OPT or MIN.
• Replace the page that will not be used for
the longest period of time. Use the time
when a page is to be used.
24
Optimal Page algorithm

25
Least Recently Used (LRU) algorithm

• Page which has not been used for the


longest time in main memory is the one
which will be selected for replacement.
• Easy to implement, keep a list, replace
pages by looking back into time.

26
Least Recently Used (LRU) algorithm

27
Page Buffering algorithm

• To get a process start quickly, keep a pool of


free frames.
• On page fault, select a page to be replaced.
• Write the new page in the frame of free pool,
mark the page table and restart the process.
• Now write the dirty page out of disk and
place the frame holding replaced page in
free pool.
28
Least frequently Used (LFU) algorithm

• The 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.

29
Comparison among Scheduler

• Most frequently Used(MFU) algorithm


• This algorithm is based on the argument that
the page with the smallest count was probably
just brought in and has yet to be used.

30
Self Assessment Questions
• 1. Every process needs to be loaded into physical
memory for execution. (True / False)
• 2. _______________ is implemented using demand
paging.
• 3. When a process is to be executed then only that
page of the process, which needs to be currently
executed, is swapped into memory. This method is
called _______________. (Pick the right option)
• a) Demand Paging
• b) Request Paging
• c) Swap Paging
• d) Change Paging
31
Self Assessment Questions

• 4. Whenever a page fault occurs instead of


using any page replacement algorithms simply
terminate the process. (True / False)
• 5. ___________ algorithm is more a
benchmark algorithm for comparison.
6. The operating system closely monitors CPU
utilization. (True / False)

32
Self Assessment Questions
• 7. _______________ is a high paging activity
in which a process spends more time in paging
than executing.
• 8. PFF stands for _______________. (Pick the
right option)
• a) Page Fault Finder
• b) Page Finding Frequency
• c) Page Fault Frequency
• d) Page Fault Finding
33
Answers to Self Assessment Questions
• 1. True
• 2. Virtual Memory
• 3. a) Demand Paging
• 4. False
• 5. Optimal Page Replacement
• 6. True
• 7. Thrashing
• 8. c) Page Fault Frequency

34
QUESTIONS TIME

35
NEXT TOPIC

• Operating System - I/O Hardware

36

You might also like