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

Lecture Virtual Memory Unit 5

Uploaded by

Adarsh Goud
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Lecture Virtual Memory Unit 5

Uploaded by

Adarsh Goud
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 24

VIRTUAL MEMORY

By: Navjot Kaur


VIRTUAL MEMORY

• Virtual memory is a feature of an operating system that allows a


computer to compensate for shortages of physical memory by
temporarily transferring pages of data from random access memory
(RAM) to disk storage.

• It is a technique that allows execution of processes that are not


completely in memory.

• One of the major advantage of this scheme is that programs can be


larger than the physical memory available.
VIRTUAL MEMORY

• Reason to move pages of data from RAM to disk storage - Because


OS was running out of RAM.

• Solution: The operating system will need to move other pages to


hard disk so it has space to bring back the pages it needs from
temporary disk storage.

This process is known as paging or swapping and the temporary


storage space on the hard disk is called a page file or a swap file.
VIRTUAL MEMORY
• Separation of user logical memory from physical memory.
• Program would no longer be constrained by the amount of physical
memory that is available.
• Because each program takes less space, more program could be run
at the same time.

• Less I/O would be needed to load or swap each user program into
memory, Virtual memory can be implemented via:
• Demand paging
• Demand segmentation
Transfer of a Paged Memory to Contiguous Disk Space
Demand Paging

• Bring a page into memory only when it is needed


• Less I/O needed
• Less memory needed
• Faster response
• More users

• Page is needed  reference to it


• not-in-memory  bring to memory
• Lazy swapper – never swaps a page into memory unless
page will be needed
• Swapper that deals with pages is a pager
Valid-Invalid Bit
• With each page table entry a valid–invalid bit is associated
(v  in-memory, i  not-in-memory)
• Initially valid–invalid bit is set to i on all entries
• Example of a page table snapshot:
Frame # valid-invalid bit
v
v
v
v
i
….

i
i
page table

During address translation, if valid–invalid bit in page table entry


is I  page fault
Page Table When Some Pages Are Not in Main Memory
Page Fault
• If the required page is not available in Physical Memory:
Page Fault
• If there is a reference to a page, first reference to that page
(if page is not available in physical memory) will trap to
operating system: page fault

1.Get empty frame


2.Swap page into frame
3.Reset tables
4.Set validation bit = v
5.Restart the instruction that caused the page fault
Steps in Handling a Page Fault
What happens if there is no free frame?
• Page replacement – find a page in memory and
swap it out
• Replacement algorithm selects the victim page
• want an algorithm which will result in minimum
number of page faults
Basic Page Replacement
1. Find the location of the desired page on disk

2. Find a free frame:


- If there is a free frame, then use it
- If there are no free frames, use a page
replacement algorithm to select a victim
frame

3. Bring the desired page into the (newly) freed


frame, and update the page and frame tables

4. Restart the interrupted instruction of the


process
Page Replacement
• Use modify (dirty) bit to reduce overhead of page transfers
• If victim page is unmodified, then no need to write it back to disk
Page Replacement Algorithms
• Want lowest page-fault rate
• Subsequently low page-fault service time too

• Evaluate algorithm by running it on a particular fixed


string of memory references (reference string) and
computing the number of page faults on that string
• FIFO page replacement
• Optimal page replacement
• LRU page replacement
FIFO Page Replacement
Graph of Page Faults vs Number of Frames

Expected behavior of a good page replacement algorithm.


First-In-First-Out (FIFO) Algorithm
• Reference string (12 total refs / 5 unique): 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
• 3 frames (3 pages can be in memory per process)

1 1 4 5
2 2 1 3 9 page faults
3 3 2 can
4 be in memory per process)
• 4 frames (3 pages

1 1 5 4
2 2 1 5 10 page faults
3 3 2

4 4 3
Optimal Algorithm (Called OPT or MIN)
We don’t! OPT is impossible to implement accurately unless
the order of page references is known a priori

1 4
2 6 page faults
3

4 5
LRU replacement

• Replace a page that has not been used for the longest period of time.
• This approach is LEAST RECENTLY USED(LRU) algorithm.
• LRU replacement associates with each page the time of the page’s last
use. When a page is to be replaced, LRU chooses the page that has not
been used for the longest period of time.
LRU Page Replacement Example
Thrashing
• Thrashing - a process is busy swapping pages in and out
• This high paging activity is called thrashing.

• If a process does not have “enough” pages, the page-fault rate is very high
• Page fault to get page
• Replace existing frame
• But quickly need replaced frame back
• This leads to:
• Low CPU utilization
• Operating system thinking that it needs to increase the degree of
multiprogramming
• Another process added to the system

• Thrashing  a process is busy swapping pages


Thrashing
• Thrashing occurs when a computer's virtual memory subsystem is in a constant
state of paging, rapidly exchanging data in memory for data on disk.
• If a process does not have “enough” pages in memory, it will quickly page fault, at
this point it must replace some page.
• Since all the pages are active in use, it must replace a page that will be needed
again, may be after some time.
• This result to occurrence of Page fault
• This leads to:
• Low CPU utilization and low throughput
• OS attempts to increase the degree of multiprogramming
• Another process added to the system
• Even more page faults ensue.
Thrashing
End of Chapter 9

You might also like