Download presentation
Presentation is loading. Please wait.
Published byHope Cannon Modified over 9 years ago
1
Operating Systems Memory management
2
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
3
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
4
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
5
Topics (continued) 27. malloc 28. sbrk 29. Memory Hierarchy Topics (continued) 27. malloc 28. sbrk 29. Memory Hierarchy
6
Memory In Systems design CPU memory I/O System Figure 1: memory Connects CPU and Peripherals Figure 1: memory Connects CPU and Peripherals
7
Binding Times source program compiler or assembler object model compile time
8
linkage editor load module loader Other object modules system library load time
9
in-memory binary memory image dynamically loaded system library execution time (run time)
10
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
11
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
12
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.
13
Single User Contiguous Memory (continued) Monitor User 32K 0 fence register Figure 4: Single User Contiguous Memory
14
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.
15
Relocation - Why and How (continued) + CPU 14000 memory Base register Logical address 346 Physical address 14346 Figure 5: Address Translation Figure 5: Address Translation
16
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.
17
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]
18
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.
19
Protection (continued) Monitor User 32K 0 fence register Figure 7: Protection in Resident Monitor Model Figure 7: Protection in Resident Monitor Model
20
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.
21
Nonuniform Sized Fixed Partitions Fixed Partitions may have differing sizes.
22
Operating system New Process Figure 8: Nonuniform fixed Partitions [3] Figure 8: Nonuniform fixed Partitions [3]
23
Uniformly Sized Fixed Partitions Memory is frequently partitioned into uniformly sized regions. Memory is frequently partitioned into uniformly sized regions.
24
Operating system 512 K Figure 9: Uniform Fixed Partition Allocation [3] Figure 9: Uniform Fixed Partition Allocation [3]
25
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.
26
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]
27
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]
28
Page frame number 0 1 2 3 4 5 6 7 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
29
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.
30
Virtual memory............ Address mapping mechanism Real storage Contiguous virtual storage locations
31
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.
32
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
33
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.
34
d } Virtual address V=(p,d) pp1p1 Page #Displacement p p1p1 d } Real Address r Frame #Displacement Associative map Associative Memory Lookup
35
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.
36
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
37
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.
38
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
39
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.
40
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.
41
Internal Fragmentation Internal fragmentation occurs when fixed size partitions are too large. Internal fragmentation occurs when fixed size partitions are too large.
42
Page 2 Page 1 Page 0 Internal fragmentation Logical Address Page#=1,Offset=478 000001 01110111110 478 Figure 16: Internal Fragmentation [3] Figure 16: Internal Fragmentation [3]
43
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.
44
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.
45
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.
46
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.
47
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.
48
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.
49
(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
50
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
51
(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.
52
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
53
(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.
54
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
55
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).
56
CPU < Logical address no Trap; address error + yes limitbase memory
57
Memory Layout of A C Programs Traditional Unix/C memory images of programs use segments. Traditional Unix/C memory images of programs use segments.
58
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
59
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).
60
user data In Use List Free List Key Memory management Information
61
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.
62
Memory allocation function malloc application code sbrk system call kernel user process
63
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.
64
Memory Hierarchy Registers Cache Main Memory Magnetic Disk (Cache) Backups Optical Juke Box Remote Access
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.