today
play

Today Memory Management Virtual Memory Segmentation, Paging - PDF document

Today Memory Management Virtual Memory Segmentation, Paging Project 5 Nov 30, 2018 Sprenkle - CSCI330 1 Review What abstraction does virtual memory provide? What requirements do we have for the VM, from the various


  1. Today • Memory Management Ø Virtual Memory Ø Segmentation, Paging • Project 5 Nov 30, 2018 Sprenkle - CSCI330 1 Review • What abstraction does virtual memory provide? • What requirements do we have for the VM, from the various stakeholders, so far? Aaron Bauer, University of Washington “Understanding Human Problem Solving in Complex Digital Environments” Talk at 4 p.m. (Reception at 3:45 p.m.) Nov 30, 2018 Sprenkle - CSCI330 2 1

  2. Address Translation: Wish List • Map virtual addresses to physical addresses • Allow multiple processes OS OS Text to be in memory at once, Process 1 Data Process 3 but isolate them from Heap Process 2 each other • Determine which subset libc code of data to keep in Process 1 memory/move to disk • Allow the same physical Stack memory to be mapped in multiple process VASes Nov 30, 2018 Sprenkle - CSCI330 3 Review: Where should process P be placed? • First fit Ø Don’t spend time searching! OS • Best fit First Fit Process P A Ø It fits tightly! Ø Maybe no other process will fit in that spot • Worst fit Best Fit B Ø Leaves lots of space for another process Worst Fit C Nov 30, 2018 Sprenkle - CSCI330 4 2

  3. (External) Fragmentation • No matter where it ends up, the remaining gaps get smaller OS • Large gaps are probably still usable, small ones likely aren’t A • Fragmentation: over time, we end up with small gaps that become more B difficult to use (eventually, wasted) • “External” because the gaps are between C allocated pieces Nov 30, 2018 Sprenkle - CSCI330 5 (External) Fragmentation • Suppose we put it here, and later, P asks for more memory? OS • What if there isn’t enough space… Ø Move P? Ø Move everybody to compact the address space? • This seems bad. Lots of tough problems P (placement, fragmentation) with no clear solutions. Nov 30, 2018 Sprenkle - CSCI330 6 3

  4. Alternative Organization of PAS • Divide PAS into fixed- size pieces • Use memory translation to assign virtual OS OS addresses to physical locations • Every physical location is an equally good choice! Nov 30, 2018 Sprenkle - CSCI330 7 Address Translation: Wish List • Map virtual addresses to physical addresses • Allow multiple processes to OS OS be in memory at once, but Text Process 1 isolate them from each other Data Process 3 • Determine which subset of Heap Process 2 data to keep in libc code memory/move to disk Process 1 • Allow the same physical memory to be mapped in multiple process VASes Stack • Make it easier to perform placement in a way that reduces fragmentation Nov 30, 2018 Sprenkle - CSCI330 8 4

  5. OS Perspective • Primary challenge: Which physical memory do we give to processes? • Other important considerations: Ø Protection : OS is resource gatekeeper, must isolate itself (and processes) Ø Performance : OS should map memory for best performance, as long as it doesn’t violate protection Nov 30, 2018 Sprenkle - CSCI330 9 Address Translation: Wish List • Map virtual addresses to physical addresses • Allow multiple processes to be OS OS in memory at once, but isolate Text Process 1 them from each other Data Process 3 • Determine which subset of Heap Process 2 data to keep in memory/move to disk libc code • Allow the same physical Process 1 memory to be mapped in multiple process VASes Stack • Make it easier to perform placement in a way that reduces fragmentation • Protection : OS is resource gatekeeper, must isolate itself (and processes) • Performance : OS should map memory for best performance, as long as it doesn’t violate protection Nov 30, 2018 Sprenkle - CSCI330 10 5

  6. Recall: Context Switching Performance • Even though it’s fast, context switching is expensive: 1. time spent is 100% overhead 2. must invalidate other processes’ resources (caches, memory mappings) 0x0 Operating system 3. kernel must execute – it must be Text accessible in memory Data Heap • Solution to #3: Ø keep kernel mapped in every process Stack VAS Ø protect it to be inaccessible 0xFFFFFFFF Nov 30, 2018 Sprenkle - CSCI330 11 Hardware • Hardware and OS are symbiotic, often influence each other Ø Example: atomic instructions • Memory management is another important area of collaboration • Hardware goals: Ø Make translation fast Ø Give OS storage for and control over mappings Nov 30, 2018 Sprenkle - CSCI330 12 6

  7. Address Translation: Wish List • Map virtual addresses to physical addresses OS OS • Allow multiple processes to be in Text Process 1 memory at once, but isolate them Data Process 3 from each other Heap Process 2 • Determine which subset of data to libc code keep in memory/move to disk • Allow the same physical memory to Process 1 be mapped in multiple process VASes Combination of hardware • Make it easier to perform Stack and OS, working together. placement in a way that reduces fragmentation In hardware, MMU: • Map addresses quickly with a little Memory Management Unit HW help Nov 30, 2018 Sprenkle - CSCI330 13 How does each benefit from having a logical memory abstraction? • The user Ø Memory size, protection • The programmer Ø Shared libraries • The compiler Ø Placement of data • The OS / OS designer Ø Memory placement, fragmentation • The hardware / hardware designer Ø Just makes it more complex BUT can help OS Nov 30, 2018 Sprenkle - CSCI330 14 7

  8. Awkward transition PROJECT 5 Nov 30, 2018 Sprenkle - CSCI330 15 Project 5 • Combines processes and memory management • proc.c Ø Implementations of process management and memory management Nov 30, 2018 Sprenkle - CSCI330 16 8

  9. proc.h Data Structures: memoryMap • Allow one process to be loaded into each segment memoryMap Ø Valid Segments: 0x2000, … 0x9000 0 Ø (0x0000 reserved for interrupt vector, USED 0x1000 reserved for kernel) 1 USED • Memory segment map: 2 FREE 3 FREE Ø Each index corresponds 4 USED to one memory segment. 5 FREE • segment = (index+2)*0x1000 6 FREE • index = (segment/0x1000)-2 7 FREE Ø Marked as: • FREE or USED Nov 30, 2018 Sprenkle - CSCI330 17 proc.h Data Structures: PCB • Process Control Block: Constants: struct truct PCB PCB DEFUNCT char name[7] STARTING int state RUNNING int segment int stackPointer READY struct PCB *next BLOCKED struct PCB *prev Nov 30, 2018 Sprenkle - CSCI330 18 9

  10. proc.h Data Structures: pcbPool • PCB Pool struct truct PCB PCB char name[7]: "\0" int state: DEFUNCT int segment: 0x0000 int stackPointer 0x0000 pcbPool struct PCB *next NULL struct PCB *prev NULL 0 1 struct PCB 2 3 . 4 . 5 . 6 7 struct PCB Nov 30, 2018 Sprenkle - CSCI330 19 proc.h Data Structures • struct PCB *running The currently running process struct PCB pcbPool struct truct PCB PCB 0 char name[7]: "uprog2\0" int state: RUNNING 1 int segment: 0x3000 2 int stackPointer 0xFF00 3 struct PCB *next NULL struct PCB *prev NULL 4 5 . . 6 . 7 struct PCB Nov 30, 2018 Sprenkle - CSCI330 20 10

  11. proc.h Data Structures • Ready Queue readyTail struct PCB Ø Doubly-linked list state: READY next: NULL prev: pcbPool struct PCB state: READY 0 next: . 1 . prev: . 2 struct PCB 3 state: READY 4 next: readyHead prev: NULL 5 . 6 . . 7 struct PCB Nov 30, 2018 Sprenkle - CSCI330 21 proc.h Data Structures: running • Initially the running process will be the idle process struct PCB *running idleProc struct truct PCB PCB char name[7]: "IDLE\0" int state: READY If no processes in int segment: 0x1000 int stackPointer 0x???? the ready queue, struct PCB *next NULL run idle process struct PCB *prev NULL Nov 30, 2018 Sprenkle - CSCI330 22 11

  12. Equally awkward translation back VM à PHYSICAL ADDRESS TRANSLATION Nov 30, 2018 Sprenkle - CSCI330 23 Address Translation: Wish List • Map virtual addresses to physical addresses OS OS • Allow multiple processes to be in Text Process 1 memory at once, but isolate them Data Process 3 from each other Heap Process 2 • Determine which subset of data to libc code keep in memory/move to disk • Allow the same physical memory to Process 1 be mapped in multiple process VASes Combination of hardware • Make it easier to perform Stack and OS, working together. placement in a way that reduces fragmentation In hardware, MMU: • Map addresses quickly with a little Memory Management Unit HW help Nov 30, 2018 Sprenkle - CSCI330 24 12

  13. Simple (Unrealistic) Translation Example • Process P 2 ’s virtual addresses don’t align with physical memory’s addresses 0 base P 2 • Consider: P 2 wants to access base + address 0x1000 P 1 • Determine offset from physical address 0 to 0 P 3 P 2 start of P 2 P 2max Phy max Ø store in base Nov 30, 2018 Sprenkle - CSCI330 25 Generalizing • Problem: process may not fit in one contiguous region 0 P 2 Base? + Base? + … Base? + P 2 ? 0 … P 2 P 2 P 2max Phy max Nov 30, 2018 Sprenkle - CSCI330 26 13

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