Escolar Documentos
Profissional Documentos
Cultura Documentos
Spring 2019
Memory Management
1
Memory Management
• Ideally programmers want memory that is
• large
• fast
• non volatile
• Memory hierarchy
• small amount of fast, expensive memory – cache
• some medium-speed, medium price main memory
• Lots of slow, cheap disk storage
2
Typical Memory Hierarchy
SMALLER
FASTER
SLOWER BIGGER
3
Basic Memory Management
"Mono-programming" without Swapping or Paging
5
Relocation and Protection
• Problem: A programmer doesn’t
know where a program will be LIMIT
loaded in memory
Relative Addresses in
• address locations of variables and
code routines cannot be absolute original program binary
• must keep a program out of other
processes’ partitions 0
• Solution: Use base and limit
values Physical
• Relocation MAX
• Address locations in a program are BASE +
relative. LIMIT Relocated Addresses
• They are added to a base value to
map to physical addresses. in Executing Binary
• Protection
BASE
• Access to address locations larger
than limit value results in an error
0
6
What if physical memory is not enough to hold all
processes?
— Swapping
in the system.
Entire
• In such cases swapping an entire process Physical RAM
is not enough.
12
Page Table
• The OS maintains
• One page table per userspace
process.
• And usually another page table
for kernel memory.
13
Question
• Consider a machine that has a 32-bit virtual address space
and 4KByte page size.
14
Translating
Virtual address (VA) to physical address (PA)
Virtual Address Space Physical RAM
Byte Address =
Page Number x Page Size +
Byte Offset in the page
6
Byte Offset
VA = VPN x Page Size + Byte Offset
5
PA = PPN x Page Size + Byte Offset
4
Virtual
3
Physical
Page 2
2 Page (frame)
Numbers Byte Offset
Numbers
(VPN)
(PPN)
1
1
0
0
Question
• Consider a machine that has a 32-bit virtual address space
and 4KByte page size.
16
Translating
Virtual address (VA) to physical address (PA)
Virtual Address Space Physical RAM
Byte Address =
Page Number x Page Size +
Byte Offset in the page
6
Byte Offset
VA = VPN x Page Size + Byte Offset
5
PA = PPN x Page Size + Byte Offset
4
Virtual
3
Physical
Page 2
2 Page (frame)
Numbers Byte Offset
Numbers
(VPN)
(PPN)
1
1
0
0
Virtual Address Translation
For Small Address Space
1.What is the total size (in bytes) of the virtual address space
for each process?
19
Quiz Answers
• Consider a machine that has a 32-bit virtual address space and 4KByte
page size.
1. Total size (in bytes) of the virtual address space for each process =
2^32 = 4 * 1024 * 1024 *1024 bytes = 4 GB
3. How many bits in a 32-bit address represent the byte offset into a
page?
• log2(8KB) = log2(2^13) = 13
• Also, 32 – 19 = 13 bits
20