Handling Requests: The Detailed View
The sbull driver as described earlier works
very well. In simple situations (as with
sbull), the macros from
<linux/blk.h> can be used to easily set up a
request function and get a working driver. As
has already been mentioned, however, block drivers are often a
performance-critical part of the kernel. Drivers based on the simple
code shown earlier will likely not perform very well in many
situations, and can also be a drag on the system as a whole. In this
section we get into the details of how the I/O request queue works
with an eye toward writing a faster, more efficient driver.
The I/O Request Queue
Each block driver works with at least one I/O request queue. This queue contains, at any given time, all of the I/O operations that the kernel would like to see done on the driver’s devices. The management of this queue is complicated; the performance of the system depends on how it is done.
The queue is designed with physical disk drives in mind. With disks, the amount of time required to transfer a block of data is typically quite small. The amount of time required to position the head (seek) to do that transfer, however, can be very large. Thus the Linux kernel works to minimize the number and extent of the seeks performed by the device.
Two things are done to achieve those goals. One is the clustering of requests to adjacent sectors on the disk. Most modern filesystems will attempt to lay out files in consecutive sectors; as a result, ...