Upload
gil-rasmussen
View
26
Download
0
Embed Size (px)
DESCRIPTION
Cosc 3P92. Week 9 & 10 Lecture slides. Violence is the last refuge of the incompetent. Isaac Asimov, Salvor Hardin in "Foundation". Virtual Memory. The main idea is to allow programs to address more memory locations than are physically available. - PowerPoint PPT Presentation
Citation preview
1
COSC 3P92
Cosc 3P92
Week 9 & 10 Lecture slides
Violence is the last refuge of the incompetent.
Isaac Asimov, Salvor Hardin in "Foundation"
2
COSC 3P92
Virtual Memory• The main idea is to allow programs to address
more memory locations than are physically available.
• first: overlays programmer manually divide programs into sections, and read, write them out during execution.
• virtual memory: automatic transparent overly mgmt
• virtual (logical) address: generated by program physical address: actual memory address during execution
• Addresses generated by programs are called virtual addresses, and which are mapped into physical addresses during execution time.
3
COSC 3P92
Virtual Memory
• Three techniques:– paging system
– segmentation system
– paged segmentation system
program
virtualaddress
VMalgorithm
physicaladdress Main
memory
secondarystorage
4
COSC 3P92
IF PageTable[page #]. residence-bit =1 THEN
RETURN Frame[ PageTable[page #].frame ]+offset
ELSE
page fault
Virtual Memory: PagingPaging system: The virtual address space is divided into equal-sized
pages and the physical memory is divided into frames of the same size. Physical memoryFrame
01234567
(4K per frame)
(32K total)
Page TableVirtual Memorypage 0page 1page 2page 3page 4page 5page 6page 7page 8page 9page 10page 11page 12page 13page 14page 15
0110010010100001
0650010000700003
page 2
page 5page 8
page 10page 1
page 15
page # offsetVirtual address
(4K per page)
(64K total)
3-bit
4-bit 12-bit
1-bit
5
COSC 3P92
Example
6
COSC 3P92
Paging • page mapping mechanism is often done via special hardware
• page fault: page not resident
- read from secondary storage into main memory
- update page table with physical memory address
- repeat instruction that caused fault
• demand paging: get page only when asked for
vs. algorithms which evaluate page usage and do predictive page fetches
• working set: the finite set of pages which a program will use during execution (ie. progrms don't use infinite memory)
• when working set size > # page frames, thrashing likely
totalpagesused
time --->
7
COSC 3P92
programmemoryspace
virtual mapping
Paging• Page replacement:
– random (not recommended)
– least recently used
– first-in-first-out (least recently paged in)
• can use dirty bits: write back pages only when modified
• fragmentation: page sizes fixed, so can have unused page portions (and therefore unused memory)
8
COSC 3P92
Paging
• Large page sizes: – maximal use of slow secondary storage
– less frequent page reads
– smaller tables
– more apt to have fragmentation
• Small page sizes:– less fragmentation
– good for programs that use small spread out memory references
– need more IO calls, larger tables
9
COSC 3P92
Virtual Memory: Segmentation• Segmentation system: A program is divided into a collection of logical
segments (e.g., procedures, arrays, stacks) which may be of different sizes. Each segment has a separate virtual address space.
segment B
segment A
segment C
segment D
0
1
2
3
Virtual Memorysegment B
segment A
Physial Memory
1 10K
1
0
0
7K
4K
5K
Segment Table
seg # offsetVirtual address
2-bit N-bit
unused
unused
IF SegmentTable[seg #].valid-bit = 1 THEN
IF offset < SegmentTable[seg #].length THEN
RETURN SegmentTable[seg #].base + offset
ELSE
memory violation
ELSE
segment fault
10
COSC 3P92
Segmentation
• Segments: can be allocated for different program parts, data structures, users
• Different modes, access privileges can be assigned– (permits memory violation checking, shared memory,...)
• Sizes are alterable during execution.
• The basis for multitasking multi-user systems
11
COSC 3P92
Segmentation
• Garbage collection: best fit, first-fit, hole compaction, ...
12
COSC 3P92
Paged segmentation system• Merges ideas of previous 2 approaches
• Segments are divided into groups of pages
• Virtual address is a triple <s,p,d>
• e.g MULTICS
13
COSC 3P92
[fig next page]
Paged segmentation• Address mapping:
1. segment numbers leads to index in segment table
» gives base address of page table
2. page no. p indexed into page table, and frame p' is found
3. physical address computed by adding displacement d to p'
• Speeding up virtual memory access– address translation look aside buffer
– like a page table cache
– associative memory contains most recently used page info
– common in mainframes
14
COSC 3P92
Physical Address
15
COSC 3P92
Paged vs Segmentation
16
COSC 3P92
Example: Pentium II VM support• A paged-segmentation system
• MMU: memory mgmt unit on CPU
• PII has segment registers: DS (data), CS (code), ...• [6.12, 6.13, 6.14]
• Scheme:– selector: 16-bits, 1 per segment, loaded into approp. segment register
– local: application; global: OS, system
– corresp. segment descriptor loaded for that segment
– offset is checked to see if it is beyong segment bounds (TRAP - software interrupt)
– seg size: G = 0 (seg size up to 1 Mb); G=1 (pages)
– base added to offset to get a linear address (base split for back-compatibility with 286)
– if paging off, this address is physical address
– if paging on: --> it’s a virtual address
» must be mapped: page directory (1K entries) --> page table (1K page entries) --> phys address [6.15]
17
COSC 3P92
18
COSC 3P92
19
COSC 3P92
20
COSC 3P92
Example: ultraSparc VM support
• Paged virtual memory supported
• only 44 bits of 64-bit addr space used for VM• varying page sizes: [6.17]
• TLB: translation lookaside buffer [6.18]– maps virtual page # to physical page frame #
– 64 most recently used virt. page #’s for each of instns, data
– also a context -- process ID
– if not in TLB, a trap called, and OS software must fix
– not same as a page miss! page may be in memory.
– OS must also maintain a TSB (trans. storage buffer) - like a cache of pages
– otherwise, if a TSB miss, then OS does whatever it wants to implement it --> no H/W support!
21
COSC 3P92
22
COSC 3P92
23
COSC 3P92
Comparing PII and UltraSparc
• PII: – 32-bit segments, fixed 1K segment/page table sizes
– max 1 million pages per segment
– can do pure segmentation, pure paging, or paged segmentation
– only 1 segment per process in Windows, Unix
• UltraSparc: – huge address space
– 2 billion pages: conventional page tables unworkable
24
COSC 3P92
The end