290 likes | 552 Views
CMT603. Lecture 8 Memory Management 1. Contents. Addressing an Address binding Logical and Physical Addressing Memory Management Unit Contiguous Addressing Fixed Partition Variable Partition Non-Contiguous Addressing Paging Segmentation. Processes are loaded in to main memory
E N D
CMT603 Lecture 8 Memory Management 1
Contents • Addressing an Address binding • Logical and Physical Addressing • Memory Management Unit • Contiguous Addressing • Fixed Partition • Variable Partition • Non-Contiguous Addressing • Paging • Segmentation
Processes are loaded in to main memory Who decides where they are placed? How do we ensure we are accessing the correct process memory? Background OS P1 P2 P3 P4
Address Binding • Can happen at Compile Time • MS-DOS .com files • Can happen at Load Time • Compiler generates a relocatable address • Can happen during Execution Time • Address binding is set at run time
Addressing • Symbolic address • Absolute address • Relocatable Address • Relocatable • Symbolic • Absolute -14 from the bytes beginning of the module -count (a variable) -74186 bytes from the beginning of the memory
Logical and Physical Addressing • Physical address is the absolute address within the main memory • This is the address the hardware address bus uses • Logical address is the address within the process relative to the start of the process • This is the address the CPU uses 0 OS Base 1000 1000 P1 1112 112 Limit 2000 3000 P2 4000 P3 4500 P4 5500
Basic MMU Addressing Hardware Trap to OS Addressing error Memory Relocation Register 1000 Logical Address 112 Physical Address 1112 CPU + >= < 1000 3000 Base Base+Limit
Contiguous Addressing- Fixed Partition • Memory broken into fixed size partitions • Each partition contains one process 0 OS 1000 P1 2000 P2 3000 P3 4000 P4 5000
Contiguous Addressing- Fixed Partition • Advantage • Simple • Disadvantage • The degree of multiprogramming is constrained. • The size of each process is bounded. • Suffers internal fragmentation • Memory that is internal to a partition but is not being used
Contiguous Addressing- Variable Partition • Processes are stored in memory in variable sized partitions 0 OS 1000 P1 3000 P2 4000 P3 4500 P4 5500
Contiguous Addressing- Variable Partition • Initially, all the memory is considered as one large block of available memory, a hole • When a process needs memory, a hole large enough for the process is allocated for it • A free memory list is used to track available memory.
Contiguous Addressing- Variable Partition P1 - 100MB OS P2 - 50MB P3 - 32MB P4 - 80MB P1 100Mb Free Memory List P5 - 32MB P2 50Mb Into which hole should P5 be put? P3 32Mb P4 80Mb
Placement Strategies • First-fit • allocate the first hole large enough • Best-fit • allocate hole with the smallest leftover space • Worst-fit • allocate the largest hole
Placement Strategies First Fit Best Fit Worst Fit OS P5 - 32MB P1 100Mb Free Memory List P5 32Mb b P3 32Mb P4 80Mb P5 32Mb a
Exercise • Assume that we have 2560k of memory available and a resident OS of 400k. Given the input queue in the table, using FCFS, how would the First-Fit algorithm place the processes in the input queue (The newly freed memory hole is appended to the end of the free memory list)?
NBExternal fragmentation 0 0 0 0 0 OS OS OS OS OS 400k 400k 400k 400k 400k P1 P1 P1 1000k 1000k 1000k 1000k P2 P4 P4 1500k 1500k 2000k 2000k 2000k 2000k P3 P3 P3 P3 2300k 2300k 2300k 2300k P5 P5 2500k 2500k 2560k 2560k 2560k 2560k 2560k Time:0 Time:0 Time:5 Time:5 Time:10
Contiguous Addressing- Variable Partition • Suffers external fragmentation • the available memory space is broken into chunks, and the largest contiguous chunk is insufficient for a request.
Reducing External Fragmentation • Coalescing – merge adjacent holes to form a single, larger hole. • Memory compaction (also referred to as garbage collection) – relocate all occupied areas of memory to one end of main memory. This leaves a single large free memory hole. • Non-contiguous memory allocation: • Paging • Segmentation
Non Contiguous Memory Allocation • A program is divided into blocks or segments that the system may place in nonadjacent slots in main memory Paging • Basic method • Break physical memory into fixed-sized blocks called frames. • Break logical memory into fixed-sized blocks called pages.
Frame number Paging Page 1 0 1 2 Page 0 3 Page 0 Page Table Page 3 Page 1 4 Page 2 5 Page 2 Page 3 6 7 8 9
Paging - Representation of Address Memory Address 0 d 1 p d 2 Page Number Displacement 3
Paging - Representation of Address • The page (frame) size is defined by the hardware. It is typically a power of 2 • If the size of a logical address space is 2n bytes, and a page size is 2m bytes. • The high-level n-m bits is used for the page number • The remaining m bits are used for the page offset. Page Number Displacement p d n-m m
Paging Hardware Physical memory Logical address Physical Address CPU p d e d Page Table p e
Example Physical memory 0 0 32 1 Page size = Frame size = 32 bytes 64 2 96 CPU 8 15 24 15 Page Table 736 23 Physical Address = (24*32) + 15 = 793 778 8 24 24 25
Exercise Physical memory 0 0 32 1 Page size = Frame size = 32 bytes 64 2 96 CPU 6 17 23 17 Page Table 736 6 23 23 Physical Address = (23*32) + 17 = 753 7 2 778 8 24 24 25
Sharing in a Paging System Process 1 page table Process 2 page table Process 3 page table
Fragmentation • Paging suffers from internal Fragmentation
Summary • Addressing an Address binding • Logical and Physical Addressing • Memory Management Unit • Contiguous Addressing • Fixed Partition • Variable Partition • Non-Contiguous Addressing • Paging • Segmentation