Recap: Translation Box (MMU)
Recap: Translation Box (MMU)
virtual physical
n Options
address address n Base and Bounds
Translation Box
CPU
n Segmentation
(MMU) physical n Paging
memory
n Multilevel translation
n Paged page tables
n Inverted page tables
Data read or write
(untranslated)
1
Segmentation Segmentation (contd.)
n Motivation
separate the virtual address space into several segments so that we can Virtual address
n error
share some of them if necessary segment offset >
n A segment is a region of logically contiguous memory n Have a table of (seg, size)
seg size n Protection: each entry has
n Main idea: generalize base and bounds by allowing a table of
(nil,read,write)
base&bound pairs
n
..
(assume 2 bit segment ID, 12 bit segment offset) . n On a context switch:
save/restore the table or a
virtual segment # physical segment start segment size pointer to the table in kernel
memory
code (00) 0x4000 0x700
+ n Pros: Efficient, easy to share
data (01) 0 0x500
- (10) 0 0 n Cons: Complex management
stack (11) 0x2000 0x1000 physical address and fragmentation within a
segment
3fff
2
Address space in Nachos Paging
0xfff high address n Motivations
stack n both branch & bounds and segmentation still require fancy memory
segment management (e.g., first fit, best fit, re-shuffling to coalesce free
fragments if no single free space is big enough for a new segment)
data uninitialized data (Heap + BSS) n can we find something simple and easy
segment ----------------------
initialized data n Solution
main
n allocate physical memory in terms of fixed size chunks of memory,
memory or pages.
text
n Simpler because it allows use of a bitmap: 00111110000001100
segment
n each bit represents one page of physical memory
(code)
n 1 means allocated, 0 means unallocated
0x000 low address
address entry point for __start
translation
3
Two-level paging example How many PTEs do we need ?
n A logical address (on 32-bit machine with 4K page size) is divided n Worst case for 32-bit address machine
into: n # of processes × 220 (if page size is 4096 bytes)
n a page number consisting of 20 bits.
n a page offset consisting of 12 bits.
n Since the page table is paged, the page number is further divided
n What about 64-bit address machine?
into: n # of processes × 252
n a 10-bit page table number.
n a 10-bit page table offset.
n Thus, a logical address is as follows: n Solutions:
n Well, it is mostly unused…
page number page offset
n Paged page tables
pi p2 d
10 10 12
where pi is an index into the outer page table, and p2 is the
displacement within the page of the outer page table.
Virtual address
VPage # offset