Linux Kernel Development (8)

Posted on 2011-06-16 17:23  Teddy Yan  阅读(190)  评论(0编辑  收藏  举报

The Block I/O Layer

The smallest addressable unit on a block device is a sector. Sectors come in various powers of two, but 512 bytes is the most common size. although many block devices can operate on multiple sectors at one time.

Software has different goals and therefore imposes its own smallest logically addressable unit, which is the block. The block is an abstraction of the filesystem—filesystems can be accessed only in multiples of a block. The kernel also requires that a block be no larger than the page size.

buffer_head

When a block is stored in memory—say, after a read or pending a write—it is stored in a buffer. Each buffer is associated with exactly one block.

BIO

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.

I/O vectors

The bi_io_vec field points to an array of bio_vec structures.These structures are used aslists of individual segments in this specific block I/O operation

Request Queues

Block devices maintain request queues to store their pending block I/O requests.

I/O Schedulers

Therefore, the kernel does not issue block I/O requests to the disk in the order they are received or as soon as they are received. Instead, it performs operations called merging and sorting to greatly improve the performance of the system as a whole.2 The subsystem of the kernel that performs these operations is called the I/O scheduler.

The I/O scheduler is not to be confused with the process scheduler (see Chapter 4,“Process Scheduling”), which divides the resource of the processor among the processes on the system.The two subsystems are similar in nature but not the same. Both the process scheduler and the I/O scheduler virtualize a resource among multiple objects. In the case of the process scheduler, the processor is virtualized and shared among the processes on the system.This provides the illusion of virtualization inherent in a multitasking and timesharing operating system, such as any Unix. On the other hand, the I/O scheduler virtualizes block devices among multiple outstanding block requests.This is done to minimize disk seeks and ensure optimum disk performance.

The entire request queue is kept sorted, sectorwise, so that all seeking activity along the queue moves (as much as possible) sequentially over the sectors of the hard disk. Because of this similarity, I/O schedulers (or sometimes just their sorting algorithm) are called elevators. Additionally, if an existing request is found in the queue that is older than a predefined threshold, the new request is added to the tail of the queue even if it can be insertion sorted elsewhere.

Copyright © 2024 Teddy Yan
Powered by .NET 8.0 on Kubernetes