memory management 1 tanenbaum ch. 3 silberschatz ch. 8,9

40
Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

Upload: marilyn-walker

Post on 02-Jan-2016

222 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

Memory Management 1

Tanenbaum Ch. 3

Silberschatz Ch. 8,9

Page 2: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 2

Background

System

User 1

User 2

User 3

Page 3: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 3

Creating an Executable File

prog.c

Page 4: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 4

Creating an Executable File

prog.c

prog.o

sqrt.c

Compiler Compiler

sqrt.o

Page 5: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 5

Creating an Executable File

prog.c

Linker

prog.o

prog.exe

sqrt.c

Compiler Compiler

sqrt.o

Library

Page 6: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 6

Address Binding

• Compile Time– Specify the physical memory locations during the

compile.

• Load Time– Determine physical addresses when all modules are

combined into a load module and loaded into memory

• Execution Time– Bind addresses when module is executed (to allow

flexibility in moving process during execution).

Page 7: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 7

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

Page 8: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 8

Figure 3-2. Illustration of the relocation problem.

Multiple Programs Without Memory Abstraction

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

Page 9: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 9

Hardware support for relocation

CPU <

LimitRegister

RelocationRegister

+Memory

addressingerror:

Page 10: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 10

Hardware support for relocation

CPU <

LimitRegister

RelocationRegister

+Memory

addressingerror:

Page 11: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 11

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

Figure 3-3. Base and limit registers can be used to give each process a separate address space.

Base and Limit Registers

Page 12: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 12

Swapping

• Move a currently executing process temporarily out of memory and into a backing store to make room for a new (higher priority?) process.

• Typically uses load time binding, but can use execution time binding.

• Context switching time can be high– 100k / 1000k = 100 milliseconds

Page 13: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 13

Figure 3-4. Memory allocation changes as processes come into memory and leave it. The shaded regions are unused memory.

Swapping (1)

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

Page 14: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 14

Figure 3-5. (a) Allocating space for growing data segment. (b) Allocating space for growing stack, growing data segment.

Swapping (2)

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

Page 15: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 15

Manage Free Memory

• With Bit Maps

• With Linked Lists

Page 16: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 16

Figure 3-6. (a) A part of memory with five processes and three holes. The tick marks show the memory allocation units. The

shaded regions (0 in the bitmap) are free. (b) The corresponding bitmap. (c) The same information as a list.

Memory Management with Bitmaps

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

Page 17: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 17

Figure 3-7. Four neighbor combinations for the terminating process, X.

Memory Management with Linked Lists

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

Page 18: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 18

Early Memory Management Techniques

• Fixed Partitioning– Simple to Implement but inefficient use of

memory

• Dynamic Partitioning– No internal fragmentation, but inefficient use of

processor

Page 19: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 19

Fixed Partitioning

OS

8 meg

8 meg

8 meg

8 meg

8 meg

8 meg

8 meg

Page 20: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 20

Fixed Partitioning

OS

8 meg

8 meg

8 meg

8 meg

8 meg

8 meg

8 meg

OS

8 meg

8 meg

12 meg

16 meg

6 meg4 meg2 meg

Page 21: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 21

Dynamic Partitioning

• Was used by IBM (OS/MVT)

• Create partitions when neededOS

P1

P2

P3

Page 22: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 22

Dynamic Partitioning

• Was used by IBM (OS/MVT)

• Create partitions when neededOS OS

P1 P1

P2

P3 P3

!P2

Page 23: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 23

Dynamic Partitioning

• Was used by IBM (OS/MVT)

• Create partitions when neededOS OS OS

P1 P1 P1

P2

P3

P4

P3 P3

!P2 P4

Page 24: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 24

Dynamic Partitioning

• Was used by IBM (OS/MVT)

• Create partitions when neededOS OS OS OS

P1 P1 P1

P2

P3

P4

P3 P3 P3

P4!P2 P4 !P1

Page 25: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 25

Dynamic Partitioning

• Was used by IBM (OS/MVT)

• Create partitions when neededOS OS OS OS OS

P1 P1 P1P5

P2

P3 P3 P3 P3 P3

P4 P4!P2 P4 !P1 P5

P4

Page 26: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 26

Placement Algorithms• First-fit

– Use the first available hole that will work

• Next-fit– Search continues from where last allocation was made

• Best-fit– Consider all available holes and use the one that most closely fits.

• Worst-fit– Consider all available holes and use the one that leaves the largest

remaining free hole.

• Quick Fit– Maintain separate lists of more common sizes

Page 27: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 27

Logical vs. Physical Address Space

• Logical Address– Referred to in executing programs– Generated by CPU (also known as virtual address)

• Physical address– Refers to an actual storage location in memory.

• Memory Management is the process of mapping logical addresses to the appropriate physical address.

• Relocation register used to map between domains

Page 28: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 28

Paging

• Difficult to find memory holes large enough to satisfy new process needs.

• Simplify the problem: Break the process memory requirements into many smaller sized lots.

• Divide physical memory into fixed size blocks called frames (typically 512 to 16 meg)

• Divide logical memory (process memory needs) into same sized blocks called pages

• Allocate as many frames as needed

Page 29: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 29

Address Translation Architecture

CPU PhysicalMemory

PageTable

f

logical address physical address

Page 30: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 30

Address Translation Architecture

CPU PhysicalMemory

PageTable

p dd

f

p{

logical address physical address

Page 31: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 31

Address Translation Architecture

CPU PhysicalMemory

PageTable

p dfd

f

p{

logical address physical address

Page 32: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 32

Paging Example

Page 0

Page 1

Page 2

Page 3

Page 0

Page 1

Page 2

Page 3

1437

0123

logicalmemory

pagetable

physicalmemory

0

1

2

3

4

5

6

7

Page 33: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 33

Paging Example

Page 0

Page 1

Page 2

Page 3

Page 0

Page 1

Page 2

Page 3

1437

0123

logicalmemory

pagetable

physicalmemory

0

1

2

3

4

5

6

7

Page 34: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 34

Paging Example

Page 0

Page 1

Page 2

Page 3

Page 0

Page 1

Page 2

Page 3

1437

0123

logicalmemory

pagetable

physicalmemory

0

1

2

3

4

5

6

7

Page 35: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 35

Figure 3-8. The position and function of the MMU – shown as being a part of the CPU chip (it commonly is nowadays).

Logically it could be a separate chip, was in years gone by.

Virtual Memory – Paging

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

Page 36: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 36

Figure 3-10. The internal operation of the MMU with 16 4-KB pages.

Paging

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

Page 37: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 37

Figure 3-11. A typical page table entry.

Structure of Page Table Entry

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

Page 38: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 38

Paging implementation issues:

• The mapping from virtual address to physical address must be fast.

• If the virtual address space is large, the page table will be large.

Speeding Up Paging

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

Page 39: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 39

Summary

• Memory Management Background

• Memory Partitioning

• Paging

Page 40: Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9

cs431-cotter 40

Questions• Explain the difference between logical address space

and physical address space. Which parts of a computer system use logical addresses and which parts use physical addresses?

• When considering dynamic memory partitioning, what is the major disadvantage of the “best fit” algorithm? What is the advantage of the “worst fit” algorithm?

• How (where) is virtual memory managed in contemporary computer systems?

• In an MMU why would we ever want to disable caching?• The book suggests that page sizes range from 512 bytes

to perhaps 64kbytes. What are the advantages of a small page size? When is a large page size preferred?