Buffer Heads

The buffer head is a descriptor of type buffer_head associated with each buffer. It contains all the information needed by the kernel to know how to handle the buffer; thus, before operating on each buffer, the kernel checks its buffer head.

The buffer head fields are listed in Table 13-6. The b_data field of each buffer head stores the starting address of the corresponding buffer. Since a page frame may store several buffers, the b_this_page field points to the buffer head of the next buffer in the page. This field facilitates the storage and retrieval of entire page frames (see Section 13.4.8.2 later in this chapter). The b_blocknr field stores the logical block number (i.e., the index of the block inside the disk partition).

Table 13-6. The fields of a buffer head

Type

Field

Description

struct buffer head *

b next

Next item in collision hash list

unsigned long

b blocknr

Logical block number

unsigned short

b size

Block size

unsigned short

b list

LRU list including the buffer head

kdev t

b dev

Virtual device identifier

atomic t

b count

Block usage counter

kdev t

b rdev

Real device identifier

unsigned long

b state

Buffer status flags

unsigned long

b flushtime

Flushing time for buffer

struct buffer head *

b next free

Next item in list of buffer heads

struct buffer head *

b prev free

Previous item in list of buffer heads

struct buffer head *

b this page

Per-page buffer list

struct buffer head *

b reqnext

Next item in the request queue

struct buffer head **

b pprev

Previous item in collision hash list

char *

b data

Pointer to buffer

struct page *

b page

Pointer to the descriptor of the page that stores the buffer

void (*)( )

b end io

I/O completion method

void (*)

b private

Specialized device driver data

unsigned long

b rsector

Block number on real device

wait queue head t

b wait

Buffer wait queue

struct inode *

b inode

Pointer to inode object to which the buffer belongs

struct list head

b inode buffers

Pointers for list of inode buffers

The b_state field stores the following flags:

BH_Uptodate

Set if the buffer contains valid data. The value of this flag is returned by the buffer_uptodate( ) macro.

BH_Dirty

Set if the buffer is dirty—that is, if it contains data that must be written to the block device. The value of this flag is returned by the buffer_dirty( ) macro.

BH_Lock

Set if the buffer is locked, which happens if the buffer is involved in a disk transfer. The value of this flag is returned by the buffer_locked( ) macro.

BH_Req

Set if the corresponding block is requested (see the next section) and has valid (up-to-date) data. The value of this flag is returned by the buffer_req( ) macro.

BH_Mapped

Set if the buffer is mapped to disk—that is, if the b_dev and b_blocknr fields of the corresponding buffer head are significant. The value of this flag is returned by the buffer mapped( ) macro.

BH_New

Set if the corresponding file block has just been allocated and has never been accessed. The value of this flag is returned by the buffer_new( ) macro.

BH_Async

Set if the buffer is being processed by end_buffer_io_async( ) (described in the later section Section 13.4.8.2). The value of this flag is returned by the buffer_async( ) macro.

BH_Wait_IO

Used to delay flushing the buffer to disk when reclaiming memory (see Chapter 16).

BH_launder

Set when the buffer is being flushed to disk when reclaiming memory (see Chapter 16).

BH_JBD

Set if the buffer is used by a journaling filesystem (see Chapter 17).

The b_dev field identifies the virtual device containing the block stored in the buffer, while the b_rdev field identifies the real device. This distinction, which is meaningless for simple hard disks, has been introduced to model Redundant Array of Independent Disks (RAID) storage units consisting of several disks operating in parallel. For reasons of safety and efficiency, files stored in a RAID array are scattered across several disks that the applications think of as a single logical disk. Besides the b_blocknr field representing the logical block number, it is necessary to specify the specific disk unit in the b_rdev field and the corresponding sector number in the b_rsector field.

+1 0

Post a comment