operating systems operating systems memory management
play

Operating Systems: Operating Systems: Memory management Memory - PowerPoint PPT Presentation

Operating Systems: Operating Systems: Memory management Memory management Fall 2008 Fall 2008 Tiina Niklander Tiina Niklander Memory Management Memory Management Programmer wants memory to be Programmer wants memory to be


  1. Operating Systems: Operating Systems: Memory management Memory management Fall 2008 Fall 2008 Tiina Niklander Tiina Niklander

  2. Memory Management Memory Management � � Programmer wants memory to be Programmer wants memory to be Registers � Indefinitely large Indefinitely large � Cache � Indefinitely fast Indefinitely fast � Main memory � Non volatile � Non volatile Magnetic disk � Memory hierarchy Memory hierarchy � Magnetic tape � small amount of fast, expensive memory small amount of fast, expensive memory – – cache cache � � some medium � some medium- -speed, medium price main memory speed, medium price main memory � gigabytes of slow, cheap disk storage gigabytes of slow, cheap disk storage � � Memory manager handles the memory hierarchy Memory manager handles the memory hierarchy � � Requirements for memory management Requirements for memory management � � Logical and physical organization Logical and physical organization � � Protection and sharing � Protection and sharing 2

  3. Memory management Memory management � Programs use logical addresses of their own address Programs use logical addresses of their own address � space (0..MAX) space (0..MAX) � OS kernel usually in a fixed location using physical OS kernel usually in a fixed location using physical � memory addresses directly memory addresses directly � Rest of the physical memory for user processes and Rest of the physical memory for user processes and � other OS parts other OS parts � � OS task: memory allocation and process relocation OS task: memory allocation and process relocation � Hardware task: address translation (to protect memory) Hardware task: address translation (to protect memory) � � MMU MMU – – memory management unit memory management unit � 3

  4. Basic Memory Management: One program Basic Memory Management: One program Monoprogramming Monoprogramming without Swapping or Paging without Swapping or Paging No No memory abstraction, no address space, memory abstraction, no address space, just an just an operating system with one user process operating system with one user process 4

  5. Multiprogramming with Fixed Partitions Multiprogramming with Fixed Partitions � OS places one process in one partition OS places one process in one partition � � Internal fragmentation (whole partition allocated to a Internal fragmentation (whole partition allocated to a � smaller process) smaller process) 5

  6. Fixed partitions Fixed partitions � Process queue for partition on disk Process queue for partition on disk � � In shared queue for all partitions or In shared queue for all partitions or � � In multiple queues for different sizes, In multiple queues for different sizes, � � No free partition, OS can swap No free partition, OS can swap � � � Move one process to disk Move one process to disk � PCB always in memory PCB always in memory � � Program too large for any partition; programmer has to Program too large for any partition; programmer has to � design solution design solution � Overlaying: keep just part of the program in memory Overlaying: keep just part of the program in memory � � Write the program to control the part swapping between Write the program to control the part swapping between � memory and disk memory and disk 6

  7. Relocation and Protection Relocation and Protection � Cannot be sure where Cannot be sure where � program will be loaded in program will be loaded in memory memory � address locations of variables, address locations of variables, � code routines cannot be code routines cannot be absolute absolute � must keep a program out of must keep a program out of � other processes’ other processes’ partitions partitions � � Use Use base and limit base and limit values values � address locations added to base address locations added to base � value to map to physical value to map to physical addr addr � address locations larger than address locations larger than � limit value is an limit value is an error error � Address translation by MMU Address translation by MMU � 7

  8. Sharing Sharing � Access to shared code / data Access to shared code / data � � No violation of the protections! No violation of the protections! � � Shared code Shared code � � must be reentrant, not to change during execution must be reentrant, not to change during execution � � � Just one copy of the shared code (e.g. library) Just one copy of the shared code (e.g. library) � Shared data Shared data � � � Processes co Processes co- -operate and share data structures operate and share data structures � E.g. shared buffer of producer and consumer E.g. shared buffer of producer and consumer � � Solution: Solution: system calls between processes, threads system calls between processes, threads � within a process (in virtual memory alt. solution) within a process (in virtual memory alt. solution) 8

  9. Swapping (1) Swapping (1) Memory allocation changes as Memory allocation changes as � processes come into memory processes come into memory � � leave memory leave memory � Shaded regions are unused memory Shaded regions are unused memory 9

  10. Swapping (2) Swapping (2) � (a) Allocating space for growing data segment (a) Allocating space for growing data segment � � (b) Allocating space for growing stack & data segment (b) Allocating space for growing stack & data segment � 10

  11. Dynamic partitions Dynamic partitions � No fixed predetermined partition sizes No fixed predetermined partition sizes � � External fragments External fragments : 6M + 6M + 4M = 14M � : 6M + 6M + 4M = 14M OS must occasionally reorganize the memory (compaction) (compaction) � OS must occasionally reorganize the memory � 11

  12. Memory Management: bookkeeping Memory Management: bookkeeping allocations and free areas allocations and free areas � Part of memory with 5 processes, 3 holes Part of memory with 5 processes, 3 holes � � tick marks show allocation units tick marks show allocation units � � shaded regions are free shaded regions are free � � (b) Corresponding bit map (b) Corresponding bit map � � (c) Same information as a list (c) Same information as a list � 12

  13. Combining freed areas Combining freed areas Four neighbor combinations for the terminating process X Four neighbor combinations for the terminating process X 13

  14. Allocation Allocation Where to place the new Where to place the new process? process? � Goal: avoid external Goal: avoid external � fragmentation and fragmentation and compaction compaction � Some alternatives: Some alternatives: � � Best Best- -fit fit � � First First- -fit fit � � Next Next- -fit fit � � Worst Worst- -fit fit Sta Fig 7.5 � � � Quick Quick- -fit fit 14

  15. Virtual memory Virtual memory (using paging) (using paging) 15

  16. Paging Paging � OS: the program OS: the program � split to pages split to pages � Page location stored Page location stored � in page table in page table � Process location Process location � 0000001111111111 0000010000000000 � � Logical address Logical address always the same always the same � MMU translates MMU translates � logical address to logical address to physical address physical address using page table using page table � Each page relocated Each page relocated � separately separately 16 Sta Fig 7.11

  17. Paging Paging � Each process has own Each process has own � page table page table � Contains the locations Contains the locations � (frame numbers) of (frame numbers) of allocated frames allocated frames � Page table location stored Page table location stored � in PCB, copied to PTR in PCB, copied to PTR for execution for execution � OS maintains a table (or OS maintains a table (or � list) of page frames, to list) of page frames, to know which are know which are unallocated unallocated 17

  18. Paging: Address Translation Paging: Address Translation MMU has one special register, Page Table Register MMU has one special register, Page Table Register (PTR), for address translation (PTR), for address translation 18

  19. Paging: Address Translation Paging: Address Translation Sta 8.3 19

  20. Page table Page table 20

  21. Page table Page table Typical Page Table Entry , Fig. 3.11 � Each process has its own page table � Each process has its own page table � Each entry has a present bit, since not all pages need to be in the Each entry has a present bit, since not all pages need to be in the � memory all the time memory all the time - -> page faults > page faults � Remember the locality principle Remember the locality principle � � Logical address space can be much larger than the physical Logical address space can be much larger than the physical � 21

  22. Page Tables Page Tables Internal Internal operation of operation of MMU with 16 MMU with 16 4 KB pages 4 KB pages 22

  23. Translation Translation Lookaside Lookaside Buffer Buffer – – TLB TLB 23

  24. TLB TLB – – Translation Translation Lookaside Lookaside Buffer Buffer Goal is to speed up paging Goal is to speed up paging TLB is a cache in MMU for page table entries TLB is a cache in MMU for page table entries 24

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