0
13kviews
Buffer Header in UNIX
1 Answer
1
924views

During system initialisation process, the kernel allocates space for a number of buffers. Buffers created according to memory size and system performance constraints. A buffer has two parts, i.e. a memory array that contains data from the disk and a buffer header that identifies the buffer. Because there is a one to one mapping of buffer headers to data arrays, the ensuing text will frequently refer to both parts as a "buffer," and the context should make clear which part is being discussed.

enter image description here

Fig: Buffer header

The data in a buffer corresponds to the data in a logical disk block on a file system, and the kernel identifies the buffer contents by looking identifier fields in the buffer header. The buffer is the in-memory copy of the disk block; the contents of the disk block map into the buffer, but this attachment is temporary and data stays until the kernel decides to map another disk block into the buffer. A disk block can never map into more than one buffer at a time. If two buffers have a data for one disk block, the kernel would not know which buffer contained the current data and could write incorrect data back to disk.

The buffer header holds a device number field and a block number field that specify the file system and block number of the data on disk and uniquely identify the buffer. The device number is the logical file system number not a physical device (disk) unit number. The buffer header also contains a pointer to a data array for the buffer, whose size must be at least as big as the size of a disk block, and a status field that specifies the current status of the buffer. The status of a buffer is a combination of the following conditions:

• The buffer is currently locked(the terms "locked" and "busy" will be used alternatively, as will "free" and "unlocked"),

• The buffer keeps valid data,

• The kernel must write the buffer contents to disk before reassigning the buffer to another block; this situation is known as "delayed-write,"

• The kernel is currently reading or writing the contents of the buffer to disk

• A process is currently waiting for the buffer to become free. The buffer header also contains two sets of pointers, used by the buffer allocation algorithms to manage the overall structure of the buffer pool.

Please log in to add an answer.