DOC PREVIEW
CMU CS 15410 - Lecture

This preview shows page 1-2-3-22-23-24-45-46-47 out of 47 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 47 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 47 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 47 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 47 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 47 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 47 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 47 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 47 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 47 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 47 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

15-410, S’04- 1 -Virtual Memory #2Mar. 1, 2004Dave EckhardtDave EckhardtBruce MaggsBruce MaggsL19_VM215-410“...The only way to win is not to play...”15-410, S’04- 2 -SynchronizationCheckpoint 1Checkpoint 1Wednesday 23:59Final Exam list postedFinal Exam list postedYou must notify us of conflicts in a timely fashion15-410, S’04- 3 -Last TimeMapping problem: logical vs. physical addressesMapping problem: logical vs. physical addressesContiguous memory mapping (base, limit)Contiguous memory mapping (base, limit)Swapping – taking turns in memorySwapping – taking turns in memoryPagingPagingArray mapping page numbers to frame numbersObservation: typical table is sparsely occupiedResponse: some sparse data structure (e.g., 2-level array)TLB – cache of virtual TLB – cache of virtual ⇒⇒ physical mappings physical mappingsSoftware-loaded TLBSoftware-loaded TLB15-410, S’04- 4 -SwappingMultiple user processesMultiple user processesSum of memory demands > system memoryGoal: Allow each process 100% of system memoryTake turnsTake turnsTemporarily evict process(es) to disk“Swap daemon” shuffles process in & outCan take seconds per processCreates external fragmentation problem15-410, S’04- 5 -External Fragmentation (“Holes”)Process 3Process 4Process 1OS KernelProcess 2Process 3Process 4Process 1OS KernelProcess 215-410, S’04- 6 -Benefits of PagingProcess growth problemProcess growth problemAny process can use any free frame for any purposeFragmentation compaction problemFragmentation compaction problemProcess doesn't need to be contiguousLong delay to swap a whole processLong delay to swap a whole processSwap part of the process instead!15-410, S’04- 7 -Partial ResidenceP0 code 0OS Kernel[free]P0 data 0P1 data 0P1 stack 0P0 stack 0P1 data 1[free]P0 code 0P0 code 1P0 data 0P0 stack 0P1 code 0P1 data 0P1 data 1P1 stack 015-410, S’04- 8 -Page Table Entry (PTE) flagsProtection bits – set by OSProtection bits – set by OSRead/write/executeValid/Present bit – set by OSValid/Present bit – set by OSFrame pointer is valid, no need to faultDirty bitDirty bitHardware sets 0⇒1 when data stored into pageOS sets 1⇒0 when page has been written to diskReference bitReference bitHardware sets 0⇒1 on any data access to pageOS uses for page eviction (below)15-410, S’04- 9 -OutlinePartial memory residence (demand paging) in actionPartial memory residence (demand paging) in actionThe task of the page fault handlerThe task of the page fault handlerBig speed hacksBig speed hacksSharing memory regions & filesSharing memory regions & filesPage replacement policiesPage replacement policies15-410, S’04- 10 -Partial Memory ResidenceError-handling code not used by every runError-handling code not used by every runNo need for it to occupy memory for entire duration...Tables may be allocated larger than usedTables may be allocated larger than usedplayer players[MAX_PLAYERS];Can run Can run veryvery large programs large programsMuch larger than physical memoryAs long as “active” footprint fits in RAMSwapping can't do thisPrograms can launch fasterPrograms can launch fasterNeedn't load whole program before running15-410, S’04- 11 -Demand PagingUse RAM frames as a cache for the set of all pagesUse RAM frames as a cache for the set of all pagesPage tables indicate which pages are residentPage tables indicate which pages are residentNon-resident pages have “present=0” in page table entryMemory access referring to page generates page faultHardware invokes page fault exception handler15-410, S’04- 12 -Page fault - Why?Address is invalid/illegal – deliver Address is invalid/illegal – deliver software exceptionsoftware exceptionUnix – SIGSEGVMach – deliver message to thread's exception port15-410 – kill threadProcess is growing stack – give it a new frameProcess is growing stack – give it a new frame“Cache misses” - fetch from disk“Cache misses” - fetch from diskWhere?15-410, S’04- 13 -Satisfying Page FaultscodedatabssstackFilesystemPaging SpaceFree-frame pool15-410, S’04- 14 -Page fault story - 1Process issues memory referenceProcess issues memory referenceTLB: miss (right?)PT: “ not present”TrapTrap to OS kernel! to OS kernel!Dump trap frameTransfer via “ page fault” interrupt descriptorRun trap handler15-410, S’04- 15 -Page fault story – 2Classify fault address: legal/illegalClassify fault address: legal/illegalCode/rodata region of executable?Code/rodata region of executable?Determine which sector of executable fileLaunch read() into a blank framePreviously resident, paged outPreviously resident, paged out“ somewhere on the paging partition”Queue disk read into a blank frameFirst use of bss/stack pageFirst use of bss/stack pageAllocate a zero frame, insert into PT15-410, S’04- 16 -Page fault story – 3Put process to sleep (for most cases)Put process to sleep (for most cases)Switch to running anotherHandle I/O-complete interruptHandle I/O-complete interruptFill in PTE (present = 1)Mark process runnableRestore registers, switch page tableRestore registers, switch page tableFaulting instruction re-started transparentlySingle instruction may fault more than once!15-410, S’04- 17 -Memory Regions vs. Page TablesWhat's a poor page fault handler to do?What's a poor page fault handler to do?Kill process? Copy page, mark read-write? Fetch page from file? Which? Where?Page Table not a good data structurePage Table not a good data structure Format defined by hardware Per-page nature is repetitive Not enough bits to encode OS metadataDisk sector address can be > 32 bits15-410, S’04- 18 -Dual-view Memory ModelLogicalLogical Process memory is a list of regions “ Holes” between regions are illegal addresses Per-region methodsfault(), evict(), unmap()PhysicalPhysical Process memory is a list of pages Faults delegated to per-region methods Many “ invalid” pages can be made validBut sometimes a region fault handler returns “ error”»Handle as with “ hole” case above15-410, S’04- 19 -Page-fault story (for real)Examine fault addressExamine fault addressLook up: address Look up: address ⇒⇒ region regionregion->fault(addr, access_mode)region->fault(addr, access_mode) Quickly fix up problem Or put process to sleep, run scheduler15-410, S’04- 20 -Demand


View Full Document

CMU CS 15410 - Lecture

Download Lecture
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?