Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tutorial 6 Memory Management

Similar presentations


Presentation on theme: "Tutorial 6 Memory Management"— Presentation transcript:

1 Tutorial 6 Memory Management
Comp346 Winter 2015 Tutorial 6 Memory Management 1 Memory Management

2 Types of Memory Primary Memory (RAM)
Holds data and programs used by a process that is executing. Only type of memory that a CPU deals with. Secondary Memory (i.e., hard disk) Non-volatile memory used to store data when a process is not executing. Memory Management

3 The Memory Manager (MM)
Purpose: to manage the use of primary and secondary memory. Responsible for: Allocating primary memory to processes. Moving processes between primary and secondary memory. Optimizing memory usage. Memory Management

4 Within a Process Memory Management

5 Process Memory There are two types of memory that can be used within a process: Stack: used for local variables and for passing parameters to function calls. Heap: used for dynamic memory allocation. Memory Management

6 Process Memory Layout Allocates more memory than needed at first.
Text Segment Allocates more memory than needed at first. Heap grows towards stack for dynamic memory allocation. Stack grows towards heap when automatic variables are created. Data Segment (global and static variables) Heap Storage Stack Segment Environment Variables, etc. Memory Management

7 Between Processes Memory Management

8 Memory Allocation When a process is ready to run, it requests memory from the MM. Different strategies can be used to allocate memory: Fixed-partition strategies Variable-partition strategies Memory Management

9 Fixed-Partition Strategies
Memory is divided into fixed-size regions. Size of each region usually is not equal. MM will allocate a region to a process that best fits it. Unused memory within an allocated partition is called internal fragmentation. Memory Management

10 An Example Operating Partition 1 System Process 1 Partition 2
Internal Fragmentation Process 2 Partition 3 Process 3 Partition 4 Internal Fragmentation Partition 5 Partition 6 Partition 7 Memory Management

11 Problems … Not suitable for systems in which process memory requirements is not known ahead of time; i.e., timesharing systems. Sometimes, user is idle; other times, memory requirements change! Memory Management

12 Variable-Partition Strategies
MM allocates regions equal to the memory requirements of a process at any given time. As processes die, holes develop in the memory, MM inserts new processes into holes using a best fit strategy. Memory Management

13 More… Results in External Fragmentation
After a while, only small processes will be able to run due to too much external fragmentation. MM must compact the memory to make more space available for larger processes. Memory Management

14 An Example Operating System Operating System Operating System
Process 5 Process 5 Process 1 Process 4 Process 4 Process 2 Process 3 Process 3 Process 3 Initially P2 completes P4 starts P1 completes P5 starts After compacting Memory Management

15 Memory Management Strategies

16 MM Strategies Since most OSs offer multiprogramming, we study multiple-partition MM strategies. We want to maximize the number of (active) processes that can be “in memory” at the same time. Makes use of “secondary storage”.

17 Swapping Comes from the basis that when a process is blocked, it does not need to be in memory. Thus, it is possible to save a process’ entire address space to disk. Implemented on Windows. Blocked = waiting for I/O, semaphore, blocked on resource and anything else you can think of…

18 Virtual Memory Comes from the basis that all of a process’ address space is not needed at once. Thus, chop up the address space into smaller parts and only load the parts that are needed. These parts need not be contiguous in memory!

19 Virtual Memory Usage Virtual memory is used in most modern operating systems: Windows NT/XP/ X uses one or more “page files” to swap pages. Linux uses a hard disk partition (“swap partition”) to swap to.

20 Virtual Memory More details about Virtual Memory will be in the next tutorial. Memory Management


Download ppt "Tutorial 6 Memory Management"

Similar presentations


Ads by Google