MODERN OPERATING SYSTEMS Third edition ANDREW S TANENBAUM Chapter 3 Memory Management Tanenbaum, Modern Operating Systems 3 e, (c)2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 3 Memory Management Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Memory management Memory(RAM)is an important and rare resource a Programs expand to fill the memory available to them Programmer's view a Memory should be private, infinitely large, infinitely fast, nonvolatile Reality a Best of people's mind: memory hierarchy a Register, cache, memory, disk, tape Memory manager a Efficiently manage memory a Keep track the free memory, allocate memory to programs
Memory Management ◼ Memory (RAM) is an important and rare resource ❑ Programs expand to fill the memory available to them ◼ Programmer’s view ❑ Memory should be private, infinitely large, infinitely fast, nonvolatile… ◼ Reality ❑ Best of people’s mind: memory hierarchy ❑ Register, cache, memory, disk, tape ◼ Memory manager ❑ Efficiently manage memory ❑ Keep track the free memory, allocate memory to programs…
Memory management The memory management in this chapter ranges from very simple to highly sophisticated
Memory management ◼ The memory management in this chapter ranges from very simple to highly sophisticated…
No Memory abstraction Early mainframe, early minicomputers, early personal computers had no memory abstraction 口 MOV REG|STER1.1000 a Here 1000 means move the content of physical memory address 1000 to register Impossible to have two programs in memory
No Memory Abstraction ◼ Early mainframe, early minicomputers, early personal computers had no memory abstraction… ❑ MOV REGISTER1, 1000 ❑ Here 1000 means move the content of physical memory address1000 to register ◼ Impossible to have two programs in memory
No Memory abstraction OXFFF Operatin Device system in drivers in rOm ROM User program program User program Operating Operating system in system in RAM RAM 0 0 0 (b) Figure 3-1. Three simple ways of organizing memory with an operating system and one user process Tanenbaum, Modern Operating Systems 3 e, (c)2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Figure 3-1. Three simple ways of organizing memory with an operating system and one user process. No Memory Abstraction Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Multiple problems without abstraction |BM360 a Memory divided into 2-KB blocks and each one with a 4-bit protection key a PSW also has a 4-bit protection key a Hardware will trap any attempt tries to access memory with a protection code different from PSW key
Multiple problems without abstraction ◼ IBM 360 ❑ Memory divided into 2-KB blocks and each one with a 4-bit protection key ❑ PSW also has a 4-bit protection key ❑ Hardware will trap any attempt tries to access memory with a protection code different from PSW key
Multiple Programs Without Memory Abstraction Drawback CMP 16412 16408 16400 16396 16388 JMP2816384 16380 16380 16380 MOV MOV 20 20 12 MP240 JMP 280 JMP240 Figure 3-2. Illustration of the relocation problem Tanenbaum, Modern Operating Systems 3 e, (c)2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Figure 3-2. Illustration of the relocation problem. Multiple Programs Without Memory Abstraction: Drawback Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Drawback of no abstraction Problem is that both programs reference absolute pnysical memory People hope that they can have a private space, that is addresses local to it BM360 a Modify the second program on the fly as it loaded it into memory a static re|ocatⅰon When a program is loaded into 16384, then the constant is added to every address Slow down loading needs extra information No abstraction memory still used in embedded and smart systems
Drawback of no abstraction ◼ Problem is that both programs reference absolute physical memory ◼ People hope that they can have a private space, that is, addresses local to it ◼ IBM 360 ❑ Modify the second program on the fly as it loaded it into memory ❑ Static relocation ◼ When a program is loaded into 16384, then the constant is added to every address ◼ Slow down loading, needs extra information ◼ No abstraction memory still used in embedded and smart systems
Abstraction: address space a Not to expose physical address to programmers o Crash OS 口 Hard to parallelize Two problems to solve a Protection a Relocation Address space aa set of memory processes can use to address memory a Each process has its own address space, independent of each other How?
Abstraction: address space ◼ Not to expose physical address to programmers ❑ Crash OS ❑ Hard to parallelize ◼ Two problems to solve: ❑ Protection ❑ Relocation ◼ Address space: ❑ A set of memory processes can use to address memory ❑ Each process has its own address space, independent of each other ❑ How?
D ynamic relocation Equip CPU with two special register: base and limit a Program be loaded into a consecutive space a No relocation during loading a When process is run and reference an address CPU automatically adds the base to that address as well as check whether it exceeds the limit register
Dynamic relocation ◼ Equip CPU with two special register: base and limit ❑ Program be loaded into a consecutive space ❑ No relocation during loading ❑ When process is run and reference an address, CPU automatically adds the base to that address; as well as check whether it exceeds the limit register