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.

Single segment 75desired size10first fitbest fit13 11 12Figure 3.10 First-fit and best-fit policiesmechanisms that discover the appropriate sizes as they are called for can be used effectively.Second, circular first fit runs into unexpected problems when the total availablespace is much larger than the average request but some requests are large. The steadystatesituation distributes moderate-sized free chunks throughout the total space, leavingnone large enough for the occasional large request. In this case, noncircular first fit, eventhough expensive, leads to higher overall utilization.To implement any of these methods, the storage manager needs to keep track ofwhich pieces of physical store are in use and which are free. Two data structures areavailable for this purpose. In the first, called the boundary-tag method, each free piecehas pointers (physical pointers, of course, which may require more than one word, as discussedearlier) that link all free pieces in a doubly linked list. They don’t have to appearin order in that list. Also, each piece, whether free or in use, has the first and last wordsreserved to indicate its status, free or busy, and its length. When a free block is needed,the doubly linked list is searched from the last stopping point until an adequate piece isfound. If necessary, it is split into a new busy piece and a new free piece. If the fit isexact, the entire piece is removed from the doubly linked free list. When a piece isreturned to free space, it is joined to the piece before it and after it (if they are free) andthen put on the free list.The other data structure is a bit map with one bit for each chunk of physical store.If chunks are as small as one word, the bit map will be unreasonably large. Therefore,chunks are perhaps 16 or 32 words. If the hardware requires segments to begin at(p −v )-bit boundaries, then a reasonable chunk size is 2 p −v . The bits in the bit map arepacked into contiguous words. Each free chunk may be represented by a zero, and eachbusy chunk by a one. Finding a free piece of size c chunks is equivalent to finding atleast c consecutive zero bits in the bit map. When a piece is freed, the corresponding bitsare reset to zero; it is not necessary to join the piece to its neighbors explicitly.When adequate room is not available for a new segment, a choice must be madeeither to swap out some segment or to shuffle. Generally, shuffling takes less time thanswapping, but no other activity can proceed meanwhile. Occasionally, swapping out asingle small segment will allow two medium-sized free pieces to coalesce into a freepiece large enough to satisfy the new segment. A policy to decide whether to shuffle orswap could be based on the percentage of time the storage manager spends shuffling. Ifthat time is less than some fixed percentage, which is a tunable parameter of the policy,then the decision would be to shuffle. Otherwise, some segment would be swapped out.

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

Saved successfully!

Ooh no, something went wrong!