Memory Management - Computer Action...
Transcript of Memory Management - Computer Action...
![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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/1.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/2.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/3.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/4.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/5.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/6.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/7.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/8.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/9.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/10.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/11.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/12.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/13.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/14.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/15.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/16.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/17.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/18.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/19.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/20.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/21.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/22.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/23.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/24.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/25.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/26.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/27.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/28.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/29.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/30.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/31.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/32.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/33.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/34.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/35.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/36.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/37.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/38.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/39.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/40.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/41.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/42.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/43.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/44.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/45.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/46.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/47.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/48.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/49.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/50.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/51.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/52.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/53.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/54.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/55.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/56.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/57.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/58.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/59.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/60.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/61.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/62.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/63.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/64.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/65.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/66.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/67.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/68.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/69.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/70.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/71.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/72.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/73.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/74.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/75.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/76.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/77.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/78.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/79.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/80.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/81.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/82.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022041012/5ebfed3c28ae851b94380e14/html5/thumbnails/83.jpg)
83
Inverted Page Table