System-Programming Paging
System-Programming Paging
Paging
Problem:
Fragmentation
Definition: Free memory that can’t be usefully allocated
Why?
• Free memory (hole) is too small and scattered
• Rules for allocating memory prohibit using this free space
Types of fragmentation
• External: Visible to allocator (e.g., OS)
• Internal: Visible to requester (e.g., if must allocate at some granularity)
Segment D
Paging
Goal: Eliminate requirement that address space is contiguous
• Eliminate external fragmentation
• Grow segments as needed
Idea: Divide address spaces and physical memory into fixed-sized pages
• Size: 2n, Example: 4KB
• Physical page: page frame
Physical View
Process 1 Process 3
Process 2
Logical View
Translation of
Page Addresses
• How to translate logical address to physical address?
• High-order bits of address designate page number
• Low-order bits of address designate offset within page
translate
16 bytes 4
1 KB 10
1 MB 20
512 bytes 9
4 KB 12
Quiz: Address Format
Given number of bits in virtual address and bits for offset,
how many bits for virtual page number?
16 bytes 4 10 6
1 KB 10 20 10
1 MB 20 32 12
512 bytes 9 16 5 7
4 KB 12 32 20
Correct?
Quiz: Address Format
Given number of bits for vpn, how many virtual pages can there be in an address space?
Page Size Low Bits Virt Addr Bits High Bits Virt Pages
(offset) (vpn)
16 bytes 4 10 6 64
1 KB 10 20 10 1K
1 MB 20 32 12 4K
512 bytes 9 16 5 32
4 KB 12 32 20 1 MB
VirtUAL => Physical PAGE
Mapping
VPN offset
Number of bits in 0 1 0 1 0 1
virtual address
format does not
need to equal Addr Mapper
number of bits in
physical address
format
1 0 1 1 0 1 0 1
PPN offset
How should OS translate VPN to PPN?
P1 P2 P3
Virt Mem
Phys Mem
Quiz:
Fill in Page Table
P1 P2 P3
Virt Mem
Phys Mem
0 1 2 3 4 5 6 7 8 9 10 11
P1 P2 P3
3 0 8
1 4 5
Page Tables: 7 2 9
10 6 11
Where Are Pagetables
Stored?
How big is a typical page table?
- assume 32-bit address space
- assume 4 KB pages
- assume 4 byte entries