83
1 Memory Management Chapter 3 Part 1

Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

1

Memory Management

Chapter 3 �

Part 1

Page 2: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

2

Outline of Chapter 3

• Basic memory management • Swapping • Virtual memory • Page replacement algorithms • Modeling page replacement algorithms • Design issues for paging systems • Implementation issues • Segmentation

in this file

Page 3: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

3

The Memory Hierarchy

Ideally programmers want memory that is... Large Fast Non volatile

Memory Hierarchy Small amount of fast, expensive memory -- cache Some medium speed, medium priced -- main memory Gigabytes of slow, cheap storage -- disk

Memory Manager manages the hierarchy

Page 4: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

4

Simplest Memory Organization

Monoprogramming One user program at a time Plus the OS

No protection

Page 5: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

5

Simplest Memory Organization

Palm OS Mainframes MS Dos

Page 6: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

6

Multiprogramming with Fixed Partitions

Main memory divided into “partitions” Done once, e.g., at startup

To run a program... Select a partition (Must find one that is large enough) Put program into partition

Not enough memory for all runnable programs? The “input queue” A list of programs waiting to be run

Page 7: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

7

Multiprogramming with Fixed Partitions

Page 8: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

8

Modelling Multiprogramming

Assume each process... 20% - computing 80% - waiting on I/O

Each process spends some fraction of time waiting p = .8

Many processes are running N = Degree of multiprogramming (e.g., N = 5 procs)

The probability that all processes are waiting for I/O pN

CPU Utilization 1 - pN

Page 9: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

9

CPU Utilization

CPU utilization as a function of number of processes in memory:

Degree of multiprogramming

CPU

Util

izat

ion

(in p

erce

nt)

Page 10: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

10

Analysis of System Performance

Example: 4 jobs Each job has 20% compute and 80% wait time Each job arrives at a different time

Job Arrival Time Total CPU minutes needed 1 10:00 4 2 10:10 3 3 10:15 2 4 10:20 2

Page 11: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

11

Analysis of System Performance

Page 12: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

12

Relocation and Protection

Cannot know ahead of time where in memory a program will be loaded.

Compiler produces code containing embedded addresses. These addresses cannot be absolute!

Linker combines pieces of the program. Assumes the program will be loaded at address 0.

Option 1: Modify the addresses at load-time

Option 2: Modify the addresses at run-time

Protection: Keep program A out of program B’s partition

Page 13: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

13

Base and Limit Registers

The simplest scheme These 2 registers describe a partition. Every address generated at runtime... Compare to the limit register (& abort if larger) Add to the base register to give physical memory address

Multiprogramming Each process is in a partition Context switch? Load new values into base and limit

OS

Partition A

Partition B Partition C Partition D Partition E

base

limit

Page 14: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

14

Swapping

When a program is running... • The entire program must be in memory. • Each program is put into a single partition.

When the program is not running... • May remain resident in memory • May get “swapped” out to disk.

Over time... • Programs come into memory • Programs leave memory get “swapped out”

Page 15: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

15

Swapping

asd

Shaded regions are unused

Time

Page 16: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

16

Swapping

Programs may want to grow during execution. More room for stack More room for heap allocation ...Etc...

Problem: The partition is too small. Must move programs around... Ugh!

Idea: Make the partitions a little larger than necessary. Can accommodate some growth easily!

Page 17: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

17

Swapping

Page 18: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

18

Managing Memory

Divide main memory into chucks Bytes <----> pages

Each chunk is either • Unused (“free”) • Used by some process

Operations • Find a chunk of unused memory (big enough to hold a new process) • Return a chunk of memory to the free pool (after a process terminates / is swapped out)

Page 19: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

19

Managing Memory with Bit Maps

Technique #1: Bit Map A long bit string One bit for every chunk of memory 1 = in use 0 = free Size of allocation unit is an issue Example: chunk size = 32 bits overhead for bit string: 1/33 = 3% Example: chunk size = 4Kbytes overhead for bit string: 1/32,769

Page 20: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

20

Managing Memory with Bit Maps

Page 21: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

21

Managing Memory with Linked Lists

Technique #2: Linked List Keep a list of elements Each element describes one chunk of memory • Free / In-use Bit (“P=process, H=hole”) • Starting address • Length • Pointer to next element

Page 22: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

22

Managing Memory with Linked Lists

0

Page 23: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

23

Merging Holes

Whenever a chunk of memory is freed... we want to merge adjacent holes!

Page 24: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

24

Merging Holes

Whenever a chunk of memory is freed... we want to merge adjacent holes!

Page 25: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

25

Merging Holes

Whenever a chunk of memory is freed... we want to merge adjacent holes!

Page 26: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

26

Merging Holes

Whenever a chunk of memory is freed... we want to merge adjacent holes!

Page 27: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

27

Managing Memory with Linked Lists

Need to find a hole? (...big enough for some new process) Search the list! • First Fit • Next Fit Start from current location in the list Not as good as first fit • Best Fit Find the smallest hole that will work Tends to create lots of little holes • Worst Fit Find the largest hole (remainder will be big) No good • Quick Fit Keep separate lists for common sizes

Page 28: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

28

Virtual Memory

With Swapping • The entire process must be in memory • Can’t run a program larger than physical memory!

Page 29: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

29

Virtual Memory

With Swapping • The entire process must be in memory • Can’t run a program larger than physical memory!

With Virtual Memory • Put only part of the program in memory. • Can run a program larger than physical memory!

Page 30: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

30

Virtual Memory

With Swapping • The entire process must be in memory • Can’t run a program larger than physical memory!

With Virtual Memory • Put only part of the program in memory. • Can run a program larger than physical memory!

The “working set” idea: • Normally, programs do not access all of their memory • Accesses tend to be concentrated within small regions • You only really need 16K to run a 16M program

Page 31: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

31

Virtual Memory

With Swapping • The entire process must be in memory • Can’t run a program larger than physical memory!

With Virtual Memory • Put only part of the program in memory. • Can run a program larger than physical memory!

The “working set” idea: • Normally, programs do not access all of their memory • Accesses tend to be concentrated within small regions • You only really need 16K to run a 16M program

The real benefit: Can get more runnable processes into memory at once!

Page 32: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

32

Memory Management Unit (MMU)

Page 33: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

33

Virtual Address Spaces and the Page Table

Here is the virtual address space (as seen by the process)

Lowest address

Highest address

Virtual Addr Space

Page 34: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

34

Virtual Address Spaces and the Page Table

Virtual Addr Space

Page 35: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

35

Virtual Address Spaces and the Page Table

The address spaces is divided into “pages” In BLITZ, the page size is 8K

Virtual Addr Space

0 1 2 3 4 5 6 7

N

Page Numbers (not addresses)

Page 36: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

36

Virtual Address Spaces and the Page Table

The address spaces is divided into “pages” In BLITZ, the page size is 8K

Page 0

Page N

Page 1

Virtual Addr Space

0 1 2 3 4 5 6 7

N

A Page

Page Numbers (not addresses)

Page 37: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

37

Virtual Address Spaces and the Page Table

In reality, only some of the process’s pages are in memory.

Virtual Addr Space

0 1 2 3 4 5 6 7

N

Not in memory

Page 38: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

38

Virtual Address Spaces and the Page Table

Physical memory is divided into “page frames” (Page size = frame size)

Physical memory Virtual Addr Space

0 1 2 3 4 5 6 7

N

A Frame

A Page

Page 39: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

39

Virtual Address Spaces and the Page Table

Some page frames are used for this process.

These frames are used for this process

Virtual Addr Space Physical memory

0 1 2 3 4 5 6 7

N

Page 40: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

40

Virtual Address Spaces and the Page Table

Some page frames are used for this process.

Used by other processes

Virtual Addr Space Physical memory

0 1 2 3 4 5 6 7

N

Page 41: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

41

Virtual Address Spaces and the Page Table

A “mapping” tells which frame holds which page

Virtual Addr Space Physical memory

0 1 2 3 4 5 6 7

N

Page 42: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

42

Virtual Address Spaces and the Page Table

The “Page Table” tells for each page... • is it in memory • if so, which frame

It has N entries.

Virtual Addr Space Physical memory

0 1 2 3 4 5 6 7

N

Page 43: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

Page Size 8 Kbytes

43

The BLITZ Architecture

Page 44: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

Page Size 8 Kbytes

Logical Addresses (“virtual addresses”) 24 bits --> 16 Mbyte virtual address space

An address:

44

The BLITZ Architecture

0 23

Page 45: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

45

The BLITZ Architecture

Page Size 8 Kbytes

Logical Addresses (“virtual addresses”) 24 bits --> 16 Mbyte virtual address space 2K Pages --> 11 bits

An address: 0 12 13 23 11 bits 13 bits

offset page number

Page 46: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

46

The BLITZ Architecture

Page Size 8 Kbytes

Logical Addresses (“virtual addresses”) 24 bits --> 16 Mbyte virtual address space 2K Pages --> 11 bits

An address:

Physical Addresses 32 bits --> 4 Gbyte installed memory (max)

0 12 13 23 11 bits 13 bits

offset page number

0 31

Page 47: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

47

The BLITZ Architecture

Page Size 8 Kbytes

Logical Addresses (“virtual addresses”) 24 bits --> 16 Mbyte virtual address space 2K Pages --> 11 bits

An address:

Physical Addresses 32 bits --> 4 Gbyte installed memory (max) 512K Frames --> 19 bits

0 12 13 23 11 bits 13 bits

offset page number

0 12 13 31 19 bits 13 bits

offset frame number

Page 48: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

48

The BLITZ Architecture

The Page Table Mapping: Page --> Frame

Virtual Address:

Physical Address:

0 12 13 23 11 bits

0 12 13 31 19 bits

Page 49: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

49

Example from Textbook

Page 50: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

50

The Page Table

An array of “page table entries” Kept in memory

2K pages in a virtual address space? ---> 2K entries in the table

Each entry is 4 bytes long 19 bits The Frame Number 1 bit Valid Bit 1 bit Writable Bit 1 bit Dirty Bit 1 bit Referenced Bit 9 bits Unused (and available for OS algorithms)

Page 51: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

51

The Page Table

0 12 13 31 frame number D R W V unused

dirty bit referenced bit

writable bit valid bit

19 bits

Page 52: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

52

The Page Table

0 12 13 31 frame number D R W V unused

frame number D R W V unused

frame number D R W V unused

frame number D R W V unused

frame number D R W V unused

0 1 2

2K

page table base register

Indexed by the page frame number

Page 53: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

53

The Page Table

0 12 13 23 page number offset

0 12 13 31 frame number D R W V unused

frame number D R W V unused

frame number D R W V unused

frame number D R W V unused

frame number D R W V unused

0 1 2

2K

page table base register virtual address

Page 54: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

54

The Page Table

0 12 13 23 page number offset

0 31

0 12 13 31 frame number D R W V unused

frame number D R W V unused

frame number D R W V unused

frame number D R W V unused

frame number D R W V unused

0 1 2

2K

page table base register virtual address

physical address

Page 55: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

55

The Page Table

0 12 13 23 page number offset

0 12 13 31 offset

0 12 13 31 frame number D R W V unused

frame number D R W V unused

frame number D R W V unused

frame number D R W V unused

frame number D R W V unused

0 1 2

2K

page table base register virtual address

physical address

Page 56: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

56

The Page Table

0 12 13 23 page number offset

0 12 13 31 offset

0 12 13 31 frame number D R W V unused

frame number D R W V unused

frame number D R W V unused

frame number D R W V unused

frame number D R W V unused

0 1 2

2K

page table base register virtual address

physical address

Page 57: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

57

The Page Table

0 12 13 23 page number offset

0 12 13 31 frame number offset

0 12 13 31 frame number D R W V unused

frame number D R W V unused

frame number D R W V unused

frame number D R W V unused

frame number D R W V unused

0 1 2

2K

page table base register virtual address

physical address

Page 58: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

58

The Page Table

Two registers in the CPU • Page Table Base Register • Page Table Length Register

These define the current page table. (Virtual address space is smaller? Use a smaller table!)

Bits in the CPU “status register” “System Mode” “Interrupts Enabled” “Paging Enabled” 1 = Perform page table translation for every memory access 0 = Do not do translation

Page 59: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

59

Internal Fragmentation

A process will fill several pages. The last page will be partially full. On average, last page will be half full.

This space is wasted, lost!!!

Example: 8K page size ---> 4K is wasted for every running process

Page 60: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

60

External Fragmentation

Memory is divided into chunks (“partitions”) Each partition has a different size. Processes are allocated space and later freed. After a while... Memory will be full of small holes.

Page 61: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

61

External Fragmentation

Memory is divided into chunks (“partitions”) Each partition has a different size. Processes are allocated space and later freed. After a while... Memory will be full of small holes.

Page 62: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

62

Page Size Issues

Choose a large page size More loss due to internal fragmentation Assume a process is using 5 regions of memory heavily ... Will need 5 pages, regardless of page size ---> Ties up more memory

Page 63: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

63

Page Size Issues

Choose a large page size More loss due to internal fragmentation Assume a process is using 5 regions of memory heavily ... Will need 5 pages, regardless of page size ---> Ties up more memory

Choose a small page size The page table will become very large Example: Virtual Address Space: 4G bytes Page Size: 4K (e.g., Pentium) Page table size: 1M entries! (4Mbytes)

Page 64: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

64

Multi-level Page Tables

Top-level Page table

2nd-level tables

frames in

memory • • •

Page 65: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

65

Multi-level Page Tables

A Virtual Address:

Top-level Page table

2nd-level tables

frames in

memory • • •

PT1 offset PT2 10-bits 10-bits 12-bits

Page 66: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

66

Multi-level Page Tables

A Virtual Address:

Top-level Page table

2nd-level tables

frames in

memory • • •

PT1 offset PT2 10-bits 10-bits 12-bits

Page 67: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

67

Multi-level Page Tables

A Virtual Address:

Top-level Page table

2nd-level tables

frames in

memory • • •

PT1 offset PT2 10-bits 10-bits 12-bits

Page 68: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

68

Multi-level Page Tables

A Virtual Address:

Top-level Page table

2nd-level tables

frames in

memory • • •

PT1 offset PT2 10-bits 10-bits 12-bits

Page 69: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

69

Multi-level Page Tables

A Virtual Address:

Top-level Page table

2nd-level tables

frames in

memory • • •

PT1 offset PT2 10-bits 10-bits 12-bits

Page 70: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

70

Multi-level Page Tables

A Virtual Address:

Top-level Page table

2nd-level tables

frames in

memory • • •

PT1 offset PT2 10-bits 10-bits 12-bits

Page 71: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

71

Multi-level Page Tables

Page 72: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

72

Translation Lookaside Buffers (TLBs)

Problem: MMU must go to page table for every memory access!

Page 73: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

73

Translation Lookaside Buffers (TLBs)

Problem: MMU must go to page table for every memory access!

Solution: Cache the page table entries Hardware cache in the MMU Small number of entries (e.g., 64) Each entry contains Page Number Other stuff from page table entry Associatively indexed On page number

Page 74: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

74

Translation Lookaside Buffers (TLBs)

Page Number Frame Number D R W V unused

50 D R W V unused

24 D R W V unused

19 D R W V unused

6 D R W V unused

23 17 92

12 5

37

Key

Other

Page 75: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

75

Translation Lookaside Buffers (TLBs)

0 12 13 23 page number offset

0 12 13 31 frame number offset

Page Number Frame Number D R W V unused

50 D R W V unused

24 D R W V unused

19 D R W V unused

6 D R W V unused

23 17 92

12

virtual address

physical address

5

37

Key

Other

Page 76: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

76

Translation Lookaside Buffers (TLBs)

0 12 13 23 page number offset

0 12 13 31 frame number offset

Page Number Frame Number D R W V unused

50 D R W V unused

24 D R W V unused

19 D R W V unused

6 D R W V unused

23 17 92

12

physical address

5

37

Key

Other

virtual address

Page 77: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

77

Translation Lookaside Buffers (TLBs)

0 12 13 23 page number offset

0 12 13 31 frame number offset

Page Number Frame Number D R W V unused

50 D R W V unused

24 D R W V unused

19 D R W V unused

6 D R W V unused

23 17 92

12

physical address

5

37

Key

Other

virtual address

Page 78: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

78

Translation Lookaside Buffers (TLBs)

0 12 13 23 page number offset

0 12 13 31 frame number offset

Page Number Frame Number D R W V unused

50 D R W V unused

24 D R W V unused

19 D R W V unused

6 D R W V unused

23 17 92

12

physical address

5

37

Key

Other

virtual address

Page 79: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

79

Translation Lookaside Buffers (TLBs)

0 12 13 23 page number offset

0 12 13 31 frame number offset

Page Number Frame Number D R W V unused

50 D R W V unused

24 D R W V unused

19 D R W V unused

6 D R W V unused

23 17 92

12

physical address

5

37

Key

Other

virtual address

Page 80: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

80

Translation Lookaside Buffers (TLBs)

What if the entry is not in the TLB? Go to page table Find the right entry Move it into the TLB Which entry to replace? Software trap -- Let OS deal with the problem Valid Bit Page tables become entirely a OS data structure!

Want to do a context switch? Must empty the TLB Just clear the “Valid Bit”

Page 81: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

81

64-Bit Virtual Addresses

Assume 4 Kbyte pages (12 bits) Virtual Space = 252 pages (page table too large!) Assume 256 Mbyte memory Can only have 64K pages in memory

Only need entries for the pages in memory

Page 82: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

82

64-Bit Virtual Addresses

Assume 4 Kbyte pages (12 bits) Virtual Space = 252 pages (page table too large!) Assume 256 Mbyte memory Can only have 64K pages in memory

Only need entries for the pages in memory

“Inverted Page Table” One entry for every frame in memory Tells which page is in that frame When running the program Given a virtual page, need the frame Search all pages? No Use an indexed, e.g., Hash table

Page 83: Memory Management - Computer Action Teamweb.cecs.pdx.edu/~Harry/Os/Slides/Ch3-MemMgmt-1.pdfMultiprogramming with Fixed Partitions ... Size of allocation unit is an issue Example: chunk

83

Inverted Page Table