Beruflich Dokumente
Kultur Dokumente
Idan Shatz
Unix’s Method
Ready?
The Big Picture
A process
Swap Device
0 Page 0
Page 1 0 block 0
Page 2 block 1
Page 3 block 2
Main (Physical) Memory
0 Frame 0
4GB Page n Frame 1
Frame 2
A process Page in
0 Page 0 Page out
Page 1 128MB Frame m
Page 2
Page 3
1GB block p
4GB Page n
The Unix Big Picture
A process
Swap Device
0 Page 0
0 block 0
Region Page 1
Region
Page D.B.D. block 1
Table Page 2
Table Page D.B.D.
PageTable
3
Table Table
Table block 2
Main (Physical) Memory
Page
Page D.B.D.
D.B.D.
0 Frame 0 Swap-use
PFdata Swap-use
Table Table
Table Frame PFdata
1
4GB Page Table
n Table
Table
Table
Frame 2Table
A process Page in
0 Page 0 Page out
Region Page 1
Region 128MB Frame m
Page D.B.D.
Table Page 2Page
Table D.B.D.
Page Table
3Table Table
Table
Page
Page D.B.D.
D.B.D.
Table Table 1GB block p
4GB Page nTable Table
Tables
Region table
Text, Data, Stack (per process)
Page table
Virtual Physical translation (per process)
Disk Block Descriptor (DBD) table
Disk location of swapped pages (per process)
PFData (Page Frame) table
Description of physical frame status (singleton)
Swap in-use table
The same as PFData, but for the swap file
(singleton)
Process Memory
static allocation
Data
dynamic allocation
Stack
4GB
Region Table
0
Region table
Text
static allocation
Data
dynamic allocation
Start Region
Permissions
Address Size
Stack
4GB
Pages and Frames
Virtual Memory
0 Main (Physical) Memory
0
process address space
Text
static allocation
Data
16MB
dynamic allocation
Frame (4k)
Stack
Page
4GB
Page Table
page table
Page 0
region table Page 1
Text Page 2
Data …
Stack Page N-2
Page N-1
Start Region
Permissions
Address Size
Valid Physical
Permissions Ref Mod COW Age
Flag Address
The Unix Big Picture
A process
Swap Device
0 Page 0
0 block 0
Region Page 1
Region
Page block 1
Table Page 2
Table Page
PageTable
3
Table block 2
Main (Physical) Memory
Page
Page 0 Frame 0
Table Frame 1
4GB Page Table
n
Frame 2
A process Page in
0 Page 0 Page out
Region Page 1
Region 128MB Frame m
Page
Table Page 2Page
Table
Page Table
3Table
Page
Page
Table 1GB block p
4GB Page nTable
Translation from Virtual to Physical address
Virtual Address
region table
Text page table
Data
Page 0
Stack
Page 1
Page 2
…
StartTranslation
Region (Boooo)
Permissions Page N-2
Address Size
Page N-1
Valid Physical
Permissions Ref Mod COW Age
Flag Address
Physical Address
Translation from Virtual to Physical address
Virtual Address offset
region table
Text page table
= Data
Page 0
Stack
Page 1
Page 2
…
Start Region
Permissions Page N-2
Address Size
Page N-1
Valid Physical
Permissions Ref Mod COW Age
Flag Address
Valid Physical
Permissions Ref Mod COW Age
Flag Address
Valid Physical
Permissions Ref Mod COW Age
Flag Address
16MB
Frame (4k)
Ref Swap/ Swap Block
Status
Count File Device Number
The Unix Big Picture
A process
Swap Device
0 Page 0
0 block 0
Region Page 1
Region
Page block 1
Table Page 2
Table Page
PageTable
3
Table block 2
Main (Physical) Memory
Page
Page 0 Frame 0 Swap-use
PFdata Swap-use
Table Frame PFdata
1
4GB Page Table
n Table
Table
Table
Frame 2Table
A process Page in
0 Page 0 Page out
Region Page 1
Region 128MB Frame m
Page
Table Page 2Page
Table
Page Table
3Table
Page
Page
Table 1GB block p
4GB Page nTable
Swap Device & swap use
1GB
Block (4k)
Ref Count
The Unix Big Picture
A process
Swap Device
0 Page 0
0 block 0
Region Page 1
Region
Page D.B.D. block 1
Table Page 2
Table Page D.B.D.
PageTable
3
Table Table
Table block 2
Main (Physical) Memory
Page
Page D.B.D.
D.B.D.
0 Frame 0 Swap-use
PFdata Swap-use
Table Table
Table Frame PFdata
1
4GB Page Table
n Table
Table
Table
Frame 2Table
A process Page in
0 Page 0 Page out
Region Page 1
Region 128MB Frame m
Page D.B.D.
Table Page 2Page
Table D.B.D.
Page Table
3Table Table
Table
Page
Page D.B.D.
D.B.D.
Table Table 1GB block p
4GB Page nTable Table
Virtual & Swap connection
region table Disk block
descriptor
Text page table table
Data
Page 0 Page 0
Stack
Page 1 Page 1
Page 2 Page 2
… …
Start Region
Permissions Page N-2 Page N-2
Address Size
Page N-1 Page N-1
Valid Physical
Permissions Ref Mod COW Age
Flag Address
Swap Dev. 1
1493K Page No. 794
Block No. 2743
Valid Physical
Permissions Ref Mod COW Age
Flag Address
COW & Age
page table
Page 0
Page 1
Page 2 The other two, updated by O.S.
… • COW – Copy on Write Flag
Page N-2 The page will be copied
on first write (Fork)
Page N-1
• Age – Page Age (a number)
=0 – to warm pages
>0 – to cold pages
Valid Physical
Permissions Ref Mod COW Age
Flag Address
The Unix Big Picture
A process
Swap Device
0 Page 0
0 block 0
Region Page 1
Region
Page D.B.D. block 1
Table Page 2
Table Page D.B.D.
PageTable
3
Table Table
Table block 2
Main (Physical) Memory
Page
Page D.B.D.
D.B.D.
0 Frame 0 Swap-use
PFdata Swap-use
Table Table
Table Frame PFdata
1
4GB Page Table
n Table
Table
Table
Frame 2Table Pager
Pager
A process Page in
0 Page 0 Page out
Region Page 1
Region 128MB Frame m Page-stealer
Page-stealer
Page D.B.D.
Table Page 2Page
Table D.B.D.
Page Table
3Table Table
Table
Page
Page D.B.D.
D.B.D.
Table Table 1GB block p
4GB Page nTable Table
Pager
Loads Pages into main memory.
Usually, the Pager process is asleep.
Wakes up on a Page Fault (Type 1).
Pager
The Page In process:
1. Look at the D.B.D table to find the page at
the swap.
2. Look at the Pfdata table to check if the
page is found at the main memory.
a. Skip to 4
3. Load the page from swap to main memory
4. Update tables.
When Valid=0
Virtual Address offset
Valid Physical
....
Flag Address
Frame (4k)
Ref Swap/ Swap Block
Status
Count File Device Number
Page Stealer
The Bad Guy
Wakes up when the
number of free frames
passes the low-water
mark of free frames
Start to free frames till
High
the high-water mark
Low
Which page to throw?
Remember the Locality Rule?
Throw cold pages
The Aging process
Happens every second
Update Age field
If (REF = =0) Age ++;
Else Age=0;
Turns off REF field
Exec
Create a new virtual memory
New Region table
New Page Tables & D.B.D
Fork
Duplicate the virtual memory
Text – can be shared because it is read-
only
Data & Stack – need to be duplicated
The Problem:
Forking in order to do exec…
Duplicate on Demand
Share while you can…
Make a copy only when needed!
Copy on Demand
A page at the data region can be shared
until one of the processes modifies it.
Therefore, the O.S. needs to trace the
first write to the page
Make the page Read-only.
Turn on the COW flag.
When we have Protection Fault
Check if the COW is on, if so, make a
duplicate.
Fork
Text Region
Share the page table
Data & Stack
Copy the page table.
To all valid pages: Read-only & COW
Protection Fault
If COW is on
copy the page
Turn off COW.
Change back to Read-Write permissions.