cs 300 – lecture 22

12
CS 300 – Lecture 22 Intro to Computer Architecture / Assembly Language Virtual Memory

Upload: sahara

Post on 08-Jan-2016

22 views

Category:

Documents


0 download

DESCRIPTION

CS 300 – Lecture 22. Intro to Computer Architecture / Assembly Language Virtual Memory. Homework. Questions!. The Bad Old Days. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CS 300 – Lecture 22

CS 300 – Lecture 22

Intro to Computer Architecture

/ Assembly Language

Virtual Memory

Page 2: CS 300 – Lecture 22

Homework

Questions!

Page 3: CS 300 – Lecture 22

The Bad Old Days

Applications were directly coupled to the physical memory of the computer. If you wanted to run something, you would load the program you want and run it until it stops, then load a new program. Each program used the same physical memory addresses.

Page 4: CS 300 – Lecture 22

The Worse Old Days

The original PCs were based on an architecture with no memory management at all. The solution was a "segmented" memory design. This pervaded the original PC architecture (hardware AND software). Even though segments allowed bigger programs to run they didn't prevent applications from interfering with each other.Nobody cried the day DOS died.Finally, with the Pentium, real memory management was possible!

Page 5: CS 300 – Lecture 22

About Virtual Memory

Virtual Memory is another level of caching that sits between the disk and the main memory. While cache is exclusively a hardware issue, VM is handled in both hardware and operating system. That is, many of the things that are done in hardware in the cache can be addressed in software in the VM context.

Page 6: CS 300 – Lecture 22

Virtual Memory Issues

What problems are virtual memory hardware trying to solve? * Multiple programs running at once * Limited supply of physical memory * Hardware enforcement of capabilities (security) * Safe sharing among applications * Ability to "route around" hardware faults in physical memory

Page 7: CS 300 – Lecture 22

VM Ideas

Memory is divided into "pages". Pentium uses 1K words (4k bytes) per page.Addresses in your code are "virtual" – these are turned into physical addresses by a page table. The OS is responsible for the page table.ALL addresses are translated through this table (really indirection)The page table (or segment table) has other info: privileges, "Present" bit.The "swap file" is where VM pages are parked when rolled out of memory

Page 8: CS 300 – Lecture 22

Big Ideas in VM

Enforce privileges in hardware – keep user code from accessing devices or other things that would allow processes to interfere with each other.Read-only pages: prevent immutable data from accidental modificationCopy on write: allow pages to be shared or live outside swap space if not written on.Protection: use VM to detect conditions like stack overflow cheaplyThe page table defines the amount of memory available to a process.

Page 9: CS 300 – Lecture 22

The TLB

Bad news: every memory access needs to go through the page table

Good news: we can cache page table information so that there's no overhead to most address translation. Yet another cache is used to keep address translation from going too slow.

Page 10: CS 300 – Lecture 22

How Big is the Page Table?

Pentium: 32 bit address – 12 for the address in the table so that leaves 20 bits (1 million). That means a page table would be > 4 megabytes!

To fix this problem, the Pentium uses a two level table (page table of page tables)

Page 11: CS 300 – Lecture 22

Pentium Paging

Page 12: CS 300 – Lecture 22

Page Faulting

Anytime an instruction references memory that is "paged out" (this is what the "P" bit is for in the page table) you have to stop the program and wait for a disk read. This is MUCH more expensive than a cache miss!

This is an interrupt, similar to an IO interrupt

Poor program performance is usually a result of too many page misses.