DeviceMapper mechanism in Linux Kernel

Source: Internet
Author: User
The DeviceMapper mechanism in the Linux kernel-general Linux technology-Linux programming and kernel information. The following is a detailed description. Level: elementary

Yin Yang, Ph.D. student

June 29, 2006

This article introduces the device er ing mechanism in the Linux kernel based on the specific code. Device er is a ing framework from a logical Device to a physical Device provided in the Linux 2.6 kernel. Under this mechanism, users can easily develop storage resource management policies based on their own needs. Currently, logical Volume Manager in Linux is popular, such as LVM2 (Linux Volume Manager 2 version) and EVMS (Enterprise Volume Management System) and dmraid (Device Mapper Raid Tool) are all implemented based on this mechanism. Understanding this mechanism is the basis for further analysis and understanding of the implementation and design of these volume managers. Through this article, we can further understand the design and implementation of Linux system block I/O.
Device Mapper is a general Device ing mechanism that supports logical volume Management in Linux2.6 kernel. It provides a highly modular kernel architecture for block Device drivers used for storage resource management.

Kernel architecture of Device Mapper

(400) {this. resized = true; this. width = 400; this. alt = 'click here to open new window';} "onmouseover =" if (this. resized) this. style. cursor = 'hand'; "onclick =" window. open ('HTTP: //'); ">

In the kernel, it uses a modular target driver plug-in to filter IO requests or redirect requests, currently, the target driver plug-in includes soft raid, soft encryption, logical volume strip, multi-path, image, and snapshot, in the figure, linear, mirror, snapshot, and multipath represent these target drivers. Device er further embodies the principle of policy and mechanism separation in the Linux kernel design, and puts all policy-related work into the user space, the kernel mainly provides the mechanisms required to complete these policies. The Device mapper user space is mainly responsible for configuring specific policies and control logic, such as establishing mappings between logical devices and physical devices and how to establish these mappings, the specific filtering and redirection of IO requests are completed by the relevant code in the kernel. Therefore, the entire device mapper mechanism consists of two parts: the device mapper driver of the kernel space, the device mapper library of the user space, and the dmsetup tool provided by it. In the following section, we will introduce the kernel and user space.


The kernel-related code of Device mapper has been integrated into the kernel source code as part of the Linux 2.6 kernel release version. The code is in the driver/md/directory of the kernel source code, the code file can be divided into two parts: files that implement the basic architecture in the device mapper kernel and target driver plug-in files that implement specific ing. The analysis results below are mainly obtained based on the above source code file.

Important Concepts

Device er is registered as a block device driver in the kernel. It contains three important object concepts: mapped device, ing table, and target Device. The Mapped device is a logical abstraction that can be understood as a logical device provided by the kernel. It establishes a ing with the target device through the ing relationship described in the ing table. The ing table from Mapped device to a target device is represented by a multi-element group, the multivariate group is composed of the starting address, range, and variable indicating the address offset and target type of the physical device where the target device is located (these addresses and offsets are based on the disk's slice in units, that is, the size of 512 bytes ). Target device indicates the physical space segment mapped to the mapped device. For the logical device indicated by mapped device, it is a physical device mapped to the logical device. The three objects in Device mapper and the target driver plug-in constitute an iterative Device Tree. In this tree structure, the top-level root node is the mapped device finally provided as the logic device. The leaf node is the underlying physical device represented by the target device. The smallest device Tree consists of a single mapped device and a target device. Each target device is exclusive to the mapped device and can only be used by one mapped device. A mapped device can be mapped to one or more target devices, and a mapped device can be used as the target device of its upper-layer mapped device, theoretically, this layer can be infinitely iterated in the device mapper architecture.

Hierarchy of objects in the Device mapper Kernel

(400) {this. resized = true; this. width = 400; this. alt = 'click here to open new window';} "onmouseover =" if (this. resized) this. style. cursor = 'hand'; "onclick =" window. open ('HTTP: //'); ">

In, we can see that mapped device1 establishes a ing relationship with the target device a, B, and c through the ing table, and target device a is evolved through mapped device 2, mapped device 2 establishes a ing relationship with target device d through the ing table.

Let's further look at the specific implementation of the above three objects in the code, dm. the mapped_device structure defined in file c is used to represent the mapped device. It mainly includes the locks related to the mapped device, the registered Request queue, some memory pools, pointers to the corresponding ing tables, and other fields. The ing table corresponding to the Mapped device is represented by the dm_table structure defined in the dm_table.c file, which contains an array of dm_target structures, the dm_target Structure describes the ing between mapped_device and a target device. In the dm_table structure, these dm_targets are organized in the form of B trees to facilitate the search operation during IO request ing. The Dm_target structure records the start address and range of the mapped device logical region mapped to the target device. It also contains pointers to the target_type structure of specific target device operations. The Target_type structure mainly includes the name of the target driver plug-in corresponding to the target device, the method for defining the construction and deletion of the target device type, the IO request re ing corresponding to the target device type, and method. The target device domain is the private domain in dm_target. The Pointer Points to the structure of the target device mapped by mapped device. The specific structure of the target device varies with the target type. For example, the simplest linear ing of the target type corresponds to the structure of the target device, which is the linear_c structure defined in the dm-linear.c file. It is defined as follows:
Related Article

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: 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.