0% found this document useful (0 votes)
33 views21 pages

Virtual Memory 1

Virtual memory allows a program's logical address space to be larger than physical memory by paging portions of memory in and out of physical memory frames as needed. When a program accesses a page not in memory, a page fault occurs which the operating system handles by finding a free frame, swapping out the needed page from disk, and updating page tables. Copy-on-write allows processes to initially share pages to improve efficiency of process creation.

Uploaded by

nasa stick
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)
33 views21 pages

Virtual Memory 1

Virtual memory allows a program's logical address space to be larger than physical memory by paging portions of memory in and out of physical memory frames as needed. When a program accesses a page not in memory, a page fault occurs which the operating system handles by finding a free frame, swapping out the needed page from disk, and updating page tables. Copy-on-write allows processes to initially share pages to improve efficiency of process creation.

Uploaded by

nasa stick
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/ 21

Chapter 9: Virtual Memory

Virtual Memory-1
 Background
 Demand Paging
 Copy-on-Write
Objectives

 To describe the benefits of a virtual memory


system

 To explain the concepts of demand paging,


page-replacement algorithms, and allocation of
page frames

 To discuss the principle of the working-set model


Background
 Virtual memory – separation of user logical memory
from physical memory.
 Only part of the program needs to be in memory for
execution
 Logical address space can therefore be much larger
than physical address space
 Allows address spaces to be shared by several
processes
 Allows for more efficient process creation

 Virtual memory can be implemented via:


 Demand paging
 Demand segmentation
Virtual Memory That is Larger Than Physical Memory


Virtual-address Space
Shared Library Using Virtual Memory
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


 invalid reference  abort
 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
Transfer of a Paged Memory to Contiguous Disk Space
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 there is a reference to a page, first reference to
that page will trap to operating system:
page fault
1. Operating system looks at another table to
decide:
 Invalid reference  abort
 Just not in memory
2. Get empty frame
3. Swap page into frame
4. Reset tables
5. Set validation bit = v
6. Restart the instruction that caused the page fault
Page Fault (Cont.)

 Restart instruction
 block move

 auto increment/decrement location


Steps in Handling a Page Fault
Performance of Demand Paging
 Page Fault Rate 0  p  1.0
 if p = 0 no page faults
 if p = 1, every reference is a fault

 Effective Access Time (EAT)


EAT = (1 – p) x memory access
+ p (page fault overhead
+ swap page out
+ swap page in
+ restart overhead
)
Demand Paging Example
 Memory access time = 200 nanoseconds

 Average page-fault service time = 8 milliseconds

 EAT = (1 – p) x 200 + p (8 milliseconds)


= (1 – p x 200 + p x 8,000,000
= 200 + p x 7,999,800

 If one access out of 1,000 causes a page fault, then


EAT = 8.2 microseconds.
This is a slowdown by a factor of 40!!
Process Creation

 Virtual memory allows other benefits during process


creation:

- Copy-on-Write

- Memory-Mapped Files (later)


Copy-on-Write
 Copy-on-Write (COW) allows both parent and child
processes to initially share the same pages in memory

If either process modifies a shared page, only then is the


page copied

 COW allows more efficient process creation as only


modified pages are copied

 Free pages are allocated from a pool of zeroed-out


pages
Before Process 1 Modifies Page C
After Process 1 Modifies Page C
What happens if there is no free frame?

 Page replacement – find some page in memory, but


not really in use, swap it out
 algorithm
 performance – want an algorithm which will
result in minimum number of page faults
 Same page may be brought into memory several
times

You might also like