Interpretation of the Linux kernel MD source code nine array RAID5 synchronization function Sync_reque

Source: Internet
Author: User
Tags linux

Welcome to use ueditor!

Let's take a look at the whole scene again:

1 Call the Md_wakeup_thread wake main thread when running the array

2 main thread call Md_check_recovery check Sync
3) Md_check_recovery function to check the need to synchronize calls Md_register_thread create a sync thread

4 synchronization thread calls the Md_do_sync function to handle the synchronization process

5 Md_do_sync do synchronization process management, step by step synchronization point, record Sync completion point, call sync_request for various array level synchronization

6) Sync_request to do the distribution of synchronized data flow

For RAID5 arrays, synchronization is distributed according to Struct Stripe_head as the base unit. For example, we now want to fry a potato into potato chips, then the first to cut potatoes into slices, and then put the potato chips into the frying pan, blown up and then fished up to box. So Md_do_sync's role is to slice the potatoes, the size of the slice is stripe_sectors size. Sync_request received this potato chips can not immediately after the pot, to use struct stripe_head to wrap it, this is similar to the potato chip outside the brush a layer of seasoning. Then call the handle_stripe for processing and eventually sent to disk, which is similar to the potato chips in the frying process. The last call to Bitmap_cond_end_sync saves the sync completion record, which is similar to recycling potato chips and boxed.

There is also a detail here, that is, to periodically save the synchronization results, every few seconds will wait for all synchronization requests to return to record. This is similar to this fried potato pot is very small, can only put 20 slices of potatoes, at the beginning we kept the potato chips, and so on 20, we stopped directly to all the potatoes are ripe and then a one-time salvage, and then put 20, repeat the above process.

Understand the above processing mechanism, and then look at the code is very easy.

 4453 Static inline sector_t sync_request (struct Mddev *mddev, sector_t sector_nr, int *skipped, int go_faster) 445  
4 {4455 struct r5conf *conf = mddev->private;  
4456 struct Stripe_head *sh;  
4457 sector_t max_sector = mddev->dev_sectors;  
4458 sector_t sync_blocks;  
4459 int still_degraded = 0;  
4460 int i; 4461 4462 if (sector_nr >= max_sector) {4463/* just being to finish up ... nothing mu                         CH to do */4464 4465 if (Test_bit (Md_recovery_reshape, &mddev->recovery)) {4466  
End_reshape (conf);  
4467 return 0;                         4468} 4469 4470 if (Mddev->curr_resync < max_sector)/* aborted/4471 Bitmap_end_sync (Mddev->bitmap, Mddev->curr_resync, 4472 &  
Amp;sync_blocks, 1); 4473 Else/* compleTed Sync */4474 conf->fullsync = 0;  
4475 Bitmap_close_sync (MDDEV->BITMAP);  
4476 4477 return 0; 4478} 

This part is handled synchronously, there are two situations in which synchronization is complete, one is normal and the other is interrupted.

4462 lines, complete synchronously.

4470 lines, sync interrupt, notify bitmap last Sync is abort

4474 lines, the synchronization completes successfully, and the update Fullsync to 0,fullsync indicates that the array is to force full synchronization.

4475 lines, notify bitmap sync complete.

Although this part of the code is placed in the front of the function, but this part of the code is Md_do_sync exit the synchronization loop after the 7521 rows of Sync_request call to. The next part is the part of the Md_do_sync loop where the Sync_request will execute:

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.