13.07.2015 Views

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

180 Transput Chapter 5usersbuffer poolprocesses1typingdisplayechoreadwrite110typingdisplayechoreadwrite10Figure 5.14 Buffers for terminalsbecause unrelated processes are trying to perform output to a stopped terminal.One extreme solution is to preallocate all our buffers among the terminals, givingeach terminal 100 characters. Although this policy avoids the starvation situation we hadearlier, it is an inefficient use of buffers. To explain why, we should point out why thebuffers are there in the first place.Buffer PrincipleThe purpose of a buffer pool is to smooth out short-term variations in speed between consumers and producers. This smoothing prevents needless blocking. In particular, buffer pools allow us to obey the Hysteresis Principle and resist switchingprocesses during transput operations. If the process is creating output, it is the producer,and the user (or the terminal) is the consumer. If the user is typing input, the user is theproducer, and the process is the consumer. In the long run, the consumer and the producermust run at the same speed because the consumer cannot read more informationthan was produced, and the producer cannot get infinitely ahead of the consumer. However,when a process wants to print 10 characters, it would rather not be blocked aftereach character. To avoid this situation, the buffer pool accepts the characters and theprocess need not be blocked. The more buffers we have, the more smoothing we canaccomplish. Therefore, restricting each process-user pair to 100 buffers prevents all ofthem from making temporary use of the smoothing possible with 1000 buffers.A reasonable compromise is to give each terminal a small number of privatebuffers, say 20. Then 800 buffers are available for whatever application happens to needthem. If only one terminal is currently very active, all 800 extra buffers will be allocated

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

Saved successfully!

Ooh no, something went wrong!