CS 2200 - PowerPoint PPT Presentation

1 / 59
About This Presentation
Title:

CS 2200

Description:

CS 2200. Presentation 11. Virtual Memory. At this point... Five Classic Components. Memory. Processor. Datapath. Control. Input. Output. Disk ... – PowerPoint PPT presentation

Number of Views:16
Avg rating:3.0/5.0
Slides: 60
Provided by: BillL161
Category:
Tags: classic

less

Transcript and Presenter's Notes

Title: CS 2200


1
CS 2200
  • Presentation 11
  • Virtual Memory

2
At this point...
  • You should have a rough idea of how a processor
    works.
  • An even rougher idea of how a pipelined processor
    works.
  • Some concepts of scheduling should be known to
    you.
  • Plus you have been introduced to basic concepts
    involving interrupts and memory management.

3
Our Road Map
Processor
Memory Hierarchy
I/O Subsystem
Parallel Systems
Networking
4
Five Classic Components
Processor
Memory
Control
Datapath
5
Five Classic Components
Processor
Memory
Control
Datapath
6
Five Classic Components
Processor
Memory
Control
Datapath
7
A word about the bus...
Address Lines
Data Lines
Control Lines
8
Five Classic Components
Processor
Memory
Control
Datapath
9
What happens...
  • When a process is running and it does some I/O?
  • Does system call (like an interrupt)
  • OS saves state of process and puts in I/O queue.
  • Process at head of ready queue gets context
    switched in
  • Control passed to active process

10
Five Classic Components
Processor
Memory
Control
Datapath
11
Quick Review...
  • We know that an entire process could be swapped
    out to disk and eventually swapped back in to a
    different place
  • We know that a process can be broken up into
    pages and that each logical page can correspond
    to a physical frame using a page table

12
Virtual Memory
  • Scheme that allows execution of a process that is
    not 100 in memory.

13
Advantages
  • Allows processes to be larger than physical
    memory
  • Abstracts memory so programmers dont have to
    worry about it.

Most of the time
14
Background
  • Weve seen how memory can be paged
  • But doesnt the whole program have to be in
    memory?
  • Think about
  • Error handling code
  • Data structures may be bigger than needed
  • Certain operations may not be used

15
Background
  • Programmer can use all of the address space
  • But actual amount used might be smaller so more
    processes at same time
  • Improved
  • CPU Utilization
  • Throughput
  • Not improved
  • Response time
  • Turnaround time

Less I/O so maybe programs will run faster
16
Demand Paging
  • Paging systems
  • Swapping systems
  • Combine the two and make the swapping lazy!
  • Remember the invalid bit?

Page Table
17
Valid/Invalid Bit
  • Before
  • Used to indicate a page that the process was not
    allowed to use
  • Encountering absolutely meant an error had
    occurred.
  • Now
  • Indicates either the page is still on disk OR the
    page is truly invalid
  • The PCB must contain information to allow the
    processor to determine which of the two has
    occurred

18
Page Fault
Physical Memory
Operating System
CPU
page table
i
19
Page Fault
?
Physical Memory
Operating System
CPU
page table
i
20
Page Fault
THE SHAFT ?
Physical Memory
Operating System
CPU
page table
i
21
Page Fault
Disk
Physical Memory
Operating System
CPU
42
356
356
page table
i
22
Page Fault
Physical Memory
Operating System
CPU
42
356
356
page table
i
23
Page Fault
Physical Memory
Operating System
TRAP!
CPU
42
356
356
page table
i
24
Page Fault
OpSys says page is on disk
Physical Memory
Operating System
CPU
42
356
356
page table
i
25
Page Fault
Small detail OpSys must somehow maintain list of
what is on disk
Physical Memory
Operating System
CPU
42
356
356
page table
i
26
Page Fault
Physical Memory
Operating System
CPU
42
356
356
page table
i
27
Page Fault
Physical Memory
Operating System
CPU
42
356
356
page table
Free Frame
i
28
Page Fault
Physical Memory
Operating System
CPU
42
356
356
page table
i
29
Page Fault
Physical Memory
Operating System
CPU
42
356
356
page table
295
v
30
Page Fault
Physical Memory
Operating System
CPU
42
356
356
Restart Instruction
page table
295
v
31
Page Fault
Physical Memory
Operating System
CPU
42
356
295
356
page table
295
v
Now it works fine!
32
New Hardware Requirements?
  • No, not really.
  • We needed the valid bit for paging.
  • We needed the disk for swapping
  • So demand paging is all software!!!
  • Well almost!
  • What happens when page fault occurs during
    instruction fetch? Memory operation?

33
Performance of Demand Paging
  • Assume probability of page fault is p
  • So 0 ? p ? 1
  • Effective access time
  • (1 - p) x ma p x pageFaultTime

34
Page Fault
OpSys says page is on disk
Physical Memory
Operating System
CPU
Restart Instruction
page table
i
35
Performance of Demand Paging
  • Assume probability of page fault is p
  • So 0 ? p ? 1
  • Effective access time
  • (1 - p) x ma p x pageFaultTime
  • (1 - p) x 100 p x 25,000,000
  • 100 24,999,990 x p
  • If p 0.001
  • Effective access time 25 ?sec (250xs!)

36
Performance of Demand Paging
  • If we want only 10 degradation in performance
  • 110 gt 100 25,000,000 x p
  • 10 gt 25,000,000 x p
  • p lt 0.0000004.
  • Thus, 1 memory access in 2,500,000 can page
    fault.

37
Questions?
38
See any problems withPage Replacement so far?
39
Page Replacement
  • A process may be 10 pages in size but may use
    only half these pages.
  • In a multiprogramming environment this means we
    will be able to bring in more processes
  • But what if some processes suddenly need their 10
    pages?
  • Run out of free frames

Free Frame
40
What to do???
  • Page fault occurs
  • We have no free frames
  • Select victim frame
  • Write victim page to disk
  • Change page and frame tables
  • Read the desired page into the (new) free frame
  • Change page and frame tables
  • Restart the user process.

41
Page Replacement
  • Notice page replacement requires double the disk
    access
  • Remember that 25,000,000???
  • We can add a dirty bit indicating that the page
    in memory has been modified.
  • Still two key areas for performance
  • Page replacement algorithms
  • Frame allocation algorithms

42
Page Replacement Algorithms
  • Goal Minimum page fault rate
  • Can test algorithms on random numbers or actual
    sequences of instructions/data
  • Only care about different pages

43
FIFO
  • Maintain queue. As page is read in enqueue. Use
    head of queue as frame to replace
  • Sample 1,2,3,4,1,2,5,1,2,3,4,5

44
FIFO
12
12
Beladys Anomaly
9
10
45
FIFO
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
2
3
3
3
3
3
3
3
3
3
3
5
4
4
4
4
4
4
4
4
4
5
5
5
5
5
5
46
Optimal
  • Replace the page that will not be used for the
    longest period of time.
  • Hah!
  • Difficult to implement
  • Used as benchmark to compare other algorithms

47
LRU
  • Assume recent past is an indication of near
    future
  • Performance good but how to implement?
  • Store counter representing time last used
  • Stack of page numbers (doubly linked list)
  • Remove page number when used
  • Put on top of stack
  • Bottom is then LRU

48
LRU Approximation
  • Add reference bit
  • Set when page is accessed
  • Additional reference bits algorithm
  • Every 100 ms put reference bit into high order
    shifting all bits right and discarding low order
  • 00000000 (Not used)
  • 11001100
  • 00110011

49
LRU Approximation
  • Second chance
  • Maintain pointer to next victim
  • Essentially uses FIFO but if reference bit is set
    keep looking.
  • As pointer moves it sets reference bit to zero
  • If all reference bits are set ends up back where
    it started
  • Degenerates into FIFO if all reference bits are
    set

50
Counting Algorithms
  • Least frequently used
  • Replace page with smallest count
  • Suffers with page used a lot in the beginning
  • Can remedy by periodic shifting
  • Most frequently used
  • Argument is that LFU has just been brought in and
    has high potential to be used!

Rarely used/expensive/poor performance
51
Page Buffering Algorithms
  • Maintain a pool of free pages
  • Bring the needed page into the pool
  • Move the page to be replaced out freeing its
    space for pool
  • Maintain list of modified pages
  • When device idle write pages and flip dirty bit
    to clean

52
Allocation of Frames
  • Minimum Number of Frames
  • Process must have enough frames to execute any of
    its instructions
  • Allocation Algorithms
  • Equal allocation
  • Proportional allocation
  • Global vs. Local Allocation
  • Which frames can process select from?

53
Thrashing
  • Causes
  • OS monitors CPU usage
  • If CPU usage too low introduce an additional
    process
  • Global page replacement is being used
  • A process needs a lot of pages and takes them
    from other processes
  • These other processes start faulting
  • Soon everyone is doing nothing
  • OS brings in more processes

54
Thrashing
  • Working-Set Model
  • Define the working set to be the frames the
    process actually needs.
  • Make sure the process has enough
  • Define a ? or time interval to look back
  • If total demand (?wsi) too high suspend
  • Page-Fault Frequency
  • Frequency too high add more frames
  • Frequency too low take away frames

55
Other Considerations
  • Prepaging
  • e.g. Give process back its working set
  • Page Size
  • Trend is to bigger
  • Tradeoff
  • Smaller Less I/O, less allocated memory
  • Larger Less effect of overhead

56
Other Considerations
  • Program Structure
  • Wait! Something that applies to YOU!
  • I/O Interlock
  • DMA?
  • Two solutions
  • Double buffering (disk to system, system to user)
  • Locking (Add lock bit)
  • Real-Time Processing
  • Doesnt work well with RTS
  • Have tried mix

57
Question
  • What works well with Virtual Memory
  • Stacks
  • Hashed symbol table
  • Sequential search
  • Binary search
  • Pure code
  • Vector operations
  • Indirection

58
Questions?
59
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com