cs 423 operating system design historical memory
play

CS 423 Operating System Design: Historical Memory Management - PowerPoint PPT Presentation

CS 423 Operating System Design: Historical Memory Management Tianyin Xu (MIC) * Thanks for Prof. Adam Bates for the slides. CS 423: Operating Systems Design Storage Hierarchy CPU Registers Size Performance 32-64 bits Cache 4-128 words


  1. CS 423 Operating System Design: Historical Memory Management Tianyin Xu (MIC) * Thanks for Prof. Adam Bates for the slides. CS 423: Operating Systems Design

  2. Storage Hierarchy CPU Registers Size Performance 32-64 bits Cache 4-128 words Memory 512-16k words Secondary Storage CS 423: Operating Systems Design 2

  3. Problem Statement We have limited amounts of fast resources, and large amounts of slower resources… How to create the illusion of an abundant fast resource? CS 423: Operating Systems Design 3

  4. History: Mem Overlays Secondary Storage 0K Overlay 1 Main Program 5k Overlay Manager Overlay 2 7k Overlay Area Overlay 3 12k Used when process memory requirement exceeded the physical memory space 4 CS 423: Operating Systems Design

  5. History: Mem Overlays Secondary Storage 0K Overlay 1 Main Program 5k Overlay Manager Overlay 2 7k Overlay 1 Overlay 3 12k Used when process memory requirement exceeded the physical memory space 5 CS 423: Operating Systems Design

  6. History: Mem Overlays Secondary Storage 0K Overlay 1 Main Program 5k Overlay Manager Overlay 2 7k Overlay Area Overlay 3 12k Used when process memory requirement exceeded the physical memory space 6 CS 423: Operating Systems Design

  7. History: Mem Overlays Secondary Storage 0K Overlay 1 Main Program 5k Overlay Manager Overlay 2 7k Overlay 2 Overlay 3 12k Used when process memory requirement exceeded the physical memory space 7 CS 423: Operating Systems Design

  8. History: Mem Overlays Secondary Storage 0K Overlay 1 Main Program 5k Overlay Manager Overlay 2 7k Overlay Area Overlay 3 12k Used when process memory requirement exceeded the physical memory space 8 CS 423: Operating Systems Design

  9. History: Mem Overlays Secondary Storage 0K Overlay 1 Main Program 5k Overlay Manager Overlay 2 7k Overlay 3 Overlay 3 12k Used when process memory requirement exceeded the physical memory space 9 CS 423: Operating Systems Design

  10. History: Mem Overlays Secondary Storage 0K Overlay 1 Main Program 5k Overlay Manager Overlay 2 7k Overlay Area Overlay 3 12k Used when process memory requirement exceeded the physical memory space 10 CS 423: Operating Systems Design

  11. History: Mem Overlays Secondary Storage 0K Overlay 1 Main Program 5k Overlay Manager Overlay 2 7k Overlay 1 Overlay 3 12k Used when process memory requirement exceeded the physical memory space 11 CS 423: Operating Systems Design

  12. History: Fixed Partition Allocation 0k 4k • Approach: Multiprogramming with fixed memory partitions • Divides memory into n fixed partitions (possibly unequal) 16k • Problem? 64k Free Space 128k CS 423: Operating Systems Design 12

  13. History: Fixed Partition Allocation 0k 4k • Approach: Multiprogramming Program 1 with fixed memory partitions • Divides memory into n fixed partitions (possible unequal) 16k • Problem? Program 2 64k Free Space Program 3 128k CS 423: Operating Systems Design 13

  14. History: Fixed Partition Allocation 0k • Approach: Multiprogramming 4k with fixed memory partitions Program 1 • Divides memory into n fixed partitions (possible unequal) 16k • Problem? Program 2 • Internal Fragmentation 64k Free Space Program 3 128k CS 423: Operating Systems Design 14

  15. History: Fixed Partition Allocation ■ Separate input queue for each partition ■ Sorting incoming jobs into separate queues ■ Inefficient utilization of memory ■ when the queue for a large partition is empty but the queue for a small partition is full. Small jobs have to wait to get into memory even though plenty of memory is free. ■ One single input queue for all partitions. ■ Allocate a partition where the job fits in. CS 423: Operating Systems Design 15

  16. History: Relocation ■ Correct starting address when a program should start in the memory ■ Different jobs will run at different addresses When a program is linked, the linker must know at what address the ■ program will begin in memory. ■ Enter “ Logical addresses” Logical address space , range (0 to max) ■ Physical addresses, Physical address space range (R+0 to R+max) for ■ base value R. User program never sees the real physical addresses ■ ■ Relocation register Mapping requires hardware with the base register ■ CS 423: Operating Systems Design 16

  17. History: Relocation Register Base Register BA Physical Logical CPU Address Address + Instruction Memory MA MA+BA Address CS 423: Operating Systems Design 17

  18. History: Variable Partition Allocation 1 Monitor Job 1 Job 2 Job 3 Job 4 Free 2 Monitor Job 1 Job 3 Job 4 Free 3 Monitor Job 1 Job 5 Job 3 Job 4 Free Free Monitor Job 5 Job 3 Job 4 Job 6 4 Free Monitor Job 7 Job 5 Job 3 Job 8 Job 6 5 Memory wasted by External Fragmentation CS 423: Operating Systems Design 18

  19. History: Storage Placement Strategy ■ Best Fit? ■ Use the hole whose size is equal to the need, or if none is equal, the hole that is larger but closest in size. ■ Problem: Creates small holes that can't be used ■ First Fit? ■ Use the first available hole whose size is sufficient to meet the need. ■ Problem: Creates average size holes. ■ Next Fit? ■ Minor variation of first fit: search from the last hole used. ■ Problem: slightly worse performance than first fit. ■ Worst Fit? ■ Use the largest available hole. ■ Problem: Gets rid of large holes making it difficult to run large programs. CS 423: Operating Systems Design 19

  20. Virtual Memory ■ Provide user with virtual memory that is as big as user needs ■ Store virtual memory on disk ■ Cache parts of virtual memory being used in real memory ■ Load and store cached virtual memory without user program intervention CS 423: Operating Systems Design 20

  21. Paging Request Page 3… Page Table VM Frame Memory 3 1 2 3 4 1 2 3 4 Virtual Memory Stored on Disk 1 2 3 4 5 6 7 8 21 CS 423: Operating Systems Design

  22. Paging Request Page 1… Page Table VM Frame Memory 3 1 1 2 3 4 1 2 3 4 Virtual Memory Stored on Disk 1 2 3 4 5 6 7 8 CS 423: Operating Systems Design 22

  23. Paging Request Page 6… Page Table VM Frame Memory 3 1 1 2 6 3 4 1 2 3 4 Virtual Memory Stored on Disk 1 2 3 4 5 6 7 8 CS 423: Operating Systems Design 23

  24. Paging Request Page 2… Page Table VM Frame Memory 3 1 1 2 6 3 2 4 1 2 3 4 Virtual Memory Stored on Disk 1 2 3 4 5 6 7 8 CS 423: Operating Systems Design 24

  25. Paging Request Page 8. Swap Page 1 to Disk First… Page Table VM Frame Memory 3 1 1 2 6 3 2 4 1 2 3 4 Virtual Memory Stored on Disk 1 2 3 4 5 6 7 8 CS 423: Operating Systems Design 25

  26. Paging Request Page 8. … now load Page 8 into Memory. Page Table VM Frame Memory 3 1 8 2 6 3 2 4 1 2 3 4 Virtual Memory Stored on Disk 1 2 3 4 5 6 7 8 CS 423: Operating Systems Design 26

  27. Shared Pages Note: Virtual Memory also supports shared pages. CS 423: Operating Systems Design 27

  28. Page Mapping Hardware Virtual Memory Virtual Address (P,D) Page Table P P D 0 D 1 4 Contents(P,D) 0 1 P→F 1 0 Physical Memory 1 F D F Physical Address (F,D) D Contents(F,D) CS 423: Operating Systems Design 28

  29. Page Mapping Hardware Virtual Memory Virtual Address (004006) Page Table 004 004 006 0 006 1 4 Contents(4006) 0 1 4→5 1 0 Physical Memory 1 005 006 005 Physical Address (F,D) 006 Contents(5006) Page size 1000 Number of Possible Virtual Pages 1000 Number of Page Frames 8 CS 423: Operating Systems Design 29

  30. Page Faults ■ Occur when we access a virtual page that is not mapped into any physical page ■ A fault is triggered by hardware ■ Page fault handler (in OS’s VM subsystem) ■ Find if there is any free physical page available ■ If no, evict some resident page to disk (swapping space) ■ Allocate a free physical page ■ Load the faulted virtual page to the prepared physical page ■ Modify the page table CS 423: Operating Systems Design 30

  31. Reasoning about Page Tables ■ On a 32 bit system we have 2^32 B virtual address space ■ i.e., a 32 bit register can store 2^32 values ■ # of pages are 2 n (e.g., 512 B, 1 KB, 2 KB, 4 KB…) ■ Given a page size, how many pages are needed? ■ e.g., If 4 KB pages (2^12 B), then 2^32/2^12=… ■ 2^20 pages required to represent the address space ■ But ! each page entry takes more than 1 Byte of space to represent. ■ suppose page size is 4 bytes (Why?) ■ (2*2) * 2^ 20 = 4 MB of space required to represent our page table in physical memory. ■ What is the consequence of this? CS 423: Operating Systems Design 31

  32. Paging Issues ■ Page size is 2 n ■ usually 512 bytes, 1 KB, 2 KB, 4 KB, or 8 KB ■ E.g. 32 bit VM address may have 2 20 (1 MB) pages with 4k (2 12 ) bytes per page ■ Page table: ■ 2 20 page entries take 2 22 bytes (4 MB) ■ Must map into real memory ■ Page Table base register must be changed for context switch ■ No external fragmentation; internal fragmentation on last page only CS 423: Operating Systems Design 32

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