Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tutorial 7 Memory Management presented by: Antonio Maiorano Paul Di Marco.

Similar presentations


Presentation on theme: "Tutorial 7 Memory Management presented by: Antonio Maiorano Paul Di Marco."— Presentation transcript:

1 Tutorial 7 Memory Management presented by: Antonio Maiorano Paul Di Marco

2 Types of Memory Primary Memory (a.k.a. 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

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

4 Within a Process

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

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

7 Between Processes

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

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

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

11 Problems… Not suitable for systems in which process memory requirements not known ahead of time; i.e. timesharing systems Sometimes, user is idle; other times, can be running many programs – memory requirements change!

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

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

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

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 9X/Me, saving to a “swap file”

18 Pros/Cons Simple strategy that does not need much extra hardware (process relocation) Inefficient to swap large address spaces for short times!

19 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!

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

21 Pros/Cons Since only the necessary parts of the process are loaded, processes load faster and it allows much better memory utilization Needs lots of extra hardware to accomplish the job (efficiently) In some cases too much paging (i.e. “thrashing”) can occur, which is very slow


Download ppt "Tutorial 7 Memory Management presented by: Antonio Maiorano Paul Di Marco."

Similar presentations


Ads by Google