Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf ·...

27
3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 26 Principles of Operating Systems CS 446/646 3. Memory Management a. Goals of Memory Management b. Partitioning c. Linking & Loading From object codes to executable in memory Loading: binding logical references to physical addresses Linking: weaving logical addresses together d. Simple Paging & Segmentation e. Virtual Memory f. Page Replacement Algorithms

Transcript of Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf ·...

Page 1: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 26

Principles of Operating SystemsCS 446/646

3. Memory Managementa. Goals of Memory Management

b. Partitioning

c. Linking & LoadingFrom object codes to executable in memoryLoading: binding logical references to physical addressesLinking: weaving logical addresses together

d. Simple Paging & Segmentation

e. Virtual Memory

f. Page Replacement Algorithms

Page 2: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3.c Linking & LoadingFrom object codes to executable

From source code to memory, via translating, linking and loading

Linkers and loadersa linker or “link editor” is a program that takes a collection of object modules (created by compilers or assemblers) and combines them into a single executable programa loader places the linked program in memory, possibly translating (relocating) addresses on the way

Memory

(Compiler(Compileror Assembler)or Assembler)

LoaderLoader

Tanenbaum, A. S. (1999) StructuredComputer Organization (4th Edition).

program

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 27

Page 3: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 28

3.c Linking & LoadingFrom object codes to executable

Positioning modules before linking and loading

Tanenbaum, A. S. (1999) StructuredComputer Organization (4th Edition).

Page 4: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 29

3.c Linking & LoadingFrom object codes to executable

Tanenbaum, A. S. (1999) StructuredComputer Organization (4th Edition).

Linking and relocating

relocation by base shift = 100

resolution of procedure reference& relocation

resolution of address reference& relocation by base shift + module A size = 500

Page 5: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 30

3.c Linking & LoadingLoading: binding logical references to physical addresses

Loading involves binding instructions and data to physical memory addresses

once an executable is finished compiling or is stored on disk, the loader places it in memorymodern systems allow a user process image to reside in any part of physical memorythree approaches to loading:

absolute loading = binding can be done beforehand, at compile time (writing once)relocatable loading = binding is done at load time (rewriting)dynamic runtime loading = binding is postponed until execution time (not writing)

Page 6: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 31

3.c Linking & LoadingLoading: binding logical references to physical addresses

Absolute load moduleStallings, W. (2004) Operating Systems:Internals and Design Principles (5th Edition).

Absolute loadingrequires that a given module always be loaded into the same location in memorythus, the compiler can bind symbolic addresses directly to absolute addressesthis was the case of the .COM format programs in MS-DOS

→ not acceptable: prevents swapping and/or multi-tasking, etc.

Page 7: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 32

3.c Linking & LoadingLoading: binding logical references to physical addresses

Relocatable load moduleStallings, W. (2004) Operating Systems:Internals and Design Principles (5th Edition).

Relocatable loadingwe need modules that can be located and relocated anywhere in memoryfor this, the compiler must produce relative addressesthen the task of the loader is basically to add one or several fixed offset(s) to all address referencesproblem: swapping in and out requires delocating and relocating every time

Page 8: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 33

3.c Linking & LoadingLoading: binding logical references to physical addresses

Dynamic runtime loadingphysical address binding does not happen until the very last moment, when the instruction is executeddone by special processor hardware (combined with protection)gives the most freedom

Stallings, W. (2004) Operating Systems:Internals and Design Principles (5th Edition).

Hardware support for relocation

Page 9: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 34

Principles of Operating SystemsCS 446/646

3. Memory Managementa. Goals of Memory Management

b. Partitioning

c. Linking & LoadingFrom object codes to executable in memoryLoading: binding logical references to physical addressesLinking: weaving logical addresses together

d. Simple Paging & Segmentation

e. Virtual Memory

f. Page Replacement Algorithms

Page 10: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 35

Principles of Operating SystemsCS 446/646

3. Memory Managementa. Goals of Memory Management

b. Partitioning

c. Linking & Loading

d. Simple Paging & SegmentationPagingHardware support for pagingSegmentation

e. Virtual Memory

f. Page Replacement Algorithms

Page 11: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3.d Simple Paging & SegmentationPaging

(Sub)divide and conquernew idea: partition process images, too, so that their physical domain doesn’t have to be contiguous anymore

memory is partitioned into small, equal-size chunksprocess images or also subdivided into the same size chunks

the chunks of a process are called pages and chunks of memory are called framesthe O/S maintains a page table for each process

Page 12: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 37

3.d Simple Paging & SegmentationPaging

Stallings, W. (2004) Operating Systems:Internals and Design Principles (5th Edition).

Page 13: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 38

3.d Simple Paging & SegmentationPaging

Stallings, W. (2004) Operating Systems:Internals and Design Principles (5th Edition).

Page 14: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 39

3.d Simple Paging & SegmentationPaging

Silberschatz, A., Galvin, P. B. and Gagne. G. (2003)Operating Systems Concepts with Java (6th Edition).

Page 15: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 40

3.d Simple Paging & SegmentationPaging

Silberschatz, A., Galvin, P. B. and Gagne. G. (2003)Operating Systems Concepts with Java (6th Edition).

Page 16: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 41

3.d Simple Paging & SegmentationPaging

Silberschatz, A., Galvin, P. B. and Gagne. G. (2003)Operating Systems Concepts with Java (6th Edition).

Page 17: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 42

3.d Simple Paging & SegmentationHardware support for paging

Stallings, W. (2004) Operating Systems:Internals and Design Principles (5th Edition).

Page 18: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 43

3.d Simple Paging & SegmentationHardware support for paging

Stallings, W. (2004) Operating Systems:Internals and Design Principles (5th Edition).

Page 19: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 44

3.d Simple Paging & SegmentationHardware support for paging

Silberschatz, A., Galvin, P. B. and Gagne. G. (2003)Operating Systems Concepts with Java (6th Edition).

Page 20: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 45

3.d Simple Paging & SegmentationSegmentation

Silberschatz, A., Galvin, P. B. and Gagne. G. (2003)Operating Systems Concepts with Java (6th Edition).

Page 21: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 46

3.d Simple Paging & SegmentationSegmentation

LogicalLogical

Tanenbaum, A. S. (1999) StructuredComputer Organization (4th Edition).

Page 22: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 47

3.d Simple Paging & SegmentationSegmentation

Tanenbaum, A. S. (1999) StructuredComputer Organization (4th Edition).

Page 23: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 48

3.d Simple Paging & SegmentationSegmentation

Silberschatz, A., Galvin, P. B. and Gagne. G. (2003)Operating Systems Concepts with Java (6th Edition).

Page 24: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 49

3.d Simple Paging & SegmentationSegmentation

must also have: offset < length

Stallings, W. (2004) Operating Systems:Internals and Design Principles (5th Edition).

Page 25: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 50

3.d Simple Paging & SegmentationSegmentation

Silberschatz, A., Galvin, P. B. and Gagne. G. (2003)Operating Systems Concepts with Java (6th Edition).

Page 26: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 51

3.d Simple Paging & SegmentationSegmentation

Silberschatz, A., Galvin, P. B. and Gagne. G. (2003)Operating Systems Concepts with Java (6th Edition).

Page 27: Principles of Operating Systems - Freedoursat.free.fr/docs/CS446_S06/CS446_S06_3_Memory2.pdf · 3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 36

3/7-16/2006 CS 446/646 - Principles of Operating Systems - 3. Memory Management 52

Principles of Operating SystemsCS 446/646

3. Memory Managementa. Goals of Memory Management

b. Partitioning

c. Linking & Loading

d. Simple Paging & SegmentationPagingHardware support for pagingSegmentation

e. Virtual Memory

f. Page Replacement Algorithms