Operating Systems Unit 7: – Virtual Memory organization Operating Systems
COP Operating Systems2 Evolution of memory organization
COP Operating Systems3 Virtual Memory concept Solves problem of limited memory space –Creates illusion of more memory than exists Creates 2 types of addresses Virtual addresses –Referenced by processes Physical addresses –Describes locations in main memory Memory management unit (MMU) Dynamic address translation Translates virtual addresses to physical address
COP Operating Systems4 Two-level Storage backing store: –maintained on hard drive –contains complete virtual memory real memory: –portion of virtual memory that is currently in use Process can only access real memory –Management of mapping is essential
COP Operating Systems5 Two-level Storage
COP Operating Systems6 Address Translation Mapping virtual addresses to real addresses need address translation map per process Address translation maps –Indicate which regions of a process’s virtual address space are currently in main memory and where they are located
COP Operating Systems7 Mapping based on block
COP Operating Systems8 address translation map is table with –block number –actual location of block in memory typical implementation –block number is offset from table origin –table entries contain block location in memory Concept: block map table
COP Operating Systems9 structure of virtual address: b is the block number in virtual memory d is the displacement from the start of block b at which the referenced item is located Concept: virtual address
COP Operating Systems10 Block Mapping Process
COP Operating Systems11 Blocks ? Pages –Blocks are fixed size –Technique is called paging Segments –Blocks maybe of different size –Technique is called segmentation
COP Operating Systems12 Paging Paging uses fixed-size block mapping: –Virtual address in paging system: v = (p, d) p is the number of the page in virtual memory on which the referenced item resides d is the displacement from the start of page p at which the referenced item is located
COP Operating Systems13 Page Frame: page in real memory Fixed-size block of main memory Aligned with page size multiple
COP Operating Systems14 Page to Frame correspondence
COP Operating Systems15 Page Table Entry (PTE) maps virtual page p to page frame p´ –Contains bit to indicate if page is in real memory –Term: Page Fault access to memory location on page that is not in real memory
COP Operating Systems16 Page Address Translation Direct Mapping Associative Memory Translation Lookaside Buffer Concerns: –memory access speed –size of page table
COP Operating Systems17 Address Translation by Direct Mapping
COP Operating Systems18 Page Table size address size: 4 bytes bytes virtual memory amount: 4GB Page size: 4k pages in virtual memory PTE size: 8 bytes bytes maximum page table size: 8MB Page table will not fit into processor cache
COP Operating Systems19 Page Table size address size: 8 bytes bytes virtual memory amount Page size: 4k pages in virtual memory PTE size: 16 bytes bytes maximum page table size Page table will not fit into processor cache
COP Operating Systems20 Address Translation by Associative Mapping
COP Operating Systems21 Combination: Direct/Associative Mapping Experience shows: TLB size of 64 or 128 Can reach 90% of associative mapping performance
COP Operating Systems22 Page Address Translation: concerns memory access speed –consider cache speed size of page table –32 bit vs. 64 bit use of memory space –locality of memory references –sparseness advanced approaches –multi-level page tables –inverted page table
COP Operating Systems23 Multilevel Page Tables Hierarchy of page tables –Each level containing a table that stores pointers to tables in the level below –Bottom-most level comprised of tables containing address translations Can reduce memory overhead compared to direct-mapping system –page table does not have to be contiguous
COP Operating Systems24 Multilevel Page Tables
COP Operating Systems25 Inverted Page Tables –One inverted page table stores one PTE in memory for each page frame in the system –Inverted relative to traditional page tables –Uses hash functions to map virtual page to inverted page table entry
COP Operating Systems26 Inverted Page Tables
COP Operating Systems27 Inverted Page Tables Hash collisions increase memory accesses Collisions can be reduced by increasing the range of the hash function –Cannot increase the size of the inverted page table because it must store exactly one PTE for each page frame trick: hash anchor table – one more level of indirection
COP Operating Systems28 Inverted Page Tables with hash anchor table
COP Operating Systems29 Also: Page Sharing programs may share common pages –data and/or instructions pages marked as sharable or nonsharable
COP Operating Systems30 Segmentation based on variable-size segments –contiguous block of process’ address space data, text, stack process can run if current segment(s) is in main memory
COP Operating Systems31 Segmentation
COP Operating Systems32 Segmentation virtual memory address v = (s, d) –s is the segment number in virtual memory –d is the displacement within segment s at which the referenced item is located
COP Operating Systems33 Address Translation by Direct Mapping
COP Operating Systems34 Segment map table entry maps segment s to real memory address s´ –has resident bit to indicate segment is in memory If so, it stores the segment base address Otherwise, it stores the location of the segment on secondary storage –has segment length field useful to protect memory outside of segment
COP Operating Systems35 Segment map table entry
COP Operating Systems36 Segment map table entry: protection
COP Operating Systems37 Also: Segment Sharing Caution: segment protection
COP Operating Systems38 Combination: Segmentation/Paging Systems Segments occupy one or more pages All pages of segment need not be in main memory at once Pages contiguous in virtual memory need not be contiguous in main memory
COP Operating Systems39 –s is segment number –p is page number within segment –d is displacement within page at which desired item located Virtual memory address
COP Operating Systems40 Address Translation
COP Operating Systems41 System-wide Table Structure
COP Operating Systems42 Sharing and Protection Page replacement requires updates to several tables Protection checking is complex
COP Operating Systems43 Agenda for next week: next week: –Chapter 11: Virtual Memory Management –Read ahead !