@@ -3099,6 +3099,31 @@ static struct extent_buffer *__alloc_extent_buffer(struct extent_io_tree *tree,
return eb;
}
+/*
+ * Used for releasing extent buffer page.
+ *
+ * can't release the first page of extent buffer at the beginning, because
+ * extent_buffer_page() gets address_space just by the first page->mapping,
+ * and then gets other pages.
+ */
+static void __release_extent_buffer_page(struct extent_buffer *eb)
+{
+ unsigned long index, num_pages;
+ struct page *page;
+
+ num_pages = num_extent_pages(eb->start, eb->len);
+ for (index = 1; index < num_pages; index++) {
+ page = extent_buffer_page(eb, index);
+ if (page)
+ page_cache_release(page);
+ else
+ break;
+ }
+ page = extent_buffer_page(eb, 0);
+ if (page)
+ page_cache_release(page);
+}
+
static void __free_extent_buffer(struct extent_buffer *eb)
{
#if LEAK_DEBUG
@@ -3187,9 +3212,7 @@ struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree,
free_eb:
if (!atomic_dec_and_test(&eb->refs))
return exists;
- for (index = 1; index < i; index++)
- page_cache_release(extent_buffer_page(eb, index));
- page_cache_release(extent_buffer_page(eb, 0));
+ __release_extent_buffer_page(eb);
__free_extent_buffer(eb);
return exists;
}
@@ -3863,9 +3886,7 @@ int try_release_extent_buffer(struct extent_io_tree *tree, struct page *page)
goto out;
}
/* at this point we can safely release the extent buffer */
- num_pages = num_extent_pages(eb->start, eb->len);
- for (i = 0; i < num_pages; i++)
- page_cache_release(extent_buffer_page(eb, i));
+ __release_extent_buffer_page(eb);
rb_erase(&eb->rb_node, &tree->buffer);
__free_extent_buffer(eb);
out: