Linux device drivers--the concept and framework of block equipment (i)

Source: Internet
Author: User

Basic concepts

Block Devices (Blockdevice)

---is a random access device with a certain structure, the reading and writing of this device is block -based, he uses buffer zone to hold temporary data, waiting for the condition to mature, from the cache once written to the device or from the device to read the buffer at once area.

Character devices (Character device)

---is a sequential data flow device in which read and write is performed by character , and these characters are continuously formed into a data stream. He does not have a buffer, so the reading and writing of this device is real-time .

sector (sectors): The basic unit of data processing for any block device hardware. Typically,1 sectors have a size of 512byte. (For Devices)

block (Blocks): The basic unit for data processing by Linux, such as the kernel or file system. Typically,1 blocks consist of one or more sectors . (for Linux operating systems)

segment (segments): Consists of a number of adjacent blocks . is part of a memory page or a memory page in the Linux memory management mechanism.

The diagram between pages, segments, blocks, and sectors is as follows:

Block device driven overall framework

The application of block devices is a complete subsystem in Linux.

In Linux, driving input or output (I/O) operations to a block device sends a request to the block device, described in the drive with the request structure . For some disk devices, however, the request is slow, and the kernel provides a queue mechanism to add these I/O requests to the queue (that is, the request queue), described in the driver with the request_queue structure . Before committing these requests to a block device, the kernel performs the requested merge and sort pre-operation to improve the efficiency of the access, and then the I/O Scheduler Subsystem in the kernel is responsible for committing I/O requests, and the scheduler allocates the disk resources to all pending block I/O requests in the system. Its job is to manage the request queue for block devices, determine the order in which requests are queued, and when to dispatch requests to devices .

The common block layer (Generic block layers) is responsible for maintaining the relationship between an I/O request in the upper file system and the underlying physical disk. In a common block layer, a bio structure is typically used to correspond to an I/O request .

Linux provides a gendisk data structure body that represents a separate disk device or partition for access to the underlying physical disk. In Gendisk, there is a similar character device in the File_operations hardware operation structure Pointer, is the block_device_operations structure .

When multiple requests are submitted to a block device, the execution efficiency depends on the order of the requests. If all requests are in the same direction (for example: Write data), the execution efficiency is the largest. The kernel collects I/O requests and sorts requests before calling block device driver routines to process requests, and then merges multiple requests for successive sector operations to improve execution efficiency (the kernel algorithm does itself without you), and the algorithm for I/O request sequencing is called the elevator algorithm (elevator algorithm). The elevator algorithm is completed at the I/O scheduling layer. The kernel provides different types of elevator algorithms, and the elevator algorithm has

1 NoOp (Implement simple FIFO, basic direct Merge and sort),
2 Anticipatory (delayed I/O requests, optimized ordering of critical sections),
3 Deadline (improved for anticipatory disadvantage, reduced delay time),
4 CFQ (Uniform allocation of I/O bandwidth, fairness mechanism)

PS: In fact, the IO scheduling layer (including the request merge sorting algorithm) is not required by the user tube, the kernel has done

Related Data structures

Block_device: A block device instance that describes a partition or an entire disk pair of cores
Gendisk: Describes a universal hard disk (generic) object.
Hd_struct: Describes the partitioning information that the partition should have
Bio: Describes how to complete a fill or read block to driver when the block data is transferred
Request: Describes requesting a list from the kernel to prepare for queue processing.
Request_queue: Describes the kernel request request resource to create a list of requests and fill in the Bio formation queue.

Linux device drivers--the concept and framework of block equipment (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.