Understanding Memory Management and Swapping Techniques

Slide Note
Embed
Share

Memory management involves techniques like swapping, memory allocation changes, memory compaction, and memory management with bitmaps. Swapping refers to bringing each process into memory entirely, running it for a while, then putting it back on the disk. Memory allocation can change as processes enter and leave memory. Memory compaction is a technique to combine multiple holes in memory into a single larger one. Allocation for processes varies depending on fixed or dynamic memory segment growth. Techniques like allocating space for data segments and managing memory with bitmaps are used in memory management practices.


Uploaded on Aug 11, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Memory management: Memory management: Swapping Swapping

  2. What is Swapping? What is Swapping? Bringing in each process in its entirety, running it for a while, then putting it back on the disk. Ali Akbar Mohammadi 2

  3. Memory allocation changes as processes come Memory allocation changes as processes come into memory and leave it. into memory and leave it. Ali Akbar Mohammadi 3

  4. Memory Compaction Memory Compaction When swapping creates multiple holes in memory, it is possible to combine them all into one big one by moving all the processes downward as far as possible. This technique is known as memory compaction. It is usually not done because it requires a lot of CPU time. Ali Akbar Mohammadi 4

  5. How much memory should be allocated for a How much memory should be allocated for a process when it is created or swapped in? process when it is created or swapped in? If processes are created with a fixed size that never changes, then the allocation is simple: the operating system allocates exactly what is needed, no more and no less. If, however, processes' data segments can grow, for example, by dynamically allocating memory from a heap, as in many programming languages, a problem occurs whenever a process tries to grow. If a hole is adjacent to the process, it can be allocated and the process can be allowed to grow into the hole. On the other hand, if the process is adjacent to another process, the growing process will either have to be moved to a hole in memory large enough for it, or one or more processes will have to be swapped out to create a large enough hole. If a process cannot grow in memory and the swap area on the disk is full, the process will have to wait or be killed. Ali Akbar Mohammadi 5

  6. (a) Allocating space for a growing data segment. (a) Allocating space for a growing data segment. (b) Allocating space for a growing stack and a growing data segment. (b) Allocating space for a growing stack and a growing data segment. Ali Akbar Mohammadi 6

  7. Memory Management with Bitmaps Memory Management with Bitmaps memory is divided up into allocation units, perhaps as small as a few words and perhaps as large as several kilobytes. Corresponding to each allocation unit is a bit in the bitmap, which is 0 if the unit is free and 1 if it is occupied (or vice versa). Ali Akbar Mohammadi 7

  8. Size of the Allocation Unit Size of the Allocation Unit The smaller the allocation unit, the larger the bitmap. A memory of 32n bits will use n map bits, so the bitmap will take up only 1/33 of memory. If the allocation unit is chosen large, the bitmap will be smaller, but appreciable memory may be wasted in the last unit of the process if the process size is not an exact multiple of the allocation unit. Ali Akbar Mohammadi 8

  9. Memory Management with Linked Lists Memory Management with Linked Lists Another way of keeping track of memory is to maintain a linked list of allocated and free memory segments, where a segment is either a process or a hole between two processes. Ali Akbar Mohammadi 9

  10. Part of Memory and the Corresponding Bitmap Part of Memory and the Corresponding Bitmap Ali Akbar Mohammadi 10

  11. Four neighbor combinations for the terminating Four neighbor combinations for the terminating process, process, X X. . Ali Akbar Mohammadi 11

  12. Algorithms for Allocate Memory for a Newly Algorithms for Allocate Memory for a Newly Created Process Created Process First fit Next fit Best fit Worst fit Quick fit Ali Akbar Mohammadi 12

  13. First Fit First Fit The process manager scans along the list of segments until it finds a hole that is big enough. The hole is then broken up into two pieces, one for the process and one for the unused memory, except in the statistically unlikely case of an exact fit. First fit is a fast algorithm because it searches as little as possible. Ali Akbar Mohammadi 13

  14. Next Fit Next Fit It works the same way as first fit, except that it keeps track of where it is whenever it finds a suitable hole. The next time it is called to find a hole, it starts searching the list from the place where it left off last time, instead of always at the beginning, as first fit does. Next fit gives slightly worse performance than first fit. Ali Akbar Mohammadi 14

  15. Best Fit Best Fit Best fit searches the entire list and takes the smallest hole that is adequate. Rather than breaking up a big hole that might be needed later, best fit tries to find a hole that is close to the actual size needed. Best fit is slower than first fit because it must search the entire list every time it is called. Somewhat surprisingly, it also results in more wasted memory than first fit or next fit because it tends to fill up memory with tiny, useless holes. First fit generates larger holes on the average. Ali Akbar Mohammadi 15

  16. Worst Fit Worst Fit To get around the problem of breaking up nearly exact matches into a process and a tiny hole, one could think about worst fit, that is, always take the largest available hole, so that the hole broken off will be big enough to be useful. Worst fit is not a very good idea either. Ali Akbar Mohammadi 16

  17. Quick Fit Quick Fit maintains separate lists for some of the more common sizes requested. With quick fit, finding a hole of the required size is extremely fast, but it has the same disadvantage as all schemes that sort by hole size, namely, when a process terminates or is swapped out, finding its neighbors to see if a merge is possible is expensive. If merging is not done, memory will quickly fragment into a large number of small holes into which no processes fit. Ali Akbar Mohammadi 17

More Related Content