Beruflich Dokumente
Kultur Dokumente
Stack
Lots of separate processes
Heap
(Reserved for OS)
Uninitialized vars
(BSS segment)
Initialized vars Stack
(data segment)
Code
(text segment)
Heap
MMU
Uninitialized vars
(Reserved for OS)
(BSS segment)
Initialized vars
Stack (data segment)
Code
(text segment)
Heap
Uninitialized vars
(BSS segment)
Initialized vars
(data segment)
Code
(text segment)
Physical RAM
Memory resident VP 4
page table VP 6
(RAM) VP 7
Copyright : University of Illinois CS 241 Staff 3
Page Hit
n Reference to VM address that is in physical
memory (RAM hit)
Physical memory
Physical page (RAM)
Virtual address
number or
VP 1 PP 0
P disk address
VP 2
PTE 0 0 null
VP 7
1 VP 4 PP 3
1
0
1 Disk
0 null
VP 1
0
PTE 7 1 VP 2
Memory resident VP 3
page table VP 4
(RAM) VP 6
Memory resident VP 3
page table VP 4
(RAM) VP 6
Memory resident VP 3
page table VP 4
(RAM) VP 6
Memory resident VP 3
page table VP 4
(RAM) VP 6
Memory resident VP 3
page table VP 4
(RAM) VP 6
Memory resident VP 3
page table VP 4
(RAM) VP 6
page size 4KB=212 (232-12)x 4bytes =4MB size of page table TOO BIG!
n Suppose
4KB (212) page size, 64-bit address
space, 8-byte PTE
n How big does the page table need to
be?
n Suppose
4KB (212) page size, 64-bit address
space, 8-byte PTE
n How big does the page table need to
be?
32,000 TB!
264 * 2-12 * 23 = 255 bytes
n Most virtual memory schemes use a two-level (or more) scheme to store
large page tables in kernel memory and second level can be swapped out to
disk rather than always being in physical memory
First level is a root page table (always in kernel memory) and each of its entries
points to a second level page table stored in kernel memory (if allocated) or
swapped out to disk
If root page table has X entries and each 2nd level page table has Y entries, then
each process can have up to X*Y pages
Size of each second level page table is equal to the page size
Virtual address
Page number Offset
addresses a byte
in Physical Mem.
Two level page table hierarchy
Level 2 Physical memory
Level 1 0
VP 0
page table page tables
...
PTE 0 PTE 0 2048 allocated
VP 1023
PTE 1 ... VM pages for
VP 1024
PTE 2 (null) PTE 1023 code and data
...
PTE 3 (null)
VP 2047
PTE 4 (null) PTE 0
PTE 5 (null) ...
PTE 6 (null) PTE 1023 6K unallocated
PTE 7 (null) Gap VM pages
PTE 8
1023 null
(9 - 1K) PTEs
null PTEs 1023 1023 unallocated
PTE 1023
unallocated pages
pages
32 bit addresses 1 allocated
VP 9215
4KB pages, VM page
...
4-byte PTEs Copyright : University of Illinois CS 241 Staff for the stack 16
Multilevel Page Tables
n What happens on a page fault?
MMU looks up index in root page table to get 2nd level
page table
MMU tries to access 2nd level page table
n May result in another page fault to load the 2nd level page
table!
MMU looks up index in 2nd level page table to retrieve
physical page address and loads the page in physical
memory from disk
CPU re-executes the faulty instruction and accesses
the physical memory address
Copyright : University of Illinois CS 241 Staff 17
Multilevel Page Tables
n Issue
Page translation has very high overhead
Up to three memory accesses plus two disk I/Os
n If match is valid, the frame # is taken from TLB without going through
page table.
File descriptor
Shared memory
fd Object (/shm_obj) Copyright : University of Illinois CS 241 Staff 25
Paging as a tool for protection
and sharing
Process 1 Physical Process 2 n Process 1 creates a
virtual memory memory virtual memory shared memory object
/shm_obj (with
shm_open)
n Process 1 maps
/shm_obj in its virtual
address space using
mmap
File descriptor
Shared memory
fd Object (/shm_obj) Copyright : University of Illinois CS 241 Staff 26
Paging as a tool for protection
and sharing
Process 1 Physical Process 2 n Process 2 opens the
virtual memory memory virtual memory same shared memory
object /shm_obj (with
shm_open)
n Process 2 maps
/shm_obj in its virtual
address space using
mmap
File descriptor
Shared memory
fd Object (/shm_obj) Copyright : University of Illinois CS 241 Staff 27
Protection + Sharing Example
n fork() creates exact copy of a process
Lots more on this next week
n When we fork a new process, all of the memory is
duplicated for the child
Does it make sense to make a copy of all of its memory?
What if the child process doesn't end up touching most of
the memory the parent was using?
Parent Child
Parent's Child's
(Reserved for OS) (Reserved for OS)
page tbl page tbl
Stack Stack
Heap Heap
Uninitialized Uninitialized
vars vars
Initialized vars Initialized vars
Code Code
Parent Child
Parent's Child's
(Reserved for OS) (Reserved for OS)
page tbl page tbl
Stack Stack
Heap Heap
Uninitialized Uninitialized
vars vars
Initialized vars Initialized vars
Code Code
Parent Child
Parent's Child's
(Reserved for OS) (Reserved for OS)
page tbl page tbl
Stack Stack
Heap Heap
Uninitialized Uninitialized
vars vars
Initialized vars Initialized vars
Code Code
Heap Heap
Uninitialized Uninitialized
vars vars
Initialized vars Copy page Initialized vars
Code Code
Heap RW Heap
Uninitialized Uninitialized
vars vars
Initialized vars Copy page Initialized vars
Code Code
Stack
Same page
Shell #2 table mapping!
Heap (Reserved for OS)
! code shares
the same
Uninitialized
vars Stack physical frames
Initialized vars in main memory
Code for shell
Code
Heap
Uninitialized
vars
Initialized vars
Code