Operating Systems Memory management. Memory Management List of Topics 1. Memory Management 2. Memory In Systems Design 3. Binding Times 4. Introduction.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

Part IV: Memory Management
OS Fall’02 Memory Management Operating Systems Fall 2002.
Modified from Silberschatz, Galvin and Gagne Lecture 16 Chapter 8: Main Memory.
Memory Management CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Operating Systems I Memory Management. Overview F Provide Services –processes  –files  F Manage Devices –processor  –memory  –disk 
Memory Management.
Memory Management 2010.
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Chapter 7: Main Memory CS 170, Fall Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
Silberschatz, Galvin and Gagne  Operating System Concepts Multistep Processing of a User Program User programs go through several steps before.
Main Memory. Background Program must be brought (from disk) into memory and placed within a process for it to be run Main memory and registers are only.
03/17/2008CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying the textbook.
03/05/2008CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Chapter 8: Main Memory.
Chapter 91 Memory Management Chapter 9   Review of process from source to executable (linking, loading, addressing)   General discussion of memory.
Chap 8 Memory Management. Background Program must be brought into memory and placed within a process for it to be run Input queue – collection of processes.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, Operating System Concepts Operating Systems Lecture 24 Paging.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
Memory Management -1 Background Swapping Memory Management Schemes
Review of Memory Management, Virtual Memory CS448.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 8: Main Memory.
Swapping and Contiguous Memory Allocation. Multistep Processing of a User Program User programs go through several steps before being run. Program components.
Memory Management. Process must be loaded into memory before being executed. Memory needs to be allocated to ensure a reasonable supply of ready processes.
OSes: 8. Mem. Mgmt. 1 Operating Systems v Objectives –describe some of the memory management schemes used by an OS so that several processes can be in.
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
1 Address Translation Memory Allocation –Linked lists –Bit maps Options for managing memory –Base and Bound –Segmentation –Paging Paged page tables Inverted.
CE Operating Systems Lecture 14 Memory management.
Chapter 4 Memory Management Virtual Memory.
Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.
CSC 360, Instructor Kui Wu Memory Management I: Main Memory.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Memory and Addressing It all starts.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Chapter 7: Main Memory CS 170, Fall Program Execution & Memory Management Program execution Swapping Contiguous Memory Allocation Paging Structure.
Main Memory CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
Module 9: Memory Management
Requirements, Partitioning, paging, and segmentation
Chapter 8: Main Memory.
Main Memory Management
Chapter 8: Main Memory.
Chapter 8: Main Memory.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
Operating System Concepts
Memory Management 11/17/2018 A. Berrached:CS4315:UHD.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
Multistep Processing of a User Program
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
Memory Management-I 1.
Main Memory Background Swapping Contiguous Allocation Paging
Chapter 8: Memory management
Outline Module 1 and 2 dealt with processes, scheduling and synchronization Next two modules will deal with memory and storage Processes require data to.
Lecture 3: Main Memory.
Operating System Chapter 7. Memory Management
Chapter 8: Memory Management strategies
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
CSE 542: Operating Systems
Presentation transcript:

Operating Systems Memory management

Memory Management List of Topics 1. Memory Management 2. Memory In Systems Design 3. Binding Times 4. Introduction to Memory Management 5. Raw Memory Model 6. Single User Contiguous Memory 7. Relocation - Why and How 8. Overlay Management List of Topics 1. Memory Management 2. Memory In Systems Design 3. Binding Times 4. Introduction to Memory Management 5. Raw Memory Model 6. Single User Contiguous Memory 7. Relocation - Why and How 8. Overlay Management

Topics (continued) 9. Protection 10. Fixed Partitions 11. Nonuniform Sized Fixed Partitions 12. Uniformly Sized Fixed Partitions 13. Simple Paging 14. Benefits of Simple Paging 15. Page Tables 16. Translation Lookaside Buffers 17. Hierarchical Address Caching Topics (continued) 9. Protection 10. Fixed Partitions 11. Nonuniform Sized Fixed Partitions 12. Uniformly Sized Fixed Partitions 13. Simple Paging 14. Benefits of Simple Paging 15. Page Tables 16. Translation Lookaside Buffers 17. Hierarchical Address Caching

Topics (continued) 18. Dynamic Partitions 19. Fragmentation 20. Internal Fragmentation 21. External Fragmentation 22. Coalescing Holes 23. Compaction 24. Dynamic Partition Placement 25. Simple Segmentation 26. Memory Layout of A C Program Topics (continued) 18. Dynamic Partitions 19. Fragmentation 20. Internal Fragmentation 21. External Fragmentation 22. Coalescing Holes 23. Compaction 24. Dynamic Partition Placement 25. Simple Segmentation 26. Memory Layout of A C Program

Topics (continued) 27. malloc 28. sbrk 29. Memory Hierarchy Topics (continued) 27. malloc 28. sbrk 29. Memory Hierarchy

Memory In Systems design CPU memory I/O System Figure 1: memory Connects CPU and Peripherals Figure 1: memory Connects CPU and Peripherals

Binding Times source program compiler or assembler object model compile time

linkage editor load module loader Other object modules system library load time

in-memory binary memory image dynamically loaded system library execution time (run time)

Introduction to Memory Management Memory management issues: 1. Relocation 2. Protection 3. Sharing 4. Logical Organization 5. Physical Organization Consider a series of solutions starting with the most primitive first Memory management issues: 1. Relocation 2. Protection 3. Sharing 4. Logical Organization 5. Physical Organization Consider a series of solutions starting with the most primitive first

Raw Memory Model The raw memory provides no services and gives the programmer complete control. The raw memory provides no services and gives the programmer complete control. 0 1 MB Figure 3: Raw Machine Model Figure 3: Raw Machine Model

Single User Contiguous Memory Primitive operating systems (such as MS- DOS and CP/M) provide some interfaces to the hardware but not much else in the way of services. Primitive operating systems (such as MS- DOS and CP/M) provide some interfaces to the hardware but not much else in the way of services.

Single User Contiguous Memory (continued) Monitor User 32K 0 fence register Figure 4: Single User Contiguous Memory

Relocation - Why and How Relocation refers to the ability to store a program at an arbitrary base memory address. Actual memory locations have physical or absolute addresses, user program's access these locations using logical addresses. Relocation refers to the ability to store a program at an arbitrary base memory address. Actual memory locations have physical or absolute addresses, user program's access these locations using logical addresses.

Relocation - Why and How (continued) + CPU memory Base register Logical address 346 Physical address Figure 5: Address Translation Figure 5: Address Translation

Overlay Management Overlays have gone out of fashion with cheaper memory, users (and compilers) determine which code to swap in and out. Overlays have gone out of fashion with cheaper memory, users (and compilers) determine which code to swap in and out.

symbol table common routines overlay driver pass 1 pass 2 20K 30K 10K 80K 70K Figure 6: Overlay Management Example [2] Figure 6: Overlay Management Example [2]

Protection It is undesirable to permit user programs (accidentally or intentionally) to accesses memory outside of their partition. It is undesirable to permit user programs (accidentally or intentionally) to accesses memory outside of their partition.

Protection (continued) Monitor User 32K 0 fence register Figure 7: Protection in Resident Monitor Model Figure 7: Protection in Resident Monitor Model

Fixed Partitions Fixed partitioning refers to memory being split into contiguous non overlapping regions of precomputed sizes. Fixed sized partitions make the selection of a partition for a job easy. Fixed partitioning refers to memory being split into contiguous non overlapping regions of precomputed sizes. Fixed sized partitions make the selection of a partition for a job easy.

Nonuniform Sized Fixed Partitions Fixed Partitions may have differing sizes.

Operating system New Process Figure 8: Nonuniform fixed Partitions [3] Figure 8: Nonuniform fixed Partitions [3]

Uniformly Sized Fixed Partitions Memory is frequently partitioned into uniformly sized regions. Memory is frequently partitioned into uniformly sized regions.

Operating system 512 K Figure 9: Uniform Fixed Partition Allocation [3] Figure 9: Uniform Fixed Partition Allocation [3]

Simple Paging Paging provides relocation, and splits memory into fixed length partitions called frames. Paging provides relocation, and splits memory into fixed length partitions called frames.

Page frame 0 Page frame 1 Page frame 2 Page frame 3 0 p-1 p 2p-1 2p 3p-1 3p 4p-1 Figure 10: Simple Paging [1] Figure 10: Simple Paging [1]

4p 5p-1 5p 6p-1 6p 7p-1 7p 8p-1 Page frame 4 Page frame 5 Page frame 6 Page frame 7 Figure 10: Simple Paging (continued) [1] Figure 10: Simple Paging (continued) [1]

Page frame number Page frame size p Range of real storage addresses 0 p-1 p 2p-1 2p 3p-1 3p 4p-1 4p 5p-1 5p 6p-1 6p 7p-1 7p 8p-1

Benefits of Simple Paging Simple paging allows discontiguous storage for memory objects exceeding the page frame size. Simple paging allows discontiguous storage for memory objects exceeding the page frame size.

Virtual memory Address mapping mechanism Real storage Contiguous virtual storage locations

Page Tables One simple mechanism is to allocate some real memory space for a table, and hash page addresses using the high order address bits as pointers into the page table. There are 2 real memory accesses per virtual memory access. One simple mechanism is to allocate some real memory space for a table, and hash page addresses using the high order address bits as pointers into the page table. There are 2 real memory accesses per virtual memory access.

Page Tables (continued) d b p p 1 d p1p1 p b Page # Displacement Virtual address } v=(p,d) Page b Map Table p } Real address b+p

Translation Lookaside Buffers Translation lookaside buffers (TLB) eliminate one physical memory reference using special associative memory, which addressed by its contents in O(1) parallel search time. Translation lookaside buffers (TLB) eliminate one physical memory reference using special associative memory, which addressed by its contents in O(1) parallel search time.

d } Virtual address V=(p,d) pp1p1 Page #Displacement p p1p1 d } Real Address r Frame #Displacement Associative map Associative Memory Lookup

Hierarchical Address Caching Rather than placing all addresses in the TLB recently/frequently used addresses are stored in associative memory, with misses being serviced by the page table. Rather than placing all addresses in the TLB recently/frequently used addresses are stored in associative memory, with misses being serviced by the page table.

Hierarchical Address Caching (continued) Address of Page table b Page table origin register p1p1 Page # p Displacement d Virtual address v=(p,d) + Partial associative pp1p1 p Try this first Performed only if no match in associative map b+p Real address Displacement d Frame # p 1 Only if match in associative map Only if no match in associative map Direct map (all pages) Map (most active pages only

Dynamic Partitions Dynamically partitioned memory allows placement of relocatable code in variable size contigous memory regions. Dynamically partitioned memory allows placement of relocatable code in variable size contigous memory regions.

Dynamic Partitions (continued) userneeds I H G F E D C B A 9K. 18K. 11K. 32K. 14K. 25K. 10K. 20K. 15K. Operating system User A 15K Operating User Operating system Free B 20K A 15K B 20K Free C 10K D 25K Free

Fragmentation Fragmentation makes available memory useless by breaking it into discontiguous pieces too small to use. Fragmentation makes available memory useless by breaking it into discontiguous pieces too small to use.

Fragmentation (continued) There are two categories of memory fragmentation: 1. Internal Fragmentation --- A fixed partition contains more memory than required by the user, and some is wasted. 2. External Fragmentation --- Results from the holes left by dynamic partitions. There are two categories of memory fragmentation: 1. Internal Fragmentation --- A fixed partition contains more memory than required by the user, and some is wasted. 2. External Fragmentation --- Results from the holes left by dynamic partitions.

Internal Fragmentation Internal fragmentation occurs when fixed size partitions are too large. Internal fragmentation occurs when fixed size partitions are too large.

Page 2 Page 1 Page 0 Internal fragmentation Logical Address Page#=1,Offset= Figure 16: Internal Fragmentation [3] Figure 16: Internal Fragmentation [3]

External Fragmentation External fragmentation happens when dynamic partitions are released. The fragments are frequently called holes. External fragmentation happens when dynamic partitions are released. The fragments are frequently called holes.

operating system User A User B User C User D User E Hole operating system User A User C User D User E Hole operating system User A User C User E Hole User B finishes and frees its storage. User D finishes and frees its storage.

Coalescing Holes Adjacent holes in dynamic partitions should be coalesced into a single larger hole. Adjacent holes in dynamic partitions should be coalesced into a single larger hole.

operating system other users 5K user A other users 2K Hole 5K Hole other users other users operating system 7K Hole other users other users operating system User A finishes and frees its storage Operating system combines adjacent holes to form a single larger hole.

Compaction If the amount of memory available in the holes is large enough to service a request, the holes may made contiguous by compacting storage. If the amount of memory available in the holes is large enough to service a request, the holes may made contiguous by compacting storage.

operating systems In use Free operating systems Free In use Operating system places all “in use” blocks together leaving free storage as a single, large hole.

(a) First-Fit Strategy Place job in first storage hole on free storage place list in which it will fit (a) First-Fit Strategy Place job in first storage hole on free storage place list in which it will fit Dynamic Partition Placement

Operating systems 16K hole 14K hole 5K hole 30K hole In use a16K c14K e 5K g30K Request for 13K Free Storage List Start Address Length (kept in storage address order, or something in random order.) 0 a b c d e f g h

(b) Best-Fit Strategy Place job in the smallest possible hole in which it will fit. (b) Best-Fit Strategy Place job in the smallest possible hole in which it will fit.

Operating systems 16K hole 14K hole 5K hole 30K hole In use e 5K c14K a 16K g30K Request for 13K Start Address Length (Kept in ascending order by hole size.) 0 a b c d e f g h Free Storage List

(c) Worst-Fit Strategy Place job in the largest possible hole in which it will fit. (c) Worst-Fit Strategy Place job in the largest possible hole in which it will fit.

Operating systems 16K hole 14K hole 5K hole 30K hole In use g30K a16K c 14K e 5K Request for 13K Start Address Length (Kept in descending order by hole size.) 0 a b c d e f g h Free Storage List

Simple Segmentation Segmentation provides relocation, and supports contiguous variable length partitions. Segmentation often provides protection (counterexample Intel 8086). Segmentation provides relocation, and supports contiguous variable length partitions. Segmentation often provides protection (counterexample Intel 8086).

CPU < Logical address no Trap; address error + yes limitbase memory

Memory Layout of A C Programs Traditional Unix/C memory images of programs use segments. Traditional Unix/C memory images of programs use segments.

high address low address text uninitialized data (bss) heap stack Initialized data Command-line arguments and environment variables initialized to zero by exec read from program file by exec

malloc Programmers often want to allocate data objects which persist beyond the function call creating them (e.g. constructors in OOP). In C and C++ the malloc operator maintains a linked list of data objects, in the user program's Data segment (on the Heap). Programmers often want to allocate data objects which persist beyond the function call creating them (e.g. constructors in OOP). In C and C++ the malloc operator maintains a linked list of data objects, in the user program's Data segment (on the Heap).

user data In Use List Free List Key Memory management Information

sbrk A user program can exhaust its default heap space allocation. The Unix sbrk system call increases data segment allocation at run time. A user program can exhaust its default heap space allocation. The Unix sbrk system call increases data segment allocation at run time.

Memory allocation function malloc application code sbrk system call kernel user process

Memory Hierarchy Users want to: 1. Increase their address space, using slow cheaper memory to extend their more expensive faster memory. 2. Increase the speed at which they can the extended memory by using small amounts of expensive fast memory. Users want to: 1. Increase their address space, using slow cheaper memory to extend their more expensive faster memory. 2. Increase the speed at which they can the extended memory by using small amounts of expensive fast memory.

Memory Hierarchy Registers Cache Main Memory Magnetic Disk (Cache) Backups Optical Juke Box Remote Access