Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The bio structure in the Linux kernel

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?
like image 683
Vikram Avatar asked Jan 28 '13 18:01

Vikram


People also ask

What is block layer in Linux?

The Linux block layer provides an upstream interface to filesystems and block-special devices allowing them to access a multitude of storage backends in a uniform manner.

What is the block layer?

blocklayer (plural blocklayers) A person employed to lay down blocks of material, for example as a road surface.


2 Answers

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.

like image 167
Praveen Felix Avatar answered Oct 14 '22 13:10

Praveen Felix


  1. "In flight" means an operation that has been requested, but hasn't been initiated yet.
  2. "Segment" here means a range of memory to be read or written, a contiguous piece of the data to be transferred as part of the operation.
  3. "Scatter/gather I/O" is meant by scatter operations that take a contiguous range of data on disk and distributes pieces of it into memory, gather takes separate ranges of data in memory and writes them contiguously to disk. (Replace "disk" by some suitable device in the preceding.) Some I/O machinery is able to do this in one operation (and this is getting more common).
like image 31
vonbrand Avatar answered Oct 14 '22 15:10

vonbrand