Linux kernel MD Source code interpretation of seven array synchronization one: Introducing Array synchronization

Source: Internet
Author: User
Tags thread linux

Array sync in Md_do_sync, so where is the entrance? Where is the array sync trigger point? I've heard of Md_check_recovery, but this is not a synchronized entry point. So the RAID5D function is the entry point, right? If you want to seriously analyze it is not.

The real sync entry point is in the Do_md_run function, which is after running the array run function, there is one line:

5171 Md_wakeup_thread (Mddev->thread);

This is the line that wakes up the raid5d, the RAID5D function is as follows:

4823 static void raid5d (struct md_thread *thread) 4824 {4825 struct mddev *mddev         = thread->mddev;  
4826         struct r5conf *conf = mddev->private;  
4827         int handled;  
4828         struct Blk_plug plug;  
4829   
4830         pr_debug ("+++ raid5d active\n");  
4831   
4832         md_check_recovery (Mddev);

4832 lines, as the name implies is to check synchronization, indicating that this is just a sync checkpoint, not really deal with sync place.

RAID5D the remainder is the place where data flow is processed first, follow Md_check_recovery, read the note first:

 7672/* 7673 * This routine are regularly called by all Per-raid-array threads to 7674 * deal with generic issues 
Like Resync and Super-block update.  7675 * Raid personalities that don ' t have a thread (LINEAR/RAID0) does not 7676 * need this as they never does any recovery 
or update the superblock. 
7677 * 7678 * It does not does any resync itself, but rather "forks" off the other threads 7679 * to do as needed. 7680 * When it's determined that resync are needed, we set md_recovery_running in 7681 * "->recovery" and create a T 
Hread at->sync_thread. 7682 * When the thread finishes it sets Md_recovery_done 7683 * and wakeups up this thread which'll reap the thread A 
nd finish up. 
7684 * This thread also removes the any faulty devices (with nr_pending = 0). 
7685 * 7686 * The overall approach is:7687 * 1/if the superblock needs, update it. 
7688 * 2/if A recovery thread is running, don ' t do anything else. 7689 * 3/if Recovery has finisheD, clean up, possibly marking spares active. 
7690 * 4/if There are any faulty devices, remove them. 7691 * 5/if array is degraded, try to add spares devices 7692 * 6/if array has spares or are not in-sync, start a re 
Sync Thread. 7693 */

This function is typically called by the array main thread to handle events such as synchronization and Super block updates. Arrays without a main thread do not need to be called (such as linear/raid0) because they do not need to rebuild or update the super blocks.

This function does not do anything specific, just start the array synchronization thread on demand.

When the array needs to be synchronized, set the md_recovery_running flag and create a synchronization thread.

Sets the Md_recovery_done flag when the synchronization thread ends, and wakes the main thread to reclaim the synchronization thread and end the synchronization.

This thread is also used to remove bad disks (when nr_pending==0).

This function process is as follows:

1, update the Super block when needed

2, when the synchronization thread is running, it returns

3. When the sync thread ends, recycle the resource and activate the hot spare if the rebuild is done

4, remove the bad disk

5. Add a hot spare to the degraded array

6, have a hot spare but the array is not synchronized state, then start the synchronization thread

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.