ch7d- 2 ee/cs/cpe 3760 - computer organization seattle pacific university individual space every...

9

Upload: leo-short

Post on 04-Jan-2016

215 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Ch7d- 2 EE/CS/CPE 3760 - Computer Organization  Seattle Pacific University Individual Space Every process wants its own space Ideally, it would like
Page 2: Ch7d- 2 EE/CS/CPE 3760 - Computer Organization  Seattle Pacific University Individual Space Every process wants its own space Ideally, it would like

Ch7d- 2EE/CS/CPE 3760 - Computer OrganizationSeattle Pacific University

Individual Space• Every process wants its own space

• Ideally, it would like the entire computer to itself

• Sharing the computer’s memory creates problems• Sometimes a program will be at location 4000,

sometimes at location 5888820, etc.

7.4

• Use Virtual Memory to fool each process to thinking that it starts at location 0

• CPU uses virtual addresses - Start the program at virtual page 0, even if it’s not physical page 0

• Each process must have an individual page table to make this work

• Every virtual page 0 must point to a different physical page, and so on

Page 3: Ch7d- 2 EE/CS/CPE 3760 - Computer Organization  Seattle Pacific University Individual Space Every process wants its own space Ideally, it would like

Ch7d- 3EE/CS/CPE 3760 - Computer OrganizationSeattle Pacific University

Example

VPN Valid PPN/(index) Bit Disk address000000 1 1001000001 0 sector 5000...000010 1 1100000011 0 sector 4323…000100 1 1011000101 1 0101000110 0 sector 1239...000111 1 0001

Page Table for process A:

VPN Valid PPN/(index) Bit Disk address000000 1 0010000001 1 0000000010 1 0011000011 1 1100000100 0 sector 2311...000101 0 sector 158...000110 0 sector 555...000111 1 0100

Page Table for process B:

7.4

Virtual page 000000 (process A) points to physical page 1001.

Virtual page 000000 (process B) points to physical page 0010.The processes both can start at location 000000, but have different data.

Note: Physical page 1100 is shared.

Page 4: Ch7d- 2 EE/CS/CPE 3760 - Computer Organization  Seattle Pacific University Individual Space Every process wants its own space Ideally, it would like

Ch7d- 4EE/CS/CPE 3760 - Computer OrganizationSeattle Pacific University

Protection Using Virtual Memory

7.4

• We want to protect different processes from each other• Can’t read or write to any other process’s memory,

unless specifically allowed

• Providing separate page tables fixes this problem• Each process can only access pages through its page

table• As long as the page table doesn’t point to pages

belonging to other processes, no problem• Since only the OS can write the page tables, the

system is safe

Page 5: Ch7d- 2 EE/CS/CPE 3760 - Computer Organization  Seattle Pacific University Individual Space Every process wants its own space Ideally, it would like

Ch7d- 5EE/CS/CPE 3760 - Computer OrganizationSeattle Pacific University

Protection Example

VPN Valid PPN/(index) Bit Disk address000000 1 1001000001 0 sector 5000...000010 1 1100000011 0 sector 4323…000100 1 1011000101 1 0101000110 0 sector 1239...000111 1 0001

Page Table for process A:

VPN Valid PPN/(index) Bit Disk address000000 1 0010000001 1 0000000010 1 0011000011 1 1100000100 0 sector 2311...000101 0 sector 158...000110 0 sector 555...000111 1 0100

Page Table for process B:

7.4

How can process A access process B’s V.P. 000010?

Note: Since physical page 1100 is shared, protection is violated.

None of process A’s V.P. point to Physical page 0011 - Impossible toto access it!

Page 6: Ch7d- 2 EE/CS/CPE 3760 - Computer Organization  Seattle Pacific University Individual Space Every process wants its own space Ideally, it would like

Ch7d- 6EE/CS/CPE 3760 - Computer OrganizationSeattle Pacific University

Shooting Ourselves in the Foot

7.4

• Virtual Memory Access

• Look up page number in page table

• Access memory

• Each memory access becomes two accesses

• Even for addresses stored in the cache

• Solution: Cache the page table entries in a special cache

• The Translation Lookaside Buffer (TLB) is just a cache that holds recently accessed page table entries

• A TLB hit means that we don’t have to actually look in the page table

Page 7: Ch7d- 2 EE/CS/CPE 3760 - Computer Organization  Seattle Pacific University Individual Space Every process wants its own space Ideally, it would like

Ch7d- 7EE/CS/CPE 3760 - Computer OrganizationSeattle Pacific University

TLB Design

7.4

• We want the TLB to have a high hit rate• Fortunately, pages are huge, providing super-high

locality• TLB usually only has a small number of entries (i.e.

64) and is fully-associative• Typical hit rates are 98.0 to 99.9%

• The TLB should store anything needed from the page table• Physical page number• Valid bit, Dirty bit

• Warning: TLB can violate protection after a process switch• Flush the TLB on each process switch

Page 8: Ch7d- 2 EE/CS/CPE 3760 - Computer Organization  Seattle Pacific University Individual Space Every process wants its own space Ideally, it would like

Ch7d- 8EE/CS/CPE 3760 - Computer OrganizationSeattle Pacific University

Virtual Memory Benefits

7.4

• Virtual Memory frees the programmer from many issues

• Large programs can run in smaller systems

• It doesn’t matter what else is running on the system, all programs start at a virtual address of zero and can access the entire address space

• Virtual memory protects different processes from each other

Page 9: Ch7d- 2 EE/CS/CPE 3760 - Computer Organization  Seattle Pacific University Individual Space Every process wants its own space Ideally, it would like

Ch7d- 9EE/CS/CPE 3760 - Computer OrganizationSeattle Pacific University

Evidence of Virtual Memory at Work

7.4

• Thrashing• If a program is just too big, it will constantly page fault

to read in new pages (and throw out ones it needs)

• Paging Out• If a program has been sitting idle for a long time, it is

likely that it will be completely paged out to disk• When you return to the program, it will start out

slow as it pages all of the memory back in

• Loading• Bringing in a new program may require writing pages

for an old one out to disk