Case Study: Virtual Memory in UNIX

Download Report

Transcript Case Study: Virtual Memory in UNIX

Case Study: Virtual Memory in UNIX

Reference –
Maurice J.Bach , The Design of the UNIX Operating System
Terminology  Physical Memory (Main Memory)
 Secondary Memory (H.Disk)
 Virtual Memory
 Swap File
Region


Virtual space of a process
Stack , Data , Text – are regions of every process
Per Process Region Table - pregion

For every region –
•
•
•
•
Starting virtual
address
Number of pages in
this region
Access mode
Pointer to the Page
Table (page table for
every region)
Page Table
Page Table Entry


Demand paging fields
• Valid
• Reference
• Modify
• Copy on Write (COW)
• Age
Modify , Reference -handle by the hardware
More tables

Page frame data table (pfdata)

Swap-use
• One table
• Mapping all physical frames to disk
• Tells how many process are using this frame
• List of free frames
• Hash from disk address to frame
• For every swap device
• Tells how many frames points to the same disk
address
Using the Copy on Write in fork()
Kernel process for Virtual Memory

Pager
•
Every time the OS needs to swap a virtual page to the physical
memory
•
•
•
•

Get the first frame from the list of free pages , if the Modify bit is set write
it’s data to the disk.
Load the page to this frame
Set the valid bit
Resume the waiting process
Page Stealer (page daemon)
•
•
•
•
•
Every period of time
Enter old frames to the list of free pages
Update the age of every valid frame if the reference bit is 0
Put 0 in the the reference bit
=> LRU with second chance
Page Table Entries Disk Block
Page Fault
Virt Addr
Some of the
possibilities :
4K
64K
1.
2.
The page is in
the swap file
The page is in
the list of free
pages
State
State
Block
1648
inv
File
3
Frame
Disk
Block
Count
1036
387
0
1648
1618
1
1861
1206
0
0K
1K

Phys
Page Frames
None
inv
File
5
1917
inv
disk
1206
1036
inv
disk
847
Virt Addr
Phys
State
State
Block
66K
1776
val
disk
847
65K
66K
67K
Page
Disk
Block
Count
1776
847
1
After Swapping Page into Memory
Event - Page Daemon done
Event – Proc A reads from Pg2
Event – Proc A call to fork()
Event – Proc A reads from Pg1
Event – Proc B write to Pg6
Event – Page Daemon done
Event – Proc B reads from Pg2 & Pg5
Event – Page Daemon done
Event – Proc A ends