Managing the Buffer Cache
Fourteen kernel services provide management of this block I/O buffer cache mechanism.
The getblk kernel service allocates a buffer header and a free buffer from the buffer pool. Given a device and block number, the getblk and bread kernel services both return a pointer to a buffer header for the block. But the bread service is guaranteed to return a buffer actually containing a current data for the block. In contrast, the getblk service returns a buffer that contains the data in the block only if it is already in memory.
In either case, the buffer and the corresponding device block are made busy. Other processes attempting to access the buffer must wait until it becomes free. The getblk service is used when:
- A block is about to be rewritten totally.
- Its previous contents are not useful.
- No other processes should be allowed to access it until the new data has been placed into it.
The breada kernel service is used to perform read-ahead I/O and is similar to the bread service except that an additional parameter specifies the number of the block on the same device to be read asynchronously after the requested block is available. The brelse kernel service makes the specified buffer available again to other processes.