@@ -3144,17 +3144,24 @@ static void end_bio_extent_readpage(struct bio *bio)
*/
int btrfs_alloc_page_array(unsigned long nr_pages, struct page **page_array)
{
- int i;
- for (i = 0; i < nr_pages; i++) {
- struct page *page;
- if (page_array[i])
+ long allocated = 0;
+ for (;;) {
+ long last = allocated;
+
+ allocated = alloc_pages_bulk_array(GFP_NOFS, nr_pages,
+ page_array);
+ if (allocated == nr_pages)
+ return 0;
+
+ if (allocated != last)
continue;
- page = alloc_page(GFP_NOFS);
- if (!page)
- return -ENOMEM;
- page_array[i] = page;
+ /*
+ * During this iteration, no page could be allocated, even
+ * though alloc_pages_bulk_array() falls back to alloc_page()
+ * if it could not bulk-allocate. So we must be out of memory.
+ */
+ return -ENOMEM;
}
- return 0;
}
/*