Commit 897ca6e9 authored by Miao Xie's avatar Miao Xie Committed by Chris Mason
Browse files

Btrfs: restructure try_release_extent_buffer()



restructure try_release_extent_buffer() and write a function to release the
extent buffer. It will be used later.
Signed-off-by: default avatarMiao Xie <miaox@cn.fujitsu.com>
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent bf9022e0
...@@ -3104,6 +3104,39 @@ static void __free_extent_buffer(struct extent_buffer *eb) ...@@ -3104,6 +3104,39 @@ static void __free_extent_buffer(struct extent_buffer *eb)
kmem_cache_free(extent_buffer_cache, eb); kmem_cache_free(extent_buffer_cache, eb);
} }
/*
* Helper for releasing extent buffer page.
*/
static void btrfs_release_extent_buffer_page(struct extent_buffer *eb,
unsigned long start_idx)
{
unsigned long index;
struct page *page;
if (!eb->first_page)
return;
index = num_extent_pages(eb->start, eb->len);
if (start_idx >= index)
return;
do {
index--;
page = extent_buffer_page(eb, index);
if (page)
page_cache_release(page);
} while (index != start_idx);
}
/*
* Helper for releasing the extent buffer.
*/
static inline void btrfs_release_extent_buffer(struct extent_buffer *eb)
{
btrfs_release_extent_buffer_page(eb, 0);
__free_extent_buffer(eb);
}
struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree, struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree,
u64 start, unsigned long len, u64 start, unsigned long len,
struct page *page0, struct page *page0,
...@@ -3181,10 +3214,7 @@ struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree, ...@@ -3181,10 +3214,7 @@ struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree,
free_eb: free_eb:
if (!atomic_dec_and_test(&eb->refs)) if (!atomic_dec_and_test(&eb->refs))
return exists; return exists;
for (index = 1; index < i; index++) btrfs_release_extent_buffer(eb);
page_cache_release(extent_buffer_page(eb, index));
page_cache_release(extent_buffer_page(eb, 0));
__free_extent_buffer(eb);
return exists; return exists;
} }
...@@ -3838,8 +3868,6 @@ int try_release_extent_buffer(struct extent_io_tree *tree, struct page *page) ...@@ -3838,8 +3868,6 @@ int try_release_extent_buffer(struct extent_io_tree *tree, struct page *page)
u64 start = page_offset(page); u64 start = page_offset(page);
struct extent_buffer *eb; struct extent_buffer *eb;
int ret = 1; int ret = 1;
unsigned long i;
unsigned long num_pages;
spin_lock(&tree->buffer_lock); spin_lock(&tree->buffer_lock);
eb = buffer_search(tree, start); eb = buffer_search(tree, start);
...@@ -3854,12 +3882,10 @@ int try_release_extent_buffer(struct extent_io_tree *tree, struct page *page) ...@@ -3854,12 +3882,10 @@ int try_release_extent_buffer(struct extent_io_tree *tree, struct page *page)
ret = 0; ret = 0;
goto out; 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));
rb_erase(&eb->rb_node, &tree->buffer); rb_erase(&eb->rb_node, &tree->buffer);
__free_extent_buffer(eb); /* at this point we can safely release the extent buffer */
btrfs_release_extent_buffer(eb);
out: out:
spin_unlock(&tree->buffer_lock); spin_unlock(&tree->buffer_lock);
return ret; return ret;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment