Bitmap source code Analysis in MD--Setup process

Source: Internet
Author: User

1. Synchronous/Asynchronous Brush disk

Bitmap File Write disk sub-synchronous and asynchronous two kinds:

1) Synchronous set: When the disk array has a write request, the corresponding bitmap file corresponding bit is placed, the bitmap memory page is dirty flag. Before sending a write request to the disk, you must ensure that the bitmap file is completed before the write request is sent to the disk. This situation requires waiting for the write bitmap disk file to complete, so it is synchronized. (completed by Bitmap_unplug ())

Write bit to write chunk data before the synchronous brush disk, because if the write request first issued, and write bit after this brush disk, when the write disk process failure, such as power down, when the data is inconsistent, In the bitmap file of the disk, the result of writing bit in memory has not yet been recorded, resulting in the mistaken belief that the data is consistent. In the case of Bitmap_statrwrite () and Bitmap_unplug () two steps to realize the bit batch brush in the bitmap, the synchronous position is realized, which is to guarantee the correctness.

2) Asynchronous clear 0 : When the issued disk write request completed, you need to bitmap memory page of the corresponding bit zeroed, and then the bitmap file brush. This process does not need to wait for the write bitmap disk file to complete and therefore is asynchronous. (completed by Bitmap_daemon_work ())

The clear bit can be done asynchronously after the write request is completed, because even if the write fails, it will not affect correctness, but will bring an additional synchronization. The advantage of asynchronous zeroing is that when it is not clear 0 or memory bitmap clear 0 but there is no brush to disk, and there is a write request to the page, just add the BMC counter or simply set the memory bitmap, instead of writing to the external memory bitmap file, thus reducing the write external memory bitmap IO. In addition, asynchronous clear 0 also implements the bit batch brush in bitmap.

2. Writing process bitmap Settings

In Raid1 's writing process, Bitmap's setup operations are mainly in Bitmap_statrwrite (), Bitmap_unplug (), and Bitmap_endwrite ().

Bitmap_statrwrite (), which is called in Make_request () in RAID1. This function is called before the bio of each disk is submitted to pending_bio_list.

The main work of Bitmap_statrwrite () :

      1. is the chunk corresponding to the write request bit 1;
      2. Set the corresponding bit bitmap_attr to Bitmap_page_dirty;
      3. Use *BMC to make a write request count that has not yet been completed.

The specific process is as follows:

    1. If it is delayed write, increase the delay write count;
    2. Because a write operation involves data segments that may correspond to multiple data blocks (Bitmap-chunk the specified size), for each such block of data:

A) Gets the bitmap memory structure of the data block, which is the content of the BP array;

b) If the data block corresponding to the counter reached the maximum, the disk array on the data area of the write access has been too many, the disk array to wait too long, at this time need to start the device queue processing;

c) If there is no in-progress write operation on the block (*BMC is 0), set filemap corresponding bit, set the Bitmap_attr property of the bitmap page to Bitmap_page_dirty, count the number of dirty chunk on the page, The corresponding count *BMC of the data block is set directly to 2;

D) If the memory bitmap for the block of data is already set, the *BMC directly to 2;

e) The corresponding BMC count is cumulative.

The main work of Bitmap_unplug () is to traverse all filemap pages of bitmap:

    1. If the page property is Bitmap_page_dirty, the page is written to disk, and Bitmap_page_dirty is cleared. Waits for the write to return after the end.
    2. If the page property is Bitmap_page_needwrite, the page is written to disk, and Bitmap_page_needwrite is cleared. Return.

It is important to note that if there is only bitmap_page_needwrite labeled pages, there is no need to wait, because the bit cleanup is not critical, even if the information is lost, the most is redundant synchronous operation, no side effects. While the bit settings, you need to ensure that the disk is written "reliable" before the disk array chunk write, otherwise, when the chunk data is written to disk, the corresponding bitmap bit before writing to the disk, the disk array anomalies, it may lead to inconsistent data and bitmap can not be detected.

The Bitmap_unplug () function implements the following two mechanisms:

Implement Bitmap Sync Brush Disk :

    1. The execution of the unplug function is performed before the write is issued. RAID1 daemon Execution Flush_pending_writes (), this process first call Bitmap_unplug () processing, call Generic_make_request () issued chunk data write request;
    2. The unplug function is not exited until the bit is completely closed. When the page property is Bitmap_page_dirty, Bitmap_unplug () waits for the Write_page () write to complete before exiting. The bitmap synchronous brush disk is implemented to ensure the reliability of the data.

Implement Bitmap Batch Brush Disk :

    1. Bitmap_startwrite and Bitmap_unplug two-step implementation. Bitmap_unplug to traverse all bitmap file caches page,bitmap_startwrite only the page of the bitmap file cache corresponding to a write operation.

Bitmap_endwrite () , after writing, take out the bitmap memory structure of the corresponding data segment:

    1. Count decrements;
    2. If count<=2, sets the Bitmap_page_clean property of the corresponding Filemap page;
    3. If there is a chunk write failure, the needed flag for the *BMC corresponding to the bitmap is set. Indicates that synchronization is required.

The specific function code flow is as follows:


3. Settings for the synchronization process bitmap

Bitmap_start_sync (). This function is called at the beginning of the chunk synchronization operation. This function gets the memory structure of the bitmap:

    1. If the needed flag or the Resync flag is set, it is assumed that the data block needs to be synchronized;
    2. At this time if the disk array work intact, then clear the needed flag, set the Resync flag;
    3. If both needed and Resync are not set, the data block is considered not to be synchronized.

Bitmap_end_sync (). After the chunk synchronization is complete, call the function. This function gets the memory structure of the bitmap:

    1. If the Resync flag is set, the flag is cleared;
    2. If the synchronization is unsuccessful, set the need bit;
    3. If the synchronization succeeds and count<=2, the page property is set to Bitmap_page_clean, indicating that the page has bit bits that need to be purged.

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

Bitmap source code Analysis in MD--Setup process

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.