summaryrefslogtreecommitdiff
path: root/fs/btrfs/raid56.c
diff options
context:
space:
mode:
authorSweet Tea Dorminy <sweettea-kernel@dorminy.me>2022-03-30 23:11:22 +0300
committerDavid Sterba <dsterba@suse.com>2022-05-16 18:03:11 +0300
commitdd137dd1f2d719682b522d4eabe6dec461b7d6fa (patch)
treebc566f7f1b070e24604cc790070ee1955c80572b /fs/btrfs/raid56.c
parent0d031dc4aa05819beb8b9188f4306a3f2bc17f55 (diff)
downloadlinux-dd137dd1f2d719682b522d4eabe6dec461b7d6fa.tar.xz
btrfs: factor out allocating an array of pages
Several functions currently populate an array of page pointers one allocated page at a time. Factor out the common code so as to allow improvements to all of the sites at once. Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Sweet Tea Dorminy <sweettea-kernel@dorminy.me> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/raid56.c')
-rw-r--r--fs/btrfs/raid56.c29
1 files changed, 4 insertions, 25 deletions
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
index 0e239a4c3b26..ba6f6be77121 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -1026,37 +1026,16 @@ static struct btrfs_raid_bio *alloc_rbio(struct btrfs_fs_info *fs_info,
/* allocate pages for all the stripes in the bio, including parity */
static int alloc_rbio_pages(struct btrfs_raid_bio *rbio)
{
- int i;
- struct page *page;
-
- for (i = 0; i < rbio->nr_pages; i++) {
- if (rbio->stripe_pages[i])
- continue;
- page = alloc_page(GFP_NOFS);
- if (!page)
- return -ENOMEM;
- rbio->stripe_pages[i] = page;
- }
- return 0;
+ return btrfs_alloc_page_array(rbio->nr_pages, rbio->stripe_pages);
}
/* only allocate pages for p/q stripes */
static int alloc_rbio_parity_pages(struct btrfs_raid_bio *rbio)
{
- int i;
- struct page *page;
-
- i = rbio_stripe_page_index(rbio, rbio->nr_data, 0);
+ int data_pages = rbio_stripe_page_index(rbio, rbio->nr_data, 0);
- for (; i < rbio->nr_pages; i++) {
- if (rbio->stripe_pages[i])
- continue;
- page = alloc_page(GFP_NOFS);
- if (!page)
- return -ENOMEM;
- rbio->stripe_pages[i] = page;
- }
- return 0;
+ return btrfs_alloc_page_array(rbio->nr_pages - data_pages,
+ rbio->stripe_pages + data_pages);
}
/*