13.07.2015 Views

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Segmentation 815.2 Storing the necessary informationMissing segments are, of course, swapped out. The segment table must indicate thataccesses to such segments should generate traps. We have shown a Boolean (one-bit)field called ‘‘Present’’ in the segment table (line 16 of the declarations) to indicate thisfact. Instead, we could have set the segment length to zero or removed all accessprivileges. Then the hardware would still trap to the kernel, but now the kernel wouldhave to refer to the context block for the process to find out whether the trap signals thatthe process is attempting an invalid access or a valid access to a missing segment.Such treatment of the segment-length or permissions field is an example of themirror tables technique. Under this technique, the hardware table is intentionallymisleading in order to have the hardware take some special action that would be tooexpensive in software. The actual state of affairs is honestly represented in a second setof tables stored by the kernel. Mirror tables are used either when the hardware lackssome needed field (for example, the hardware segment table lacks a Present field) or forreasons of efficiency (for example, composite page tables for processes that are themselvesoperating systems).Before a missing segment may be accessed, the storage manager must swap thatsegment back into main store. To find it on backing store, the storage manager mustremember its location. Some hardware provides another field in the segment table forthis purpose. This field is ignored by the hardware. If the hardware provides only aPresent field, the storage manager can use the Start and Permissions fields to store thebacking-store address, if there is room. The use of the same field to mean differentthings at different times is called overloading. If overloading is not possible, the storagemanager can save a mirror copy of the translation table in the context block, and thiscopy can have a ‘‘backing-store location’’ field.5.3 SwappingOnce the missing segment has been swapped back in, the kernel switches back to thecontext in which the process was running. Its program counter is reset to the instructionthat failed previously. The hardware then tries to execute that instruction again. If all iswell, no new trap will occur. However, the instruction might still fail for several reasons.It might require another operand from another segment that is also missing. In fact, asingle instruction on a three-address machine can cause five segment faults: one for eachof the two operands, one for the result, and two for the instruction itself if it lies on aboundary between two segments. (We are not even considering the case where operandscan cross segment boundaries!) The storage manager keeps bringing in segments untilthe process can continue. With luck, some other process is ready and can make use ofthe processor while the segments are being swapped in.The decision to swap out a segment does not completely inactivate the process thatwas using it. As long as the process avoids accessing virtual addresses within that segment,it can continue to run. When it does require that segment, the hardware will trap tothe kernel. We call this event a segment fault. The storage manager will swap that

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!