18 Pages

ECE344-Lecture17-Memory Management

Course: ECE 344, Fall 2011
School: University of Toronto
Rating:
 
 
 
 
 

Word Count: 1150

Document Preview

17: Lecture Memory Management David Lie ECE344 University of Toronto 1 Overview The TLB Miss Handler: Page Fault Handler Swap Handler Managing the Swap Area Paging issues and Performance Putting it all together. VM and OS events: Process Creation, Copy-on-Write Process Termination Context Switching Memory mapped files and shared memory Modern Paging hardware: Superpages ECE344: Operating Systems 2...

Register Now

Unformatted Document Excerpt

Coursehero >> Canada >> University of Toronto >> ECE 344

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
17: Lecture Memory Management David Lie ECE344 University of Toronto 1 Overview The TLB Miss Handler: Page Fault Handler Swap Handler Managing the Swap Area Paging issues and Performance Putting it all together. VM and OS events: Process Creation, Copy-on-Write Process Termination Context Switching Memory mapped files and shared memory Modern Paging hardware: Superpages ECE344: Operating Systems 2 Putting it all together What does virtual memory system do during key OS events? Process Creation (fork) Process Execution (execv) Process Termination (exit) Context switch ECE344: Operating Systems 3 Putting it all together (fork) Fork creates a new address space: 1. Copy Parents address space structure All regions will have the same location, sizes and permissions 2. Create a new page table Page table is a copy of the parents page table This means virtual pages in child address space map to the same physical frames as parent Is there a problem with this? ECE344: Operating Systems 4 Copy-on-write Problem: If child/parent modifies a page, then the other will see the modification since both are mapping the same physical page. No isolation between child and parent. Solution: copy-on-write (COW) When copying an address space, mark all virtual mappings in both page tables as read-only (even if region is writeable) Pages that should be writeable but have been made read-only are called COW pages. When one process modifies a COW page, this will cause a TLB fault with a read-only type. ECE344: Operating Systems 5 TLB Faults on COW pages When the TLB fault handler detects a fault on a COW page: 1. Allocate a new physical page 2. Copy the contents of the original page to the new page 3. Make page table entry in current address space point to the new page 4. Remove current address space from reference of original page in coremap and add current address space as reference to the new page. 5. Make page table entry in current address space writeable and write to TLB 6. Optional: Check the number of references on the original page, if it is the last reference (only one), then make the corresponding page table entry writeable as well. Saves an extra fault later on. ECE344: Operating Systems 6 Putting it all together (execv) Process start (i.e. execv) 1. Destroy old address space structure Includes traversing page table and freeing all page frames mapped by the page table Free all swap regions used by the process Free space used by address space structure 2. Create new address space structure Set size text and code regions according to executable Set size of heap and stack according to defaults Initialize a new page table with all invalid entries ECE344: Operating Systems 7 Putting it all together (exit, context switch) Process Termination (exit, process crash): Destroy old address space. The same as destroying old address space in execv. Context switch: Have to change the currently active page table Hardware managed TLB(x86): Change the hardware register that points to current page table. This automatically causes a TLB flush. Software manage TLB(os161): Change current address space and page table Flush TLB ECE344: Operating Systems 8 System Calls for Sharing Memory mmap(), munmap() system calls allow process to control memory mappings Allows accessing a file using a memory interface Threads read and write files using load/store rather than read/write! These files are called memory-mapped files ECE344: Operating Systems 9 Memory-Mapped Files OS maps file contiguously within address space Say, virtual address file_base stores start of file Then, file_base + N refers to offset N in file loading Allows file data in memory on demand (demand paging) OS reads a page frame from file when invalid (but mapped) page is accessed OS writes a page frame to file when dirty page is evicted Essentially, file is used for backing store instead of swap area When threads map the same file, they can share file data via memory ECE344: Operating Systems 10 Example of Memory-Mapped File Any part of the file can be mapped Page 2^20 - 1 Stack Mapped file Heap Data Page 1 Page 0 ECE344: Operating Systems Text Virtual address space 11 Page Sharing Two (or more) processes can share memory by mapping a page to the same frame in their page tables Implemented using the mmap system call Typical mmap arguments: Address of mapped region Size of mapped region Protection flags (writeable, readable, executable) File Descriptor Two processes share memory by mapping the same file into their address spaces: The same physical frames are used to back the virtual pages in both processes ECE344: Operating Systems 12 Page Sharing Physical memory Stack (rw) Thread 1 address space Thread 1 page table Data (rw) Text (rx) Shared text pages Thread 2 address space Thread 2 page table ECE344: Operating Systems 13 Motivation for Page Sharing Typically, programs run in their own address space because it provides protection However, sometimes programs need to share memory Web server parent and children threads may wish to only a few pages (i.e. communication buffer) Sharing entire address space provides no protection No sharing requires copying data through disk, i.e., slow communication If more than one instance of a program is running, then the text (code) segments can be shared: Code segments are read-only anyways so its safe to map the same physical frame into multiple address spaces. ECE344: Operating Systems 14 Page Sharing Page table entries can have different protection E.g., one process has read, another write enabled, allows certain types of broadcast communication Shared memory can be mapped at same or different virtual address in each address space Must update all page table entries when frame is evicted Use coremap to find all mappings ECE344: Operating Systems 15 Shared Libraries Shared libraries are another form of page sharing: Libraries are loaded via a the mmap system call Multiple processes all map the library into their address space: Library is only loaded once into memory, but shared among many unrelated processes -- saves physical memory. Example: many programs use libc (common functions like printf, system calls, etc) Libc is only loaded at one physical location Can be mapped into any location various processes ECE344: Operating Systems 16 Modern OS and Hardware Modern computer systems have much larger memories available to them: Not unreasonable to have 8-16GB in a desktop PC Application use 64-bit address spaces to take advantage of larger memory. Memory usage is higher. Memory pressure puts more pressure on TLB use Applications that use more memory use more TLB entries TLB misses can become a performance bottleneck Higher overhead due to page table size: Program that allocates 1MB of memory needs 25 page table entries ECE344: Operating Systems 17 Superpages Modern processors support several pages sizes to accommodate programs that use more memory: OS can configure processor to use larger pages, known as superpages Larger pages can waste memory due to internal fragmentation so this the optimal choice is application dependent. Example: x86 processors support standard 4KB pages as well as 2MB, 4MB and 1GB pages under various configurations ECE344: Operating Systems 18
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

University of Toronto - ECE - 344
Lecture 18: Page Replacement AlgorithmsDavid LieECE344University of Toronto1OverviewIntroductionPage replacement algorithmsLocal vs. global page replacementPage bufferingThrashingECE344: Operating Systems2Introduction We have seen that OS al
University of Toronto - ECE - 344
Lecture 19: Page Replacement AlgorithmsDavid LieECE344University of Toronto1OverviewIntroductionPage replacement algorithmsLocal vs. global page replacementPage bufferingThrashingECE344: Operating Systems2Least Recently Used (LRU) A refineme
University of Toronto - ECE - 344
Lecture 20: SchedulingDavid LieECE344University of Toronto1OverviewPurpose of schedulingScheduling AlgorithmsMultiprocessor IssuesModern SystemsECE344: Operating Systems2Purpose of Scheduling OS scheduler decides when a thread should be run
University of Toronto - ECE - 344
Lecture 21: SchedulingDavid LieECE344University of Toronto1OverviewPurpose of schedulingScheduling AlgorithmsMultiprocessor IssuesModern SystemsECE344: Operating Systems2Static Priority Scheduling Each thread is assigned a priority when it is
University of Toronto - ECE - 344
Lecture 22: File SystemsDavid LieECE344University of Toronto1Outline File Systems Overview of file system Disk Basics File system design Consistency and crash recovery Sharing files Unix file system Disks Disk scheduling algorithms Redundan
University of Toronto - ECE - 344
Lecture 23: File SystemsDavid LieECE344University of Toronto1Outline File Systems Overview of file system Disk Basics File system design Consistency and crash recovery Sharing files Unix file system Disks Disk scheduling algorithms Redundan
University of Toronto - ECE - 344
Lecture 24: File SystemsDavid LieECE344University of Toronto1Outline File Systems Overview of file system Disk Basics File system design Consistency and crash recovery Sharing files Unix file system Disks Disk scheduling algorithms Redundan
University of Toronto - ECE - 344
Lecture 25: File SystemsDavid LieECE344University of Toronto1Outline File Systems Overview of file system Disk Basics File system design Consistency and crash recovery Sharing files Unix file system Disks Disk scheduling algorithms Redundan
University of Toronto - ECE - 344
Lecture 26: VirtualizationDavid LieECE344University of Toronto1System Virtualization Operating systems virtualize the CPU and devices so that youcan run multiple, independent processes: Each process is isolated, it believes it has exclusive access
University of Toronto - ECE - 344
Lecture 27: VirtualizationDavid LieECE344University of Toronto1Memory Virtualization Another challenge with VMM implementation is virtualizing theMMU: VMM needs to use MMU to isolate different guest OSs fromeach other Guest OSs need to use MMU t
University of Toronto - ECE - 344
Lab 0: OverviewDavid LieECE344University of Toronto1Lab Goals Get familiar with OS161 Learn to build and install a kernel and test environment Get familiar with tools: Cscope: source code navigation Subversion: versioning and collaboration GDB:
University of Toronto - ECE - 344
Lab 1: OverviewDavid LieECE344University of Toronto1Overview Review 3 synchronization types: Locks Semaphores Conditional Variables What is deadlock? Overview of synch.h Tips on DebuggingECE344: Operating Systems2
University of Toronto - ECE - 344
Lab 2: OverviewDavid LieECE344University of Toronto1Overview Some notes: How to use splhigh/splx Explanation of system callsECE344: Operating Systems2Splhigh/Splx These disable interrupts Think of this as a global lock for all threads. Everyt
University of Toronto - ECE - 344
Lab 2.1: OverviewDavid LieECE344University of Toronto1Function call flowsys_execvsys_forkthread_forkmd_forkentrymd_usermodemips_usermodeECE344: Operating Systems2Md_usermode vs md_forkentrySets up processor for going back to userspace for a
University of Toronto - ECE - 344
Lab 3.0: OverviewDavid LieECE344University of Toronto1Primer Look at kern/arch/mips/include/tlb.h: Description of the TLB interface0xc000000KSEG0 Understand memory layout of MIPS0x8000000 Look at kern/arch/mips/include/vm.h KUSEG: user progra
University of Toronto - ECE - 344
Lab 3.1: OverviewDavid LieECE344University of Toronto1Tasks Major Task: Implement as_copy() so you can support fork() Minor Task Implement sbrk()ECE344: Operating Systems2Implementing as_copy() As_copy() in dumbvm just does a keep copy of the
University of Toronto - ECE - 344
Lab 3.2: OverviewDavid LieECE344University of Toronto1TasksMajor Task: Implement SwappingMinor Task Performance counters and tuningECE344: Operating Systems2Implementing SwapOverview: In your coremap allocation function, you should currently
University of Toronto - CSC - 326
CSC326 Programming Languages (Lec1)CSC326 Programming Languages (Lec 1)iCSC326 Programming Languages (Lec1)iiREVISION HISTORYNUMBERDATE1.02011-09DESCRIPTIONNAMEJZCSC326 Programming Languages (Lec1)iiiContents1Agenda12Goal13Whats
University of Toronto - CSC - 326
CSC326 Python Imperative Core (Lec2)CSC326 Python Imperative Core (Lec 2)iCSC326 Python Imperative Core (Lec2)iiREVISION HISTORYNUMBERDATE1.02011-09DESCRIPTIONNAMEJZCSC326 Python Imperative Core (Lec2)iiiContents1Agenda12Invoking Py
University of Toronto - CSC - 326
CSC326 Python SequencesiCSC326 Python SequencesCSC326 Python SequencesiiREVISION HISTORYNUMBERDATE1.02011-09DESCRIPTIONNAMEJZCSC326 Python SequencesiiiContents1Agenda12while Statement13Sequence Overview24String25Lists46Dict
University of Toronto - CSC - 326
CSC326 Array Programming ParadigmiCSC326 Array Programming ParadigmCSC326 Array Programming ParadigmiiREVISION HISTORYNUMBERDATE1.02011-09DESCRIPTIONNAMEJZCSC326 Array Programming ParadigmiiiContents1Agenda12Array Programming Language
University of Toronto - CSC - 326
CSC326 Persistent ProgrammingiCSC326 Persistent ProgrammingCSC326 Persistent ProgrammingiiREVISION HISTORYNUMBERDATE1.02011-09DESCRIPTIONNAMEJZCSC326 Persistent ProgrammingiiiContents1Agenda12Persistent Programming13File14File na
University of Toronto - CSC - 326
CSC326 Object Oriented ProgrammingiCSC326 Object Oriented ProgrammingCSC326 Object Oriented ProgrammingiiREVISION HISTORYNUMBERDATE1.02011-09DESCRIPTIONNAMEJZCSC326 Object Oriented ProgrammingiiiContents1Agenda12Classes and Objects13
University of Toronto - CSC - 326
CSC326 Meta ProgrammingiCSC326 Meta ProgrammingCSC326 Meta ProgrammingiiREVISION HISTORYNUMBERDATE1.02011-09DESCRIPTIONNAMEJZCSC326 Meta ProgrammingiiiContents1Agenda12Class Factory13Meta Class14Decorator25Misuse of Decorators
University of Toronto - CSC - 326
CSC326 Functional ProgrammingiCSC326 Functional ProgrammingCSC326 Functional ProgrammingiiREVISION HISTORYNUMBERDATE1.02011-09DESCRIPTIONNAMEJZCSC326 Functional ProgrammingiiiContents1Agenda12Eliminating if13Eliminating Sequential S
Northwestern - PHYSICS - 102
Bernard WenSept. 23, 2010BP: A False FaadeAs one of the worlds largest energy companies, (Who We Are) BP is constantlyunder public scrutiny, so it is easy for the company to advertize a false faade of socialresponsibility. Its homepage is inundated w
University of Texas - EE - 351K
EE 351K Probability, Statistics, and Random ProcessesInstructor:S.ShakkottaiHomework 1 SolutionsProblem 1and P (A B ).SPRING 2012shakkott@ece.utexas.eduWe are given that P (A) = 0.6, P (B c ) = 0.45, and P (A B ) = 0.85. Determine P (B )Solution :
University of Texas - EE - 351K
EE 351K Probability, Statistics, and Random ProcessesInstructor:S.ShakkottaiHomework 1SPRING 2012shakkott@ece.utexas.eduProblem 1and P (A B ).We are given that P (A) = 0.6, P (B c ) = 0.45, and P (A B ) = 0.85. Determine P (B )Problem 2Let A and
University of Texas - EE - 351K
EE 351K Probability, Statistics, and Random ProcessesInstructor:S. ShakkottaiHomework 2 SolutionsSPRING 2012shakkott@ece.utexas.eduProblem 1A hard disk storing information in binary form has been corrupted, so it can only be read withbit errors. Du
University of Texas - EE - 351K
EE 351K Probability, Statistics, and Random ProcessesInstructor:S. ShakkottaiHomework 2SPRING 2012shakkott@ece.utexas.eduProblem 1A hard disk storing information in binary form has been corrupted, so it can only be read withbit errors. Due to error
University of Texas - EE - 351K
EE 351K PROBABILITY & RANDOM PROCESSESInstructor: Sujay SanghaviHomework 3 SolutionFALL 2011sanghavi@mail.utexas.eduProblem 1Count the number of distinguishable ways in which you can arrange the letters in the words:(a) children(b) bookkeeperSol:
University of Texas - EE - 351K
EE 351K PROBABILITY & RANDOM PROCESSESInstructor: Sujay SanghaviHomework 3FALL 2011sanghavi@mail.utexas.eduDue: September 22th in classProblem 1Count the number of distinguishable ways in which you can arrange the letters in the words:(a) children
University of Texas - EE - 351K
EE 351K PROBABILITY & RANDOM PROCESSESInstructor: Sujay SanghaviHomework 4 SolutionFALL 2011sanghavi@mail.utexas.eduProblem 1There are n multiple-choice questions in an exam, each with 5 choices. The student knows the correctanswer to k of them, an
University of Texas - EE - 351K
EE 351K PROBABILITY & RANDOM PROCESSESInstructor: Sujay SanghaviHomework 4FALL 2011sanghavi@mail.utexas.eduDue: September 29th in classProblem 1There are n multiple-choice questions in an exam, each with 5 choices. The student knows the correctans
University of Texas - EE - 351K
EE 351K PROBABILITY & RANDOM PROCESSESInstructor: Sujay SanghaviHomework 5 SolutionFALL 2011sanghavi@mail.utexas.eduProblem 1Let Y be a random variable with probability density function (PDF) 1 + y, 1 y 0,y,0 < y 1,fY (y ) =0,otherwise.Find(
University of Texas - EE - 351K
EE 351K PROBABILITY & RANDOM PROCESSESInstructor: Sujay SanghaviHomework 5FALL 2011sanghavi@mail.utexas.eduDue: October 13th in classProblem 1Let Y be a random variable with probability density function (PDF) 1 + y, 1 y 0,y,0 < y 1,fY (y ) =0,
University of Texas - EE - 351K
EE 351K PROBABILITY & RANDOM PROCESSESInstructor: Sujay SanghaviHomework 6 SolutionFALL 2011sanghavi@mail.utexas.eduProblem 1(a) A re station is to be located at a point a along a road of length A, 0 < A < . If res willoccur at points uniformly cho
University of Texas - EE - 351K
EE 351K PROBABILITY & RANDOM PROCESSESInstructor: Sujay SanghaviHomework 6FALL 2011sanghavi@mail.utexas.eduDue: October 20th in classProblem 1(a) A re station is to be located at a point a along a road of length A, 0 < A < . If res willoccur at po
University of Texas - EE - 351K
EE 351K PROBABILITY & RANDOM PROCESSESInstructor: Sujay SanghaviHomework 7 SolutionFALL 2011sanghavi@mail.utexas.eduProblem 1Let X1 , X2 , . . . be independent random variables that are uniformly distributed over [1.1]. For each of thefollowing cas
University of Texas - EE - 351K
EE 351K PROBABILITY & RANDOM PROCESSESFALL 2011Instructor: Sujay Sanghavisanghavi@mail.utexas.eduHomework 7Due: October 27th in classFocus: Limit Theorems, MAP Rule (Section 5.1-5.4, 8.1-8.2 in Textbook)Problem 1Let X1 , X2 , . . . be independent
University of Texas - EE - 351K
EE 351K PROBABILITY & RANDOM PROCESSESInstructor: Sujay SanghaviHomework 8 SolutionFALL 2011sanghavi@mail.utexas.eduProblem 1Nefeli, a student in a probability class, takes a multiple-choice test with 10 questions and 3 choices perquestion. For eac
University of Texas - EE - 351K
EE 351K PROBABILITY & RANDOM PROCESSESFALL 2011Instructor: Sujay Sanghavisanghavi@mail.utexas.eduHomework 8Due: November 2nd, 4:00pm (dropping it to mailbox @ENS 431)Focus: Bayesian Inference (Section 8.1-8.5 in Textbook)Problem 1Nefeli, a student
University of Texas - EE - 351K
EE 351K PROBABILITY & RANDOM PROCESSESInstructor: Sujay SanghaviHomework 9 SolutionFALL 2011sanghavi@mail.utexas.eduProblem 1The parameter of an exponential random variable has to be estimated from one sample. What is the MLestimator? Is it unbiase
University of Texas - EE - 351K
EE 351K PROBABILITY & RANDOM PROCESSESInstructor: Sujay SanghaviHomework 9Focus: ML Estimation (Chapter 9.1 in Textbook)FALL 2011sanghavi@mail.utexas.eduDue: November 22th in classProblem 1The parameter of an exponential random variable has to be
University of Texas - EE - 351K
EE 351K PROBABILITY & RANDOM PROCESSESInstructor: Sujay SanghaviHomework 10 SolutionFALL 2011sanghavi@mail.utexas.eduProblem 1A radar works by transmitting a pulse, and seeing if there is an echo. Ideally, an echo means object ispresent, and no ech
University of Texas - EE - 351K
EE 351K PROBABILITY & RANDOM PROCESSESInstructor: Sujay SanghaviHomework 10Focus: Classical Statistical Inference (Chapter 9 in Textbook)FALL 2011sanghavi@mail.utexas.eduDue: December 5th @ ENS 428Problem 1A radar works by transmitting a pulse, an
University of Texas - EE - 319K
University of Texas - EE - 319K
1/11EE 319K Fall 2010 Final ExamRamesh YerraballiFull N ame(eid) :Duration: 3 hoursThis is a closed book exam; You may use your calculators; Write answers within the space (box)provided after each of the questions. There are 11 questions on the test
University of Texas - EE - 319K
1/11EE 319K Fall 2010 Final ExamRamesh YerraballiFull N ame(eid) :Duration: 3 hoursThis is a closed book exam; You may use your calculators; Write answers within the space (box)provided after each of the questions. There are 11 questions on the test
University of Texas - EE - 319K
1/11EE 319K Spring 2010 Final ExamRamesh YerraballiTThFull Name:Duration: 75 minutesThis is a closed book exam; You may use your calculators; Write answers within the spaceprovided after each of the questions. There are 7 questions on the test, rea
University of Texas - EE - 319K
1/11EE 319K Spring 2010 Final ExamRamesh YerraballiTThFull Name:Duration: 75 minutesThis is a closed book exam; You may use your calculators; Write answers within the spaceprovided after each of the questions. There are 7 questions on the test, rea
University of Texas - EE - 319K
1/11EE 319K Spring 2011 Final ExamRamesh YerraballiTThFull Name(eid):BME: Yes/NoDuration: 3 hoursThis is a closed book exam; You may use your calculators; Write answers within the space (box) providedafter each of the questions. There are 9 questi
University of Texas - EE - 319K
1/7EE 319K Fall 2010 First Mid-TermDr. Ramesh YerraballiFull Name (eid):()Duration: 75 minutesThis is a closed book exam; No calculators are allowed; Write answers within the spaceprovided after each of the questions. There are THREE questions on
University of Texas - EE - 319K
1/7EE 319K Fall 2010 First Mid-TermDr. Ramesh YerraballiFull Name (eid):()Duration: 75 minutesThis is a closed book exam; No calculators are allowed; Write answers within the spaceprovided after each of the questions. There are THREE questions on
University of Texas - EE - 319K
1 /8EE 319K Fall 2011 First Mid-TermDr. Ramesh YerraballiFull Name:Duration: 75 minutesSolutionEID:_Instructions: This is a closed book exam No calculators are allowed Write answers within the box/space provided after each of the questions. The
University of Texas - EE - 319K
1/8EE 319K Spring 2010 First Mid-TermDr. Ramesh YerraballiFull Name:Duration: 75 minutesThis is a closed book exam; No calculators are allowed; Write answers within the spaceprovided after each of the questions. There are FOUR questions on the test,
University of Texas - EE - 319K
1/8EE 319K Spring 2010 First Mid-TermDr. Ramesh YerraballiFull Name:Duration: 75 minutesThis is a closed book exam; No calculators are allowed; Write answers within the spaceprovided after each of the questions. There are FOUR questions on the test,
University of Texas - EE - 319K
1 /8EE 319K Spring 2011 First Mid-TermDr. Ramesh YerraballiFull Name:Duration: 75 minutesEID:_Instructions: This is a closed book exam No calculators are allowed Write answers within the box/space provided after each of the questions. If you need
University of Texas - EE - 319K
1 /8EE 319K Spring 2011 First Mid-TermDr. Ramesh YerraballiFull Name:Duration: 75 minutesEID:_Instructions: This is a closed book exam No calculators are allowed Write answers within the box/space provided after each of the questions. If you need
University of Texas - EE - 362K
University of Texas - EE - 362K