Download presentation
Presentation is loading. Please wait.
1
Lecture 26: Memory Management - Swapping
2
Review: goals of memory management
Memory allocation A new process comes into memory Memory de-allocation A process leaves memory Address translation Virtual address to physical address Process isolation One process cannot access the memory of other processes
3
Review: Memory management for different systems
Processes are known in advance and can fit in memory Embedded systems, e.g., radios, washing machines, and microwaves Processes are unknown in advance, memory might not be large enough Swapping Virtual memory
4
Swapping Each individual process can fit in memory
But memory cannot fit all processes Each process occupies some consecutive blocks Swap some process out to disk Swap in a process when needed
5
Managing free memory Bitmap Linked list
6
Bitmap Divide memory into blocks
Use a bit 0/1 for every block to indicate whether it is free or not
7
Bitmap (a) (b) A part of memory with five processes and three holes.
Shaded areas are holes (b) The corresponding bitmap
8
Memory allocation/de-allocation with Bitmap
Needed when a new process is loaded or swapped in from disk Suppose a process needs k blocks Find k consecutive 0 bits in the bitmap Memory deallocation Reset the corresponding blocks in bitmap to 0
9
Linked list Put processes and free memory blocks in a linked list
10
Linked list A part of memory with five processes and three holes.
Shaded areas are holes (b) The corresponding bitmap (c) Linked list
11
Linked list Put processes and free memory blocks in a linked list
Each node in this list has four fields First field (binary): indicate free or not Second field (integer): indicate the start address Third field (integer): length of the memory segment Fourth field (pointer): point to the next segment
12
Memory allocation in linked list
First fit Go through the linked list, and find the first free segment that can fit the process, and then split the segment. Best fit Find the smallest free segment that is enough Worst fit Find the largest free segment
13
Memory de-allocation in linked list
Merge neighboring free segments into a larger one
14
Address translation Static address translation slows down loading/swapping in Dynamic address translation Base register in CPU Store the starting physical address of a process Physical address = base + virtual address
15
Process isolation “Limit register” in CPU
Store the length of a process By coming the base register and limit register, we know the memory area that a process has access to
16
Base and limit registers
17
Memory compaction A relatively large process might not fit into the memory even if the free memory is large enough When the free memory are divided into small non-consecutive segments Memory compaction Periodically move processes in memory so that we can have large free segments
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.