Using the Buffer Cache write Services
There are three slightly different write routines. All of them take a buffer pointer as a parameter and all logically release the buffer by placing it on the free list.
The bwrite service puts the buffer on the appropriate device queue by calling the device’s strategy routine. The bwrite service then waits for I/O completion and sets the caller's error flag, if required. This service is used when the caller wants to be sure that I/O takes place synchronously, so that any errors can be handled immediately.
The bawrite service is an asynchronous version of the bwrite service and does not wait for I/O completion. This service is normally used when the overlap of processing and device I/O activity is desired.
The bdwrite service does not start any I/O operations, but marks the buffer as a delayed write and releases it to the free list. Later, when the buffer is obtained from the free list and found to contain data from some other block, the data is written out to the correct device before the buffer is used. The bdwrite service is used when it is undetermined if the write is needed immediately.
For example, the bdwrite service is called when the last byte of the write operation associated with a block special file falls short of the end of a block. The bdwrite service is called on the assumption that another write will soon occur that will use the same block again. On the other hand, as the end of a block is passed, the bawrite service is called, because it is assumed the block will not be accessed again soon. Therefore, the I/O processing can be started as soon as possible.
Note that the getblk and bread services dedicated the specified block to the caller while making other processes wait, whereas the brelse, bwrite, bawrite, or bdwrite services must eventually be called to free the block for use by other processes.