1 / 28

Operating Systems Design (CS 423)

Learn about base and limit virtual memory, memory allocation algorithms, buddy system, system initialization, deallocation, paging, and more for effective memory management in operating systems.

Download Presentation

Operating Systems Design (CS 423)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC http://www.cs.illinois.edu/class/cs423/ Based on slides by Roy Campbell, Sam King, and Andrew S Tanenbaum

  2. Base and Limit virtual mem • Load each process into contiguous regions of physical memory If(virt addr > bound){ trap to kern } else { phys addr = virt addr + base } physical mem lim2 0 base2 + lim2 base2 base1 + lim1 virtual mem base1 lim1 0 0

  3. Base and limit • What must change during a context switch? • Can a process change its own base and limit? • Can you share memory with another process? • How does the kernel handle the address space growing • You are the OS designer, come up with an algorithm for allowing processes to grow

  4. Memory Allocation in the small virtual mem physical mem physical mem physical mem virtual mem ? virtual mem virtual mem virtual mem

  5. Memory Management w/ Linked Lists A B C D E F 8 16 24 32 • Info for each hole • Both ends: • Size of hole • Bit saying free or allocated • Together • Next and Previous pointers to other holes • Info for each allocated “chunk: • Size and allocation bit, together, on each end

  6. Memory Allocation Algorithms A B C D E F • Allocated 2 units: • First fit 8 8 8 8 16 16 16 16 24 24 24 24 32 32 32 32 G A B C D E F • Best fit G A B C D E F • Worst fit G A B C D E F

  7. Memory Deallocation – Linked Lists A B C D E F 8 8 8 8 8 16 16 16 16 16 24 24 24 24 24 32 32 32 32 32 - A B C D E F - B A C D E F - C - E A A B B C D D E F F

  8. Buddy System Blocks of memory allocated in sizes that are 2x Determine the largest size block 2u that fits in available memory Fix a smallest size to be allocated 2l When ymemory needed, determine smallest k such that 2k y Find free block of that size If none exists, find smallest one large enough Divide it in half repeatedly until small enough Allocate in first piece, marking all others as free

  9. Buddy System - Deallocating Each block has a “buddy” to its left or right When block is released, its buddy is checked When two buddies are free, they are merged Minimizes external fragmentation - gaps in allocated memory May still have much internal fragmentation - gaps between allocation and actual use

  10. Buddy System System Initialization u= 10; 2uk = 1024k = 1m l = 2; 22 = 4k Initialize search tree 1024k Free

  11. Buddy System A needs 100k Divide memory into two 512K blocks Divide first into two 256k blocks Divide first into two 128k blocks Assign A first of these A 128k 128k 256k Part Free Part 512k Free Part Free Full

  12. Buddy System B needs 300k Search left Stop at second branch because it is not free Search right Assign B 512K block 128k A 128k 256k Part B Full Part 512k Free Part Free Full

  13. Buddy System C needs 200k Find leftmost block that fits Assign C 256K block 128k A 128k C 256k Part B Full Part 512k Full Part Free Full

  14. Buddy System D needs 50k Split 128K block Assign C first 64K block 128k A 64k D 64K C 256k Part Full Part B Full Part 512k Part Full Free Full

  15. Buddy System Deallocate A Buddy is part full; just free A 128k 64k D 64K C 256k Part Full Part B Full Part 512k Part Free Free Full

  16. Buddy System Deallocate D Immediate buddy is free; merge One level up, buddy is free; merge Mark 256K free 256k C 256k B 512k Part Full Part Full Free

  17. Buddy System Deallocate B Immediate buddy is not free Just free 512K 256k C 256k Part Free Part Full Free 512k

  18. Buddy System Deallocate C Immediate buddy is free; merge Next buddy is free; merge Mark all 1024k free 1024k Free

  19. Paging • Allocate physical memory in terms of fixed‐ size chunk • Fixed unit easier to allocate • Any free physical page (page frame) can store any virtual page • Virtual address • Virtual page # (high bits of address) • Offset (low bits of address, e.g., bits 11‐0 for 4k page)

  20. Translations table • Fig 3.9 from Tanenbaum

  21. Translation Process If(virtual page is invalid or non-resident or protected) { trap to OS fault handler } else { physical page # = pageTable[virtpage#].physPageNum }

  22. Translation Process • What must change on a context switch?

  23. Translation Process • What must change on a context switch? • Page table must be replaces • Each virtual page can be in physical memory or swapped out to disk (called paged)

  24. Resident Pages • How does the processor know that a virtual page is not in memory?

  25. Resident Pages • How does the processor know that a virtual page is not in memory? • A bit in the page table entry • Resident means a virtual page is in memory • NOT an error for a program to access non‐resident page

  26. Valid Pages Accesses • Pages can have different protections • Read, write, execute • Valid means that a virtual page is legal for the program to access • E.g. page not part of the address space is invalid page • IS an error to try to access an invalid page

  27. Valid vs Resident • Who makes a page resident / non‐resident? • Who makes a virtual page valid / invalid? • Why would a process want one if its virtual pages to be invalid?

  28. Valid vs Resident • Who makes a page resident / non‐resident? • OS • Who makes a virtual page valid / invalid? • (user) program • Why would a process want one of its virtual pages to be invalid? • Security, and general protection from self

More Related