Download presentation
Presentation is loading. Please wait.
1
The Operating System Memory Manager
Memory Management The Operating System Memory Manager This lecture: Memory hierarchy Physical vs logical (virtual) address space Address binding Relocation and Protection Reading: Bacon
2
The Memory Hierarchy OS OS Storage Access Capacity Managed Type Time
by Registers 100 to 1K compiler 1 ns Cache Memory CPU 8 to 128M 2-20 ns hardware Main 100M 100 ns OS Memory to 1G 10M to 1T Disk 10 ms OS Storage 19 November 2018 CS2051 Lecture 9
3
Background Program must be brought into memory and placed within a process so that it can be run. Simplest scheme: mono-programming: Memory is shared only between operating system (resident part) and the program. If the program was too big? …overlay techniques Multiprogramming: simple but not efficient: fixed partitions more dynamic approaches are needed, which introduce interesting problems! 19 November 2018 CS2051 Lecture 9
4
Multiple processes share memory
Transparency No process needs to be aware of this Processes should not care about physical memory allocation Safety processes should not be able to write to each other’s space Efficiency Two fundamental problems: Relocation and protection Also: How to allocate/manage memory? What if memory does not suffice? (swapping) 19 November 2018 CS2051 Lecture 9
5
The Address Space Machine instructions: Address width is:
load (r1) jump (r3) Address width is: 32 bits in Pentium 64 bits in Alpha, Itanium, SPARC-V9 Addresses need binding to locations before use Physical address space vs virtual address space (recall slide 3 from lecture 2) 19 November 2018 CS2051 Lecture 9
6
Address Binding Requirement
Compiler allocates addresses within module Linker allocates addresses within program application libraries heap gap stack 128K application libraries heap gap stack 192K Program b Program a 19 November 2018 CS2051 Lecture 9
7
Address Binding in Action
Option (a): Static relocation: fix up addresses when program is loaded But … once a process is assigned a place in memory the OS cannot move it (unless ???)! Option (b): Dynamic relocation: use Dynamic Address Translation Translate program addresses into main memory addresses during execution using H/W Use different translations for different programs 19 November 2018 CS2051 Lecture 9
8
Dynamic Translation: Datum scheme
P1 OS P2 P3 D1 D2 D3 P1 NB: Fragmentation P2 P3 19 November 2018 CS2051 Lecture 9
9
Relocation & Protection H/W
Base Register + Virtual (or Logical) Address from CPU Physical Address to Memory >? Limit Register ERROR MMU 19 November 2018 CS2051 Lecture 9
10
(Contiguous) Memory Allocation
As processes are created, grow(?), terminate, the OS must keep track of the memory available: P1 OS P2 P3 free T0: 3 processes T1: P1, P2 finished P4 arrived P4 OS free P3 P4 OS free P3 P5 T2: P5 arrived How to allocate memory? How to deal with fragmentation? How to reclaim memory? How to know what memory is available? 19 November 2018 CS2051 Lecture 9
11
(Contiguous) Memory Allocation -2
Memory allocation policies: First-fit: first hole that is big enough Best-fit: the smallest hole that is big enough Worst-fit: the largest hole Fragmentation: External (as before - reduce by compaction) Internal (within a process’s space) Reclaim memory (read about garbage collection) More dynamic memory allocation? 19 November 2018 CS2051 Lecture 9
12
More to come: Towards Sharing?
OS P2 P3 P1 D1 D2 D3 libc My linux box has ~50 processes running, each with libc (0.6Mb), libX (0.6Mb), libKDE, etc... 19 November 2018 CS2051 Lecture 9
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.