Overview Operating Systems I Management Provie Services processes files Manage Devices processor memory isk Simple Management One process in memory, using it all each program nees I/O rivers until 96 I/O rivers Simple Management Small, protecte, rivers D Mono-programming -- No multiprocessing ROM Device Drivers ROM User Prog User Prog User Prog User Prog Multiprocessing w/fixe Partitions Partion Partion Partion Partion (a) 9k 5k k k Unequal queues Simple! Partion Partion Partion Partion (b) Waste large partition Skip small jobs Aress Bining Compile Time maybe absolute bining (.com) Link Time ynamic vs. static libraries Loa Time relocatable coe Run Time relocatable memory segments overlays paging Source Object Loa Moule Binary Compile Link Loa Run
vs Aresses Compile-Time + Loa Time aresses same Run time aresses ifferent Relocatable Coe Allow logical aresses Protect other processes Aress 6 Relocation Register + MMU User goes from to max Aress 6 goes from R+ to R+max Limit Reg < error no yes Reloc Reg + aress Aresses must be contiguous! Object Moule Information require to loa into memory Heaer Information Machine Coe Initialize Data Symbol Table Relocation Information (see sample) Loaing an Object Resolve references of object moule On Disk Heaer Executable Coe Initialize Data In Executable Coe Initialize Data Uninitialize Data Variable-Size Partitions Iea: want to remove waste memory that is not neee in each partition Definition: Hole - a block of available memory scattere throughout memory New process allocate memory from hole large enough to fit it process 5 8 one Variable-Size Partitions process 5 keeps track of: allocate partitions process 5 process 9 process 9 9 arrv arrv 5 one free partitions (holes) queues! process
Variable-Size Partitions Variable-Size Partitions Given a list of free holes: k k k 5k 5k k k k 5k How o you satisfy a request of sizes? k, k, k 5k Requests: k, k, k First-fit: allocate first hole that is big enough Best-fit: allocate smallest hole that is big enough Worst-fit: allocate largest hole (say, k) Variable-Size Partitions First-fit: might not search the entire list Best-fit: must search the entire list Worst-fit: must search the entire list First-fit an Best-ft better than Worst-fit in terms of spee an storage utilization Request? What if a request for aitional memory? process malloc(k)? Internal Fragmentation Have some empty space for each processes Allocate to A A stack A ata A program Room for growth Internal Fragmentation - allocate memory may be slightly larger than requeste memory an not being use. External Fragmentation External Fragmentation - total memory space exists to satisfy request but it is not contiguous 5k Process 9? process 5k k
Analysis of External Fragmentation Assume: system at equilibrium process in mile if N processes, / time process, / hole ==> / N holes! Fifty-percent Rule Funamental: ajacent holes combine ajacent processes not combine 5k Compaction Shuffle memory contents to place all free memory together in one large block Only if relocation ynamic! Same I/O DMA problem Process 9 process 5k 9k 5k k (a) process (b) process Review What is a relocation register? What is external fragmentation? How to fix? Given fixe partitions. List three ways to hanle a job that requests too much memory. Cost of Compaction Compaction of vs. Swap (Disk) process process 5k process process 9k 5k k Disk much slower! Solution? Want to minimize external fragmentation Large Blocks But internal fagmentation! Traeoff Sacrifice some internal fragmentation for reuce external fragmentation Paging Paging aress space of a process can be noncontiguous; process is allocate memory wherever latter is available Divie memory into fixe-size blocks size is a power of, between 5 an 89 bytes calle Frames Divie logical memory into bocks of same size calle Pages
Paging Aress generate by ivie into: Page number (p) - inex to page table page table contains base aress of each page in memory (frame) Page offset () - offset into page/frame p f page table f memory Page size bytes Page Paging Example size bytes (8 pages) Page Page Page 5 6 Page Page Page Page Page Page Page Page Paging Example Offset Page Frame aress space m page size n page offset m-n Paging Harware page number p m-n page offset note: not losing any bytes! n phsical memory m bytes Paging Example Consier: memory = 8 bytes aress space = 8 frames How many bits in an aress? How many bits for page number? How many bits for page offset? Can a logical aress space have only pages? How big woul the page table be? Page Page Process B Page Page Process A Example page number p page offset m-n= n= 5 6 b= Page A Page B Page A Page B 5
Avantages Paging Traeoffs no external fragmentation (no compaction) relocation (now pages, before were processes) Disavantages internal fragmentation consier: 8 byte pages,,66 byte proc 5 pages + 86 bytes = 96 bytes avg: / page per process small pages! overhea page table / process (context switch + space) lookup (especially if page to isk) Implementation of Page table kept in registers Fast! Only goo when number of frames is small Expensive! Registers Disk Implementation of Page table kept in main memory Base Register (PTBR) Page Page Length PTBR Two memory accesses per ata/inst access. Solution? Associative Registers Page Page logical aress p Associative Registers page frame number number miss associative registers hit f page table f aress -% mem time memory Associative Register Performance Hit Ratio - percentage of times that a page number is foun in associative registers Effective access time = hit ratio x hit time + miss ratio x miss time hit time = reg time + mem time miss time = reg time + mem time * Example: 8% hit ratio, reg time = nanosec, mem time = nanosec.8 * +. * = nanosecons Protection Protection bits with each frame Store in page table Expan to more perms Page Page Page v v v i Protection Bit Page Page Page 6
Large Aress Spaces Typical logical aress spaces: Gbytes => aress bits (-byte aress) Typical page size: Kbytes = bits Page table may have: / = = million entries Each entry bytes => MB per process! Do not want that all in Solution? Page the page table Multilevel paging page number p p Page Multilevel Paging page offset Outer Page Table Multilevel Paging Translation Multilevel Paging Performance page number p p page offset p outer page table p inner page table esire page memory access if miss Effective access time? 9% hit rate.8 * +. * = 6 nanosecons Inverte Page table maps to aresses pi p search pi p i i View Paging lost users view of memory Nee logical memory units that grow an contract ex: stack, share library subroutine main stack Still nee page per process --> backing store accesses longer! (search + swap) Solution? Segmentation! symbol table
Segmentation Segmentation aress: <segment, offset> Segment table - maps two-imensional user efine aress into one-imensional aress base - starting location limit - length of segment Harware support Segment Table Base Register Segment Table Length Register logical aress s limit base < error no yes + aress main stack memory Management Outline Basic Fixe Partitions Variable Partitions Paging Basic Enhance Specific WinNT Linux Virtual Management in WinNT bit aressess ( = GB aress space) Upper GB share by all processes (kernel moe) Lower GB privater per process Page size is KB (, so offset is bits) Multilevel paging ( levels) bits for outer page table (page irectory) bits for inner page table bits for offset Management in WinNT Each page-table entry has bits only neee for aress translation bits left-over Characteristics Access: rea only, rea-write States: vali, zeroe, free Inverte page table points to page table entries list of free frames Management in Linux Page size: Alpha AXP ha 8 Kbyte page Intel x86 has Kbyte page Multilevel paging ( levels) Even though harware support on x86! 8
Management in Linux Buy-heap Buy-blocks are combine to larger block Linke list of free blocks at each size If not small enough, broken own 6 KB 8 KB 8 KB 8 KB KB KB 9