SMD149 - Operating Systems - Memory Roland Parviainen November 8, 2005 1/57 Outline Overview Mostly historical management Paging 2/57
Overview 3/57 Memory hierarchy Memory divided into tiers Main memory Relatively expensive Relatively small capacity High-performance Secondary storage Cheap Large capacity Slow Main memory requires careful management 4/57
5/57 Management Memory manager When to load, try to anticipate, what to replace Where to place things in memory? Strategies Fetch Strategies - on-demand and anticipatory Placement Strategies Replacement Strategies History From single user systems to modern segmentation/paging systems 6/57
Evolution of memory organizations 7/57 Single user contiguous memory allocation 8/57
Overlays 9/57 Protection in single user os 10 /57
Processor utilization 11 /57 Fixed partition multiprogramming 12 /57
Memory waste 13 /57 Relocatable translation and loading 14 /57
Memory protection 15 /57 Internal fragmentation 16 /57
Variable partioning 17 /57 Memory holes 18 /57
Coalescing 19 /57 Compaction 20 /57
Memory placement: First fit 21 /57 Best fit 22 /57
Worst fit 23 /57 Single process swapping 24 /57
Create the illusion of larger memory Increase the degree of multiprogramming 25 /57 Evolution of memory organizations 26 /57
Address spaces Physical, real, main memory addresses Virtual addresses Translated by the MMU (memory managemet unit) Dynamic Address Translation V: Virtual Address Space R: Real Address Space V much larger than R Two level storage: main memory and secondary storage 27 /57 Two level storage 28 /57
29 /57 Block mapping Dynamic address translation must maintain address translation maps Can not contain entries for every address in V Mapping information should be a fraction of main memory Blocks Tradeoff in size Fixed size blocks: paging Variable size blocks: segmentation Ordered pairs: v = (b, d) Have to be fast 30 /57
Block mapping 31 /57 Paging Pages: fixed size blocks Page frames: blocks in main memory Page table contains mappings from page numbers to page frame numbers v = (p, d) r = ps*p + d n bits in address: p: n - m bits, d: m bits Concatenation, not addition, can be used Page table stores Page Table Entries (PTEs) 32 /57
33 /57 Page table entry 34 /57
Direct mapping One entry in page table for each page in this process virtual memory space, V Any entry can be directly accessed Like accessing an array Page table often in main memory One extra memory access - half the speed? High speed cache memory? 35 /57 Direct mapping 36 /57
Associative mapping Using content addressed associative mapping Fast and expensive All entries search simultaneously Not used 37 /57 Associative mapping 38 /57
Direct/Associative mapping Combination of Direct and Associative Mapping Smaller associative memory: translation lookaside buffer (TLB) Store small number of often used PTEs Utilizes locality TLB hit: entry is in TLB TLB miss: entry is not in TLB, fetch from page table 64-128 TLB entries can achieve more than 90% of AM performance 39 /57 Direct/Associative mapping 40 /57
Multilevel page tables 32 bit virtual address space, 4KB pages: 2 20 entries for each process 32 bit/entry: 4MB per process Most memory is not used: table fragmentation Multilevel (hierarchical) page tables For two levels: v = (p, t, d) Can reduce page table fragmentation by 99% Overhead: one more memory access per level Relies on high TLB hit ratios 41 /57 Multilevel page tables 42 /57
Inverted page tables Some applications use most of 32bit address space 64bit systems need even more memory for page tables Inverted Page Tables stores one PTE for each page frame Memory needed: proportional to physical memory size, not virtual address space Hash functions to map virtual address to PTEs Collisions handled by chaining Collisions can be reduced by using a hash anchor table 43 /57 Inverted page tables 44 /57
IPT with hash anchor table 45 /57 Sharing in a paging system Allow more than one process reference the same page frame Only nonmodifiable data can be shared Copy-on-write Read-only pages Exception on write - make copy now 46 /57
Sharing in a paging system 47 /57 Variable size blocks: segments No internal fragmentation Can have large external fragmentation 48 /57
49 /57 50 /57
51 /57 /paging system Combination of segmentation and paging Segments occupy one or more pages A complete segment need not be in main memory v = (s, p, d) 52 /57
/paging system 53 /57 54 /57
Protection 55 /57 56 /57
http://www.sm.luth.se/csee/courses/smd/149/ No lecture on monday, 14 november. Next: management 57 /57