提交 aee35e4b 编写于 作者: Q Qu Wenruo 提交者: David Sterba

btrfs: raid56: avoid double for loop inside alloc_rbio_essential_pages()

The double loop is just checking if the page for the vertical stripe
is allocated.

We can easily convert it to single loop and get rid of @stripe variable.
Signed-off-by: NQu Wenruo <wqu@suse.com>
Reviewed-by: NDavid Sterba <dsterba@suse.com>
Signed-off-by: NDavid Sterba <dsterba@suse.com>
上级 ef340fcc
...@@ -2380,24 +2380,23 @@ void raid56_add_scrub_pages(struct btrfs_raid_bio *rbio, struct page *page, ...@@ -2380,24 +2380,23 @@ void raid56_add_scrub_pages(struct btrfs_raid_bio *rbio, struct page *page,
static int alloc_rbio_essential_pages(struct btrfs_raid_bio *rbio) static int alloc_rbio_essential_pages(struct btrfs_raid_bio *rbio)
{ {
const u32 sectorsize = rbio->bioc->fs_info->sectorsize; const u32 sectorsize = rbio->bioc->fs_info->sectorsize;
int stripe; int total_sector_nr;
int sectornr;
for_each_set_bit(sectornr, &rbio->dbitmap, rbio->stripe_nsectors) { for (total_sector_nr = 0; total_sector_nr < rbio->nr_sectors;
for (stripe = 0; stripe < rbio->real_stripes; stripe++) { total_sector_nr++) {
struct page *page; struct page *page;
int index = (stripe * rbio->stripe_nsectors + sectornr) * int sectornr = total_sector_nr % rbio->stripe_nsectors;
sectorsize >> PAGE_SHIFT; int index = (total_sector_nr * sectorsize) >> PAGE_SHIFT;
if (!test_bit(sectornr, &rbio->dbitmap))
continue;
if (rbio->stripe_pages[index]) if (rbio->stripe_pages[index])
continue; continue;
page = alloc_page(GFP_NOFS); page = alloc_page(GFP_NOFS);
if (!page) if (!page)
return -ENOMEM; return -ENOMEM;
rbio->stripe_pages[index] = page; rbio->stripe_pages[index] = page;
} }
}
index_stripe_sectors(rbio); index_stripe_sectors(rbio);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册