aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2008-04-18 10:29:50 -0400
committerChris Mason <chris.mason@oracle.com>2008-09-25 11:04:02 -0400
commit7b13b7b119c932a5eca486db4113f4c1fe3b97a8 (patch)
treecf4432c69f660f0c22c1b6415c0d907ba6d44c8a
parent7ae9c09d8f001eb19ee2ba219dc5c3d4f6d60614 (diff)
Btrfs: Don't drop extent_map cache during releasepage on the btree inode
The btree inode should only have a single extent_map in the cache, it doesn't make sense to ever drop it. Signed-off-by: Chris Mason <chris.mason@oracle.com>
-rw-r--r--fs/btrfs/disk-io.c23
-rw-r--r--fs/btrfs/extent_io.c38
-rw-r--r--fs/btrfs/extent_io.h3
3 files changed, 44 insertions, 20 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 76ee7a4ae00c..2de2b00afebc 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -76,13 +76,12 @@ struct extent_map *btree_get_extent(struct inode *inode, struct page *page,
76 struct extent_map *em; 76 struct extent_map *em;
77 int ret; 77 int ret;
78 78
79again:
80 spin_lock(&em_tree->lock); 79 spin_lock(&em_tree->lock);
81 em = lookup_extent_mapping(em_tree, start, len); 80 em = lookup_extent_mapping(em_tree, start, len);
82 spin_unlock(&em_tree->lock); 81 spin_unlock(&em_tree->lock);
83 if (em) { 82 if (em)
84 goto out; 83 goto out;
85 } 84
86 em = alloc_extent_map(GFP_NOFS); 85 em = alloc_extent_map(GFP_NOFS);
87 if (!em) { 86 if (!em) {
88 em = ERR_PTR(-ENOMEM); 87 em = ERR_PTR(-ENOMEM);
@@ -95,15 +94,21 @@ again:
95 94
96 spin_lock(&em_tree->lock); 95 spin_lock(&em_tree->lock);
97 ret = add_extent_mapping(em_tree, em); 96 ret = add_extent_mapping(em_tree, em);
98 spin_unlock(&em_tree->lock);
99
100 if (ret == -EEXIST) { 97 if (ret == -EEXIST) {
101 free_extent_map(em); 98 free_extent_map(em);
102 em = NULL; 99 em = lookup_extent_mapping(em_tree, start, len);
103 goto again; 100 if (em)
101 ret = 0;
102 else
103 ret = -EIO;
104 } else if (ret) { 104 } else if (ret) {
105 em = ERR_PTR(ret); 105 free_extent_map(em);
106 em = NULL;
106 } 107 }
108 spin_unlock(&em_tree->lock);
109
110 if (ret)
111 em = ERR_PTR(ret);
107out: 112out:
108 return em; 113 return em;
109} 114}
@@ -496,7 +501,7 @@ static int btree_releasepage(struct page *page, gfp_t gfp_flags)
496 } 501 }
497 tree = &BTRFS_I(page->mapping->host)->io_tree; 502 tree = &BTRFS_I(page->mapping->host)->io_tree;
498 map = &BTRFS_I(page->mapping->host)->extent_tree; 503 map = &BTRFS_I(page->mapping->host)->extent_tree;
499 ret = try_release_extent_mapping(map, tree, page, gfp_flags); 504 ret = try_release_extent_state(map, tree, page, gfp_flags);
500 if (ret == 1) { 505 if (ret == 1) {
501 invalidate_extent_lru(tree, page_offset(page), PAGE_CACHE_SIZE); 506 invalidate_extent_lru(tree, page_offset(page), PAGE_CACHE_SIZE);
502 ClearPagePrivate(page); 507 ClearPagePrivate(page);
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index a984a7bc1197..81f8b4fd069b 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -2464,6 +2464,31 @@ err:
2464EXPORT_SYMBOL(extent_prepare_write); 2464EXPORT_SYMBOL(extent_prepare_write);
2465 2465
2466/* 2466/*
2467 * a helper for releasepage, this tests for areas of the page that
2468 * are locked or under IO and drops the related state bits if it is safe
2469 * to drop the page.
2470 */
2471int try_release_extent_state(struct extent_map_tree *map,
2472 struct extent_io_tree *tree, struct page *page,
2473 gfp_t mask)
2474{
2475 u64 start = (u64)page->index << PAGE_CACHE_SHIFT;
2476 u64 end = start + PAGE_CACHE_SIZE - 1;
2477 int ret = 1;
2478
2479 if (test_range_bit(tree, start, end, EXTENT_IOBITS, 0))
2480 ret = 0;
2481 else {
2482 if ((mask & GFP_NOFS) == GFP_NOFS)
2483 mask = GFP_NOFS;
2484 clear_extent_bit(tree, start, end, EXTENT_UPTODATE,
2485 1, 1, mask);
2486 }
2487 return ret;
2488}
2489EXPORT_SYMBOL(try_release_extent_state);
2490
2491/*
2467 * a helper for releasepage. As long as there are no locked extents 2492 * a helper for releasepage. As long as there are no locked extents
2468 * in the range corresponding to the page, both state records and extent 2493 * in the range corresponding to the page, both state records and extent
2469 * map records are removed 2494 * map records are removed
@@ -2475,8 +2500,7 @@ int try_release_extent_mapping(struct extent_map_tree *map,
2475 struct extent_map *em; 2500 struct extent_map *em;
2476 u64 start = (u64)page->index << PAGE_CACHE_SHIFT; 2501 u64 start = (u64)page->index << PAGE_CACHE_SHIFT;
2477 u64 end = start + PAGE_CACHE_SIZE - 1; 2502 u64 end = start + PAGE_CACHE_SIZE - 1;
2478 u64 orig_start = start; 2503
2479 int ret = 1;
2480 if ((mask & __GFP_WAIT) && 2504 if ((mask & __GFP_WAIT) &&
2481 page->mapping->host->i_size > 16 * 1024 * 1024) { 2505 page->mapping->host->i_size > 16 * 1024 * 1024) {
2482 u64 len; 2506 u64 len;
@@ -2507,15 +2531,7 @@ int try_release_extent_mapping(struct extent_map_tree *map,
2507 free_extent_map(em); 2531 free_extent_map(em);
2508 } 2532 }
2509 } 2533 }
2510 if (test_range_bit(tree, orig_start, end, EXTENT_IOBITS, 0)) 2534 return try_release_extent_state(map, tree, page, mask);
2511 ret = 0;
2512 else {
2513 if ((mask & GFP_NOFS) == GFP_NOFS)
2514 mask = GFP_NOFS;
2515 clear_extent_bit(tree, orig_start, end, EXTENT_UPTODATE,
2516 1, 1, mask);
2517 }
2518 return ret;
2519} 2535}
2520EXPORT_SYMBOL(try_release_extent_mapping); 2536EXPORT_SYMBOL(try_release_extent_mapping);
2521 2537
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index 232300d13be2..e48346147514 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -110,6 +110,9 @@ void extent_io_tree_empty_lru(struct extent_io_tree *tree);
110int try_release_extent_mapping(struct extent_map_tree *map, 110int try_release_extent_mapping(struct extent_map_tree *map,
111 struct extent_io_tree *tree, struct page *page, 111 struct extent_io_tree *tree, struct page *page,
112 gfp_t mask); 112 gfp_t mask);
113int try_release_extent_state(struct extent_map_tree *map,
114 struct extent_io_tree *tree, struct page *page,
115 gfp_t mask);
113int lock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask); 116int lock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask);
114int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask); 117int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask);
115int extent_read_full_page(struct extent_io_tree *tree, struct page *page, 118int extent_read_full_page(struct extent_io_tree *tree, struct page *page,