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.

82 Space Management Chapter 3segment back in. While the segment is being swapped in, which takes on the order of 20to 50 milliseconds (depending on what sort of backing store is used and how long thesegment is), the kernel switches to some other process. Once the segment is in, the firstprocess will be allowed to continue. It has no inkling that a segment fault occurred.(Otherwise, the operating system would violate the Beautification Principle.)When the storage manager needs to swap some segment out in order to make roomfor some other segment, it is best to choose a segment that is not currently in use by anyprocess. Otherwise, a segment fault in one process may impede progress in otherprocesses as well. We will devote a great deal of attention to mechanisms to accomplishthis feat when we discuss paging.One danger should be mentioned. Since a single instruction might require five ormore different segments in order to be executed, segments that have just been brought inshould not be subject to swapping out before they have even been used the first time, orelse the operating system might thrash by victimizing segments that are needed for thecurrent instruction.Swapping out a segment is not always expensive. A segment that does not havewrite permission (by any process that uses it) need not be written to backing storebecause it has not changed since it was last on backing store. It is only necessary to resetits Present field to false in the segment table and to reclaim its space. Similarly, writablesegments that have not been changed since they were last swapped in are cheap to swapout. Some machines set a Boolean field called ‘‘Dirty’’ in the segment table entry to truewhenever a write access occurs to the corresponding segment. The storage manager initializesDirty to false whenever it swaps the segment in. When a segment is about to beswapped out, it only needs to be written to backing store if Dirty is true. Of course, thismechanism requires that a copy be kept on the backing store of all segments that arebrought into main store.5.4 Large segment spacesOn some machines, the number of bits devoted to the segment number is very large. Forexample, the Honeywell 645, which supports the Multics operating system, has 18 bits ofsegment number. Instead of using segments in a range from zero to some reasonablysmall number, programs in such machines may use a few segment numbers scatteredwithin the enormous space of possibilities. The reason Multics uses so many segments isthat every subprogram that exists has its own segment number that is reserved for as longas the subprogram is saved on secondary store; this time could be years.The implementation just described does not work very well for large, sparse segmentspaces because the segment table has one entry for each potential segment. Thehardware is certainly not going to refer directly to a table with 2 18 = 256K entries; such atable would require more physical store than most computers have! Instead, a hashingtechnique can be used, a technique that first converts the segment number into an indexin a hash table where the desired entry can be found. <strong>An</strong>other alternative is to apply pagingto the segment table. To understand that solution, we must first understand paging,which will be presented shortly.

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

Saved successfully!

Ooh no, something went wrong!