4 Memory Management Where in memory is executing process? How do we allow multiple processes to share main memory?What’s an address and how is one interpreted?
5 Background: Computer Architecture Program executable on diskOS loads program into memoryCPU fetches instructions & data from memory while executing program
6 Memory Management: Terminology Segment: chunk of memory assigned to processPhysical address: real address in memoryVirtual address: address relative to start of process’s address space
7 Where Do Addresses Come From? Instruction & data addressesCompile-time:Exact physical location in memory starting from fixed position kLoad-time:OS determines process’s starting position, fixes up addressesExecution time:OS can place address anywhere in physical memory
8 UniprogrammingOnly one program at a time ) simplifies memory managementOS gets fixed region of memory (e.g., highest)One process at a timeLoad at address 0Executes in contiguous memoryCompiler generates physical addressesMax address = memory size – OS sizeOS protected from process by checking addresses
9 Example: Uniprogramming Simple – but no overlap of I/O, computation
10 Multiprogramming Requirements TransparencyNo process aware memory is sharedProcess has no constraints on physical memorySafetyProcesses cannot corrupt each otherOr the OSEfficiencyPerformance not degraded due to sharing
11 Relocation Put OS in high memory Process starts at 0 Max addr = memory size – OS sizeLoad process by allocating contiguous segment for processSmallest addr = base, largest = limit
12 Static RelocationAt load time, OS adjusts addresses in process to reflect position in memoryOS cannot move process after relocation
13 Dynamic RelocationHardware adds relocation register (base) to virtual address to get physical addressHardware compares address with limit register (addr must be less than base)Test fails ) trap
14 Relocation, Pros & Cons Advantages Disadvantages OS can easily move process during executionOS can allow process to grow over timeSimple, fast hardwareTwo special registers, add, & compareDisadvantagesSlows everything (add on every reference)Can’t share memory between processes“Text” sectionProcess limited to physical memory sizeDegree of multiprogramming limitedAll memory of active processes must fit in memoryComplicates memory management
15 Relocation, Properties TransparencyProcesses largely unaware of sharingSafetyEach memory reference checkedEfficiencyMemory checks fast if done in hardwareBut: if process grows, may have to be moved (SLOW)
16 Memory AllocationAs processes enter system, grow & terminate, OS must track available and in-use memoryCan leave holesOS must decide where to put new processes
17 Memory Allocation Policies First-fit:Use first hole in which process fitsBest-fit:Use smallest hole that’s large enoughWorst-fit:Use largest holeWhat’s best?
18 FragmentationFragmentation = % memory unavailable for allocation, but not in useExternal fragmentation:Caused by repeated unloading & loadingMany small holesNo contiguous chunk large enoughInternal fragmentation:Space inside process allocationsUnavailable to other processes
19 Compaction Can make space available by compacting process space Eliminate holes
20 Compaction Example Issues Amount of memory moved Size of created block Other choices?
21 Alternative: Swapping Swapping = copy process to disk, release all memoryWhen process active, must reloadStatic relocation: same position(!)Dynamic relocation: okCompaction simplified if swapping supportedBut not supported in modern OS’sInteraction with scheduling?
22 Summary Processes must reside in memory to execute Generally use virtual addressesTranslated to physical addresses before accessing memorySegmentation:Allows processes to share memoryExpensive to grow over timeSwapping:Total being used by all can exceed main memoryIncreases context switch time