The bio structure in the Linux kernel

Vikram picture Vikram · Jan 28, 2013 · Viewed 9.1k times · Source

I am reading Linux Kernel Development by Robert Love. I don't understand this paragraph about the bio structure:

The basic container for block I/O within the kernel is the bio structure, which is defined in <linux/bio.h>. This structure represents block I/O operations that are in flight (active) as a list of segments. A segment is a chunk of a buffer that is contiguous in memory. Thus, individual buffers need not be contiguous in memory. By allowing the buffers to be described in chunks, the bio structure provides the capability for the kernel to perform block I/O operations of even a single buffer from multiple locations in memory. Vector I/O such as this is called scatter-gather I/O.

  1. What exactly does flight(active) means?
  2. "As a list of segments" -- are we talking about this segmentation?
  3. What does "By allowing the buffers ... in memory" mean?

Answer

Praveen Felix picture Praveen Felix · Jan 29, 2013

Block Devices are such device which deals with a chunk (512, 1024 bytes) of data during an I/O transaction. "struct bio" is available for block I/O operations from Kernel-Space. This structure is commonly used in block device driver development.

Q1) What exactly does flight(active) means?

Block devices are usually implemented with a File-System meant for storing files. Now when ever an user-space application initiates a File I/O operation (read, write), the kernel in turn initiates a sequence of Block I/O operation through File-System Manager. The "struct bio" keeps track of all Block I/O transactions (initiated by user app) that is to be processed. That's what is mentioned here as flight/active regions.

"Q2) As a list of segments" -- are we talking about this segmentation?

Memory buffers are required by the kernel to hold data to/from Block device.

In kernel there are two possiblilites in which the memory is allocated.

  1. Virtual Address Continuous - Physical Address Continuous (Using kmalloc() - Provides good Performance but limited in size)
  2. Virtual Address Continuous - Physical Address Non-continuous (Using vmalloc() - For huge memory size requirement)

Here a segment indicates the first type i.e. continuous physical memory which is used for block IO transfer. List of segment indicates a set of such continuous physical memory regions. Note that the list elements are non-continuous memory segments.

Q3) What does "By allowing the buffers ... in memory" mean?

Scatter-gather is feature which allows data transfer from/to multiple non-continuous memory location to/from device, in a single shot (read/write transaction). Here "struct bio" keeps record of multiple segments that is to be processed. Each segment is a continuous memory region whereas multiple segments are non-continuous with one another. "struct bio" provides capability to the kernel to perform scatter-gather feature.