Purpose: To give the illusion that there is more memory than you have.
Purpose: To speed the loading of programs by not loading unnecessary code
or just loading the startup code on startup.
Observation: Most programs have code they need rarely, like error code.
Observation: Most programs go thru phases, and you only need keep one phase
in memory at a time (like overlays, but not quite as good.)
Observation: Most programs delcare arrays bigger than needed. C and FORTRAN
seem to make this a big habit.
Observation: Most programs only work with a small subset of their data
(Like an airport lookup or a BBall stats program).
Implementation: Demand Paging
Yes, their is a demand segmentation. Pretty much the same thing, except
that segments have variable size and tend to be bigger.
Hardware:
Page table needs a valid-invalid bit, and really should have a r/w bit
and a referenced bit.
Need CPU to generate a page-fault when tries to access an invalid page.
Place to store memory (like a disk).
Can restart all instructions.
Consider string copy instructions for overlapping strings.
Consider REP-COUNT instructions of i386.
What to do when a page-fault occures:
If (reference is not valid)
error the process
Get a free page
Read the page off the disk (scheduler does stuff here)
change the page table to reflect the new page
restart the faulting instruction
Performance:
A single instruction can generate MANY page faults.
Luckily, almost all instructions generate NO page faults.
For computation in the book
effective-access-time = (1-p) * memory + p * disk
Hard problem: Which page to swap out when you need to swap out.
Kill process instead.
Use FIFO
Use LRU
Use some sort of frequency.
Program Structure
Good for V.M. subsystems
Accessing arrays in linear order
Not using more array than needed
Special multidimensioned arrays
Vary the rightmost index most often
Make the dimentioned size of the leftmost indexes be minimal
Stacks have great locality
Tree structures that have large branching factor
Putting all error handling code in in file
Putting related function in one file
Large sections of read only data
Bad for locality (and therefore VM)
Following pointers in general
Tree structures with small branching factors
Hash tables
Large sections of written data or mixed data
V.M. allocation and fairness
Conflicting goals:
Want to allocate pages for maximum global performance
Don't want other greedy people to hurt me
Fixed allocation per process, local replacement policy
Each process is given a quantity of pages on startup, never to change
When a new page need to be brought in for this process, the same process
loses a different page
Easy to administer
Have humans set quantity
Have program tell O.S. on start up.
Can result in very poor global performance due to a few poor processes
Can waste memory
Variable allocation per process, global replacement policy
Choose a victum page based on some global quality, such as oldest unused
page in RAM.
Processes can gain or loose memory
Provides global best performance
Others can effect YOU adversly
Variable allocation per process, local replacement policy
Each process has a fixed allocation of pages.
On each page fault, faulting process donates a page
Occasionally, allocations are reviewed and changed
by humans
more frequently, by automatic review of things like fault frequency
Others can only somewhat hurt YOU, global performance O.K.
Really, this is a compromise
Swapping
Swapping is moving out to secondary storage ALL of a process.
Proccesses cannot run when the are swapped.
Swapping should occur when the RAM is overcommitted.
Can stop system from seeming locked up (always soem room for root to log
in)
Can increase global performance
How to swap
If load is to high
Pick a non-swapped process
Choose by UID (not root)
By I/O (don't pick interactive processes)
By memory allocation (pick large processes)
By prioity (pick low)
By page fault freqency (pick high)
Most recently started process (likely to not be in RAM yet).
Stop scheduling it
Shove it out to disk
If load is too low
Pick a swapped process
Bring it in from disk
begin scheduling it (put on ready queue).
Overcommitment of V.M. resources
Suppose you have 40M swapspace and 20M ram.
Only promise 60M total virtual space
Often must not accept requests when you really could
Can always meet any promise made
Promise the world
Almost never get caught in lie
Sometimes in trouble
freeze process causing problem -- hope page frees up