Linux kernel MD Source code interpretation 13 RAID5 heavy Probation

Source: Internet
Author: User
Tags thread

In the previous section we talked about the failure of the Raid5_align_endio, which joins the request in the array retry list in the callback function, and after the raid5d thread is awakened, the RAID5D thread calls the request Retry_aligned_read function for heavy probation:

4539static int  retry_aligned_read (struct r5conf *conf, struct bio *raid_bio)  
4540{4541/     * We Able to submit a whole bio at once as there 
4542     * May is enough stripe_heads. 
4543     * We cannot pre-allocate enough stripe_heads as we may need 
4544     * More than exist in the cache (if We Llow ever large chunks). 
4545 * So we did one stripe head at the a time and the 
4546 *->bi_hw_segments How many have the done     . 
4547     * 
4548     * We *know* that this entire raid_bio are in one chunk and so 
4549     * It would be onl Y one ' dd_idx ' and only need one call to Raid5_compute_sector. 
4550     *

If there is not enough struct stripe_head structure, we are not able to submit the request in a one-time. We also cannot reserve enough struct stripe_head structure in advance, so we submit one struct stripe_head at a time and the submitted records in the Bio->bi_hw_segments field.

Because it is in the bar, so the Raid_bio request interval is within a bar, so we only need to call once raid5_compute_sector to compute the corresponding disk subscript dd_idx.

After reading the comments section above, we know that the Bio->bi_hw_segment field is used to record the number of struct stripe_head that have been issued, how to use it specifically? Let's continue to look at the code:

4558     logical_sector = raid_bio->bi_sector & ~ ((sector_t) stripe_sectors-1);  
4559     sector = raid5_compute_sector (conf, logical_sector,  
4560                          0, &dd_idx, NULL);  
4561     last_sector = Raid_bio->bi_sector + (raid_bio->bi_size>>9);

4558 lines, calculate the stripe sector corresponding to the request start sector, because the basic unit of the read operation is stripe size, that is, a page size

4559 lines, compute the corresponding disk subscript dd_idx, offset sector on the disk

4561 line, request end sector

 4563 for (; Logical_sector < last_sector; 4564 Logical_sector + = stripe_sectors, 4565 sector + + stripe_sectors, 4566 scnt++ {4567 4568 if (scnt < Raid5_bi_processed_stripes (Raid_bio)) 4569/* already done this s  
Tripe * * 4570 continue;  
4571 4572 sh = get_active_stripe (conf, sector, 0, 1, 0); 4573 4574 if (!sh) {4575/* failed to get a stripe-must wait */4576 Raid5_set  
_bi_processed_stripes (Raid_bio, SCNT);  
4577 conf->retry_read_aligned = Raid_bio;  
4578 return handled; 4579} 4580 4581 if (!add_stripe_bio (SH, Raid_bio, DD_IDX, 0)) {4582 release_stripe  
(SH);  
4583 raid5_set_bi_processed_stripes (Raid_bio, SCNT);  
4584 conf->retry_read_aligned = Raid_bio;  
4585 return handled;  4586} 4587 4588        Set_bit (R5_readnomerge, &sh->dev[dd_idx].flags);  
4589 handle_stripe (SH);  
4590 release_stripe (SH);  
4591 handled++; 4592} 

4563 lines, for each of the stripe in the bar, for example, the bar is 64kb,stripe to 4KB, request for the entire bar, then this need to cycle 16 times. 4568 lines, if the request has been issued stripe, then jump over. As we have said in the note above, we have used bio->bi_hw_segments to represent the number of stripe that have been issued in a request. For example, once only issued 8 stripe, with the continue so the next time you come in this function will continue to be issued after the 8 stripe. 4572 line, get sector corresponding stripe_head4574 line, if not apply to Stripe_head, then save the number of stripe already issued, the request Raid_bio saved to the array retry_read_aligned pointer, The next time you wake up raid5d get the bio from the pointer and continue to stripe the request. 4578 lines, return the stripe number 4581 lines, add the bio to the Stripe_head request list

4582 line, if add failure, release stripe_head, record stripe quantity, save heavy probation request

4588 lines, setting block layer does not require merging flags

4589 lines, Handling stripe

4590 lines, descending stripe count

4591 lines, increase the number of processing stripe

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.