Memory Management Memory Manager Requirements Minimize executable memory
![Memory Management Memory Management](https://slidetodoc.com/presentation_image_h2/3d769c2c2b651a7eddf98dbdeebf74c9/image-1.jpg)
Memory Management
![Memory Manager • Requirements – Minimize executable memory access time – Maximize executable memory Memory Manager • Requirements – Minimize executable memory access time – Maximize executable memory](http://slidetodoc.com/presentation_image_h2/3d769c2c2b651a7eddf98dbdeebf74c9/image-2.jpg)
Memory Manager • Requirements – Minimize executable memory access time – Maximize executable memory size – Executable memory must be cost-effective • Today’s memory manager: – Allocates primary memory to processes – Maps process address space to primary memory – Minimizes access time using cost-effective memory configuration – May use static or dynamic techniques
![Address Space vs Primary Memory Process Address Space Mapped to object other than memory Address Space vs Primary Memory Process Address Space Mapped to object other than memory](http://slidetodoc.com/presentation_image_h2/3d769c2c2b651a7eddf98dbdeebf74c9/image-3.jpg)
Address Space vs Primary Memory Process Address Space Mapped to object other than memory Hardware Primary Memory
![Building the Address Space Source code Library code Secondary memory C Reloc Object code Building the Address Space Source code Library code Secondary memory C Reloc Object code](http://slidetodoc.com/presentation_image_h2/3d769c2c2b651a7eddf98dbdeebf74c9/image-4.jpg)
Building the Address Space Source code Library code Secondary memory C Reloc Object code Other objects Link Edit Primary memory • Compile time: Translate elements • Link time: Combine elements Loader Process address • Load time: space • Allocate primary memory • Adjust addresses in address space • Copy address space from secondary to primary memory
![Primary & Secondary Memory CPU • CPU can load/store • Ctl Unit executes code Primary & Secondary Memory CPU • CPU can load/store • Ctl Unit executes code](http://slidetodoc.com/presentation_image_h2/3d769c2c2b651a7eddf98dbdeebf74c9/image-5.jpg)
Primary & Secondary Memory CPU • CPU can load/store • Ctl Unit executes code from this memory • Transient storage Load • Access using I/O operations • Persistent storage Primary Memory (Executable Memory) e. g. RAM Secondary Memory e. g. Disk or Tape Information can be loaded statically or dynamically
![Static Memory Allocation Unused In Use pi Issue: Need a mechanism/policy for loading pi’s Static Memory Allocation Unused In Use pi Issue: Need a mechanism/policy for loading pi’s](http://slidetodoc.com/presentation_image_h2/3d769c2c2b651a7eddf98dbdeebf74c9/image-6.jpg)
Static Memory Allocation Unused In Use pi Issue: Need a mechanism/policy for loading pi’s address space into primary memory Operating System Process 3 Process 0 Process 2 Process 1
![Fixed-Partition Memory Mechanism Operating System pi needs ni units ni pi Region 0 N Fixed-Partition Memory Mechanism Operating System pi needs ni units ni pi Region 0 N](http://slidetodoc.com/presentation_image_h2/3d769c2c2b651a7eddf98dbdeebf74c9/image-7.jpg)
Fixed-Partition Memory Mechanism Operating System pi needs ni units ni pi Region 0 N 0 Region 1 N 1 Region 2 N 2 Region 3 N 3
![Fixed-Partition Memory -- Best-Fit Operating System Internal Fragmentation Region 0 N 0 Region 1 Fixed-Partition Memory -- Best-Fit Operating System Internal Fragmentation Region 0 N 0 Region 1](http://slidetodoc.com/presentation_image_h2/3d769c2c2b651a7eddf98dbdeebf74c9/image-8.jpg)
Fixed-Partition Memory -- Best-Fit Operating System Internal Fragmentation Region 0 N 0 Region 1 N 1 pi 2 Region N 2 Region 3 N 3 • Loader must adjust every address in the absolute module when placed in memory
![Fixed-Partition Memory -- Worst-Fit Operating System pi Region 0 N 0 Region 1 N Fixed-Partition Memory -- Worst-Fit Operating System pi Region 0 N 0 Region 1 N](http://slidetodoc.com/presentation_image_h2/3d769c2c2b651a7eddf98dbdeebf74c9/image-9.jpg)
Fixed-Partition Memory -- Worst-Fit Operating System pi Region 0 N 0 Region 1 N 1 Region 2 N 2 Region 3 N 3
![Fixed-Partition Memory -- First-Fit Operating System pi Region 0 N 0 Region 1 N Fixed-Partition Memory -- First-Fit Operating System pi Region 0 N 0 Region 1 N](http://slidetodoc.com/presentation_image_h2/3d769c2c2b651a7eddf98dbdeebf74c9/image-10.jpg)
Fixed-Partition Memory -- First-Fit Operating System pi Region 0 N 0 Region 1 N 1 Region 2 N 2 Region 3 N 3
![Fixed-Partition Memory -- Next-Fit Operating System Region 0 N 0 pi 1 Region N Fixed-Partition Memory -- Next-Fit Operating System Region 0 N 0 pi 1 Region N](http://slidetodoc.com/presentation_image_h2/3d769c2c2b651a7eddf98dbdeebf74c9/image-11.jpg)
Fixed-Partition Memory -- Next-Fit Operating System Region 0 N 0 pi 1 Region N 1 Pi+1 Region 2 N 2 Region 3 N 3
![Variable Partition Memory Mechanism Operating System Process 0 Process 1 Process 6 Process 2 Variable Partition Memory Mechanism Operating System Process 0 Process 1 Process 6 Process 2](http://slidetodoc.com/presentation_image_h2/3d769c2c2b651a7eddf98dbdeebf74c9/image-12.jpg)
Variable Partition Memory Mechanism Operating System Process 0 Process 1 Process 6 Process 2 Process 3 Process 4 Process 5 Process 4 Loader adjusts every address in every absolute module when placed in memory Process 4 • External fragmentation • Compaction moves program in memory
![Cost of Moving Programs load R 1, 0 x 02010 3 F 013010 Program Cost of Moving Programs load R 1, 0 x 02010 3 F 013010 Program](http://slidetodoc.com/presentation_image_h2/3d769c2c2b651a7eddf98dbdeebf74c9/image-13.jpg)
Cost of Moving Programs load R 1, 0 x 02010 3 F 013010 Program loaded at 0 x 01000 3 F 016010 Program loaded at 0 x 04000 • Must run loader over program again! Consider dynamic techniques
![Dynamic Memory Allocation • Could use dynamically allocated memory • Process wants to change Dynamic Memory Allocation • Could use dynamically allocated memory • Process wants to change](http://slidetodoc.com/presentation_image_h2/3d769c2c2b651a7eddf98dbdeebf74c9/image-14.jpg)
Dynamic Memory Allocation • Could use dynamically allocated memory • Process wants to change the size of its address space – Smaller Creates an external fragment – Larger May have to move/relocate the program • Allocate “holes” in memory according to – Best- /Worst- / First- /Next-fit
![Special Case: Swapping • Special case of dynamic memory allocation • Suppose there is Special Case: Swapping • Special case of dynamic memory allocation • Suppose there is](http://slidetodoc.com/presentation_image_h2/3d769c2c2b651a7eddf98dbdeebf74c9/image-15.jpg)
Special Case: Swapping • Special case of dynamic memory allocation • Suppose there is high demand for executable memory • Equitable policy might be to time-multiplex processes into the memory (also space-mux) • Means that process can have its address space unloaded when it still needs memory – Usually only happens when it is blocked
![Dynamic Address Relocation CPU Relative Address 0 x 02010 Relocation Register 0 x 10000 Dynamic Address Relocation CPU Relative Address 0 x 02010 Relocation Register 0 x 10000](http://slidetodoc.com/presentation_image_h2/3d769c2c2b651a7eddf98dbdeebf74c9/image-16.jpg)
Dynamic Address Relocation CPU Relative Address 0 x 02010 Relocation Register 0 x 10000 load R 1, 0 x 02010 + 0 x 12010 MAR • Program loaded at 0 x 10000 Relocation Register = 0 x 10000 • Program loaded at 0 x 04000 Relocation Register = 0 x 04000 We never have to change the load module addresses!
![Runtime Bound Checking CPU Relative Address + Relocation Register Limit Register • Bound checking Runtime Bound Checking CPU Relative Address + Relocation Register Limit Register • Bound checking](http://slidetodoc.com/presentation_image_h2/3d769c2c2b651a7eddf98dbdeebf74c9/image-17.jpg)
Runtime Bound Checking CPU Relative Address + Relocation Register Limit Register • Bound checking is inexpensive to add • Provides excellent memory protection < MAR Interrupt
![L 1 Cache Memory L 2 Cache Memory “Main” Memory Optical Memory Sequentially Accessed L 1 Cache Memory L 2 Cache Memory “Main” Memory Optical Memory Sequentially Accessed](http://slidetodoc.com/presentation_image_h2/3d769c2c2b651a7eddf98dbdeebf74c9/image-18.jpg)
L 1 Cache Memory L 2 Cache Memory “Main” Memory Optical Memory Sequentially Accessed Memory Faster access Primary (Executable) CPU Registers Rotating Magnetic Memory Secondary Larger storage Memory Hierarchies – Dynamic Loading
![Exploiting the Hierarchy • Upward moves are (usually) copy operations – Require allocation in Exploiting the Hierarchy • Upward moves are (usually) copy operations – Require allocation in](http://slidetodoc.com/presentation_image_h2/3d769c2c2b651a7eddf98dbdeebf74c9/image-19.jpg)
Exploiting the Hierarchy • Upward moves are (usually) copy operations – Require allocation in upper memory – Image exists in both higher & lower memories • Updates are first applied to upper memory • Downward move is (usually) destructive – Destroy image in upper memory – Update image in lower memory • Place frequently-used info high, infrequently-used info low in the hierarchy • Reconfigure as process changes phases
![Memory Mgmt Strategies • Fixed-Partition used only in batch systems • Variable-Partition used everywhere Memory Mgmt Strategies • Fixed-Partition used only in batch systems • Variable-Partition used everywhere](http://slidetodoc.com/presentation_image_h2/3d769c2c2b651a7eddf98dbdeebf74c9/image-20.jpg)
Memory Mgmt Strategies • Fixed-Partition used only in batch systems • Variable-Partition used everywhere (except in virtual memory) • Swapping systems – Popularized in timesharing – Relies on dynamic address relocation – Now dated • Dynamic Loading (Virtual Memory) – Exploit the memory hierarchy – Paging -- mainstream in contemporary systems – Segmentation -- the future
![NT Memory-mapped Files Ordinary file • Open the file • Create a section object NT Memory-mapped Files Ordinary file • Open the file • Create a section object](http://slidetodoc.com/presentation_image_h2/3d769c2c2b651a7eddf98dbdeebf74c9/image-21.jpg)
NT Memory-mapped Files Ordinary file • Open the file • Create a section object (that maps file) • Identify point in address space to place the file Section object Secondary memory Executable memory Memory mapped files
- Slides: 21