A bit of code to run when page faulting
// gets real address in RAM for a given virtual address
pmap(va)
each process gets its own page table - necessary for isolation, threads in a process have just
one page table
each process haves own pmap function p->pmap
// gets real address in RAM for a given virtual address
pmap(va)
each process gets its own page table - necessary for isolation, threads in a process have just
one page table
each process haves own pmap function p->pmap
// gives disk address for a given virtual address
p->swapmap(va)
{
// something like this
if(va > p->valim) ? FAULT : return p-> diskorigin + va;
}
// takes process that faulted, virtual address that faulted
pfault(p, va)
{
if(p->swapmap(va) == FAULT) kill(p);
else {
// op is other process, ova is other virtual address
(op, ova) == removal_policy();
pa = op->pmap(ova);
// write pa block to disk @ op->swapmap(ova)
// read pa block from disk @ p->swapmap(va)
// not real c-code (updates page tables)
p->pmap(va) = pa;
op->pmap(va) = FAULT;
}
}
- POLICY
- Use memory traces to choose correct algorithm
- Q: Which page to choose as a victim
- A0: Pick victim at random
- (Works if memory accesses are truly random)
- But: LOCALITY OF REFERENCE
- A1: FIFO (First In First Out)
- A2: Oracle policy - replace page that won't be needed for the longest time
- A3: Least Recently Used - often, but not always better than FIFO
- Improving Performance
- A. Demand paging
- read just main page & then execute
- + start faster
- - more page-fault code executed
- - more disk-arm movement in a multiprocess app.
- read just main page & then execute
- B. Don't write victim page to disk if it's never been written to
- A. Demand paging
- Making fork faster
- fork()
- copies all of process's virtual memory
- How to speed up?
- 1) Don't need to copy read only areas
- 2) Don't copy writable pages either
- copy on write is to fork as demand paging is to exec
- vfork()
- parent and child share memory (& therefore page tables)
- parent is frozen until child exits or execs
- p = vfork();
-
if (!p) { //fiddle a bit ‹- should not write to global RAM exec(); exit(); }
-
- parent and child share memory (& therefore page tables)
- fork()
- Distributed Systems & RPC (remote procedure call)
- // sample call to exchange $10 from account A to B
- transfer(10, A, B);
- RPCs differ from ordinary function calls & syscalls
- - slower yet (limited by speed of light)
- + hard modularity (caller and callee not sharing address spaces)
- - no call by reference (caller cannot tell callee to look at address, always call by value)
- +/- caller/callee may have different architecture (requires data format to be known)
- marshall
- converts data structure to transferable bytes
- caller
- most marshall the data
- callee
- unmarshall data
- // sample call to exchange $10 from account A to B