Analysis of bitmap source code in MD--an overview of entry problems

Source: Internet
Author: User

In the MD module, all levels of RAID are used by a copy of the bitmap source code, that is, a common bitmap process, the following RAID1 use as an example to analyze how bitmap works.

When using the RAID1 disk array, there is a high demand for the reliability of the data. In the process of writing, there may be unstable factors, such as disk damage, power down/down, network failure, system failure, and so on, resulting in write failure, after the system recovery, RAID also need to recover, if the disk is larger, then the process of synchronous recovery will be very long. In the case of RAID1, in the event of a failure, it is possible that the array of data are already consistent, in fact, only a small part of the inconsistency, so there is no need for a full scan, but the system does not know what data in the disk array is consistent, this needs to be recorded somewhere in the synchronized. For this reason, Bitmap was born, in short, thebitmap is to record which data in the raid is consistent, which is inconsistent , so that when the raid recovery is not the full amount of synchronization, Instead, the increments are synchronized, reducing the time to recover.

Bitmap's working principle is also straightforward, the content of the file is a bitmap. Bitmap a bit corresponds to a chunk (the data block, the default is 4KB), before the disk array data is written, set the chunk corresponding bit, the disk array write completion, then clear the bit. To synchronize, refer to the bitmap, only the bit corresponding to the chunk to synchronize, which shortens the synchronization time, improve efficiency.

Bitmap principle is very clear, according to the principle of direct implementation is also possible, but directly implemented, because the write of a data block more than two times the disk access (bitmap settings and cleanup), write efficiency will be greatly affected, so also need to consider some optimizations. The core of optimization is embodied in two aspects, the specific code is to achieve the two-point idea:

1 , Bitmap batch write after setting;

2 , Bitmap Time -lapse cleanup.

These two aspects of optimization, need to build in-memory and the disk bitmap file corresponding data structure,bitmap operations first in the cache, and if necessary, real disk operations.

Bitmap is divided into two kinds, one is internal, the other is external. The internal bitmap is located near the superblock of the member disk of the RAID device (which can also be followed before), and the external is a separate file to hold the bitmap. That is, the bitmap disk file can be stored outside the MD device, at which point the bitmap_file in the MD structure represents the bitmap file. The bitmap disk file can also be stored on the MD device itself, where bitmap is specified by Bitmap_offset relative to the location of the MD device's Super block. Bitmap_offset can be a negative number, indicating that Bitmap is located before Superblock. The location of the bitmap relative to Superblock is related to the parameter metadata when the MD device was created. For example, the following create MD device command:

Mdadm–cr/dev/md0–l1–n2/dev/sdb/dev/sdc–bitmap=internal–metadata=x–assume-clean

In metadata=1.0, Bitmap_offset for -8,bitmap before Superblock; metadata=1.1 for Bitmap_offset after 8,bitmap in Superblock At the time of metadata=1.2, Bitmap_offset is 8,bitmap after superblock; in metadata=0.9, Bitmap is followed by superblock from the comments in the code. The bitmap of the internal is located near the superblock of the MD device, and external is a separate file to store bitmap.

The superblock version of MD is specified by the-metadata parameter. There are four versions of Superblock:

0.9--limit the number of devices in a raid to 28, limiting the component device size to 2TB;

1.0--superblock stored at the end of the device;

1.1--superblock stored at the beginning of the device;

The 1.2--superblock is stored at 4K at the device.

  The next article will analyze in detail how the data structure of bitmap is designed to achieve these two optimization mechanisms.

Reprint Please specify source: http://www.cnblogs.com/fangpei/

Resources:

[1] Linux kernel source 2.6.32

[2] The bitmap in MD begins http://blog.csdn.net/qincp/article/details/4396517

[3] Bitmap analysis of Linux soft raid http://blog.csdn.net/qincp/article/details/4396517

Analysis of bitmap source code in MD--an overview of entry problems

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.