Virtual Memory Management - PowerPoint PPT Presentation

About This Presentation
Title:

Virtual Memory Management

Description:

Virtual Memory Management G. Anuradha Ref:- Galvin Important questions What is paging? Explain the structure of page table What is belady s algorithm? – PowerPoint PPT presentation

Number of Views:239
Avg rating:3.0/5.0
Slides: 36
Provided by: anur9
Category:

less

Transcript and Presenter's Notes

Title: Virtual Memory Management


1
Virtual Memory Management
  • G. Anuradha
  • Ref- Galvin

2
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

3
(No Transcript)
4
(No Transcript)
5
(No Transcript)
6
(No Transcript)
7
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

8
Transfer of a Paged Memory to Contiguous Disk
Space
9
Valid-Invalid Bit
  • With each page table entry a validinvalid bit is
    associated(v ? in-memory, i ? not-in-memory)
  • Initially validinvalid bit is set to i on all
    entries
  • Example of a page table snapshot
  • During address translation, if validinvalid bit
    in page table entry
  • is I ? page fault

Frame
valid-invalid bit
v
v
v
v
i
.
i
i
page table
10
Page Table When Some Pages Are Not in Main Memory
11
Page Fault
  • If there is a reference to a page, first
    reference to that page will trap to operating
    system
  • page fault
  • Operating system looks at another table to
    decide
  • Invalid reference ? abort
  • Just not in memory
  • Get empty frame
  • Swap page into frame
  • Reset tables
  • Set validation bit v
  • Restart the instruction that caused the page fault

12
Steps in Handling a Page Fault
13
Demand Paging
  • Pure Demand Paging-
  • Begin a process with no pages in the memory
  • Bring the pages only as and when required
  • Hardware support for demand paging
  • Page table
  • Secondary memory

14
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 )

15
Sequence of events when a page fault occurs
  1. Trap to OS
  2. Save the user registers and process states
  3. Determine the interrupt that causes a page fault
  4. Check that the page referred was legal and
    determine the location of the page on the disk
  5. Issue a read from the disk to free frame
  6. Wait in a queue until serviced
  7. Wait for device seek/latency time
  8. Begin the transfer of page to a free frame

16
Sequence of events when a page fault occurs
  1. While waiting, allocate the CPU to some other
    user
  2. Receive an interrupt from the disk I/O subsystem
  3. Save the registers and process state for the
    other user
  4. Determine that the interrupt was from disk
  5. Correct page table entries
  6. Wait for CPU to be allocated to the process again
  7. Restore the user registers, process state and
    then resume the interrupted instruction

17
  • Effective Access Time (EAT)
  • EAT (1 p) x memory access
  • p (page fault overhead
  • swap page out
  • swap page in
  • restart overhead )

18
Demand Paging Example
  • Memory access time 200 nanoseconds
  • Average page-fault service time 8 milliseconds
  • Effective Access Time (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!!
  • (PAGE FAULT SHOULD BE KEPT AT HE MINIMUM POSSIBLE
    VALUE IN ORDER TO IMPROVE THE ACCESS TIME)

19
Copy-on-write
  • Process creation can be initiated by demand
    paging
  • However fork command bypasses the need of demand
    paging
  • Fork() command created a copy of the parents
    address space for the child
  • If many child process uses the exec() system call
    a copy-on-write method is used

20
Before Process 1 Modifies Page C
21
After Process 1 Modifies Page C
  • A copy of page C is created
  • Child process will modify its copied page and not
    the page belonging to the parent process
  • If pages are not modified then its shared by
    parent and child processes.

22
Page Replacement
23
Basic Page Replacement
  1. Find the location of the desired page on disk
  2. Find a free frame - If there is a free
    frame, use it - If there is no free frame,
    use a page replacement algorithm to select a
    victim frame
  3. Bring the desired page into the (newly) free
    frame update the page and frame tables
  4. Restart the process

24
Page Replacement
Use modify (dirty) bit to reduce overhead of page
transfers only modified pages are written to
disk
25
Page Replacement contd
  • Two major problems must be solved to implement
    demand paging
  • Frame allocation algorithm
  • Page-replacement algorithm
  • Want lowest page-fault rate
  • Evaluate algorithm by running it on a particular
    string of memory references (reference string)
    and computing the number of page faults on that
    string

26
First-In-First-Out (FIFO) Algorithm
  • Reference string 1, 2, 3, 4, 1, 2, 5, 1, 2, 3,
    4, 5
  • 3 frames (3 pages can be in memory at a time per
    process)
  • 4 frames
  • Beladys Anomaly more frames ? more page faults

1
1
4
5
2
2
1
3
9 page faults
3
3
2
4
1
1
5
4
2
2
1
10 page faults
5
3
3
2
4
4
3
27
FIFO Page Replacement
28
FIFO Illustrating Beladys Anomaly
29
Optimal Algorithm
  • Replace page that will not be used for longest
    period of time
  • 4 frames example
  • 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
  • How do you know this?
  • Used for measuring how well your algorithm
    performs

1
4
2
6 page faults
3
4
5
30
Optimal Page Replacement
Difficult to implement becos it requires future
knowledge of reference string
31
Least Recently Used (LRU) Algorithm
  • Reference string 1, 2, 3, 4, 1, 2, 5, 1, 2, 3,
    4, 5
  • Counter implementation
  • Every page entry has a counter every time page
    is referenced through this entry, copy the clock
    into the counter
  • When a page needs to be changed, look at the
    counters to determine which are to change

1
1
5
1
1
2
2
2
2
2
5
4
4
3
5
3
3
3
4
4
32
LRU Page Replacement
33
LRU Algorithm (Cont.)
  • Stack implementation keep a stack of page
    numbers in a double link form
  • Page referenced
  • move it to the top
  • Most recently used page is always at the top of
    the stack and least recently used page is always
    at the bottom
  • Can be implemented by a double linked list with a
    head pointer and a tail pointer
  • Both LRU and ORU comes under the class of algos
    called as stack algorithm
  • Does not suffer from Beladys Anamoly

34
Important questions
  • What is paging? Explain the structure of page
    table
  • What is beladys algorithm? Explain LRU, FIFO,
    OPR algos. Which algorithm suffers from Beladys
    anomaly?
  • Short note on page fault handling
  • Explain virtual memory and demand paging
  • Draw and explain paging hardware with TLB
  • Explain paging in detail. Describe how logical
    address converted to physical address
  • Explain how memory management takes place in
    Linux

35
Important questions
Write a Comment
User Comments (0)
About PowerShow.com