memory management
play

Memory Management One of the most important OS jobs. Review memory - PowerPoint PPT Presentation

Memory Management One of the most important OS jobs. Review memory hierarchy sizes, speed, cost Growing memories -> growing programs need for swapping and paging The simplest way to use memory is to have one program in memory sharing


  1. Memory Management One of the most important OS jobs. Review memory hierarchy – sizes, speed, cost Growing memories -> growing programs need for swapping and paging The simplest way to use memory is to have one program in memory sharing it with the OS. No swapping or paging. We want multiprogramming – have more than one program in memory at a time.

  2. Memory Management First idea is to divide memory into fixed sized chunks (partitions). The partitions may be equal in size or be of different sizes. A program is given one of the slots and the rest of the partition is wasted. Put it into smallest chunk it will fit into. Single queue of all processes is better than a queue for each size.

  3. Memory Management FIFO vs. pick largest job to not waste memory (poor for small jobs). CPU utilization = 1 – p^n (p = time process waits for I/O, n = degree of multiprogramming). More processes = more efficient use of cpu.

  4. Memory Management Absolute (real) memory address vs. relative memory address. Relocation problem. Programs start at address 0 + have offset. Also must protect address space from other programs.

  5. Memory Management If there isn't enough RAM to hold all the processes, secondary memory + swapping can be used. With swapping whole processes move back and forth between RAM and disk. May be brought back into a different place in memory. Use variable length partitions for better memory utilization. May get many small holes in memory - do memory compaction (slow)

  6. Memory Management How much memory should be allocated to a process? - Fixed size – give exact amount needed - Growth and shrinking - grow into a hole, or have to be moved or swap somebody out. - allocate some space to allow growth. Need a way to keep track of allocated memory (+ to which process) + free memory.

  7. Memory Management Bit maps are one way to keep track of allocated and free memory. - A 1 indicates used and a 0 unused. - Each bit represents one allocation unit (4 bytes, 8 bytes). Linked lists are another way to keep track of memory.

  8. Memory Management Need an algorithm to decide which hole to give to a process. Four fit algorithms. - First Fit – give process first hole in list that is big enough. Break it into two parts (process and a smaller hole). Fast . - Next Fit – Similar to First fit except instead of searching from beginning start where left off. Performs slightly worse than first fit .

  9. Memory Management - Best Fit – Find the smallest hole that will work. Slower than first fit . Wastes more memory because creates small holes. - Worst Fit – Use biggest hole and leave the biggest possible new hole. Doesn't work well in simulation. Another idea is Quick Fit . Have lists of more commonly requested sizes. Can find a good size hole fast. Merging free memory back is hard.

  10. Memory Management Data Structure Thoughts - One list with both processes and holes - slower to find a hole - faster to free up memory. - Two lists – one for processes and one for holes. - can order hole list and speed up best fit. - harder to reallocate. Any other ideas?

  11. The Buddy System Memory blocks are available of size 2 k , L <= k <= U 2 L = smallest size block allowed 2 U = largest block allocated (entire available memory) Start by considering available memory as one block. Then break it down into two buddies of equal size. Continue until smallest block needed for process is created or found. (think binary search).

  12. The Buddy System When memory is released empty buddies can be merged back into a single block. Two free blocks can only be combined if they are buddies, and buddies have addresses that differ only in one bit. Two one-byte blocks are buddies iff they differ in the last bit, two two byte blocks are buddies iff they differ in the second to last bit and so on. (Go over an example)

  13. Buddy System Example Start off with 1 MB to manage 1 MB A requests 100k A=128k, 128k free, 256k free, 512k free B requests 240k A=128k, 128k free, B=256k, 512k free C requests 64k A=128k, C=64k, 64k free, B=256k, 512k free

  14. Buddy System Example D requests 256k A=128k,C=64k, 64k free, B=256k,D=256k, 256k free Release B A=128k,C=64k, 64k free,256k free,D=256k, 256k free Release A 128k free,C=64k,64k free,256k free,D=256k,256k free E requests 75k E=128k,C=64k,64k free,256k free,D=256k,256k free

  15. Buddy System Example Release C E=128k,128k free,256k free, D=256k,256k free Release E 512k free, D=256k,256k free Release D 1 MB

  16. Buddy System Internal and External Fragmentation 129k example Good compromise to overcome disadvantages of fixed and variable partitioning. Used in Linux some for kernel memory

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend