diff options
author | Josef Bacik <josef@redhat.com> | 2010-02-03 14:33:23 -0500 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2010-03-15 11:00:13 -0400 |
commit | 2ac55d41b5d6bf49e76bc85db5431240617e2f8f (patch) | |
tree | ee8e2a716ef0b50388ef5e4a86387ec0499bca89 /fs/btrfs/file.c | |
parent | 5a1a3df1f6c86926cfe8657e6f9b4b4c2f467d60 (diff) |
Btrfs: cache the extent state everywhere we possibly can V2
This patch just goes through and fixes everybody that does
lock_extent()
blah
unlock_extent()
to use
lock_extent_bits()
blah
unlock_extent_cached()
and pass around a extent_state so we only have to do the searches once per
function. This gives me about a 3 mb/s boots on my random write test. I have
not converted some things, like the relocation and ioctl's, since they aren't
heavily used and the relocation stuff is in the middle of being re-written. I
also changed the clear_extent_bit() to only unset the cached state if we are
clearing EXTENT_LOCKED and related stuff, so we can do things like this
lock_extent_bits()
clear delalloc bits
unlock_extent_cached()
without losing our cached state. I tested this thoroughly and turned on
LEAK_DEBUG to make sure we weren't leaking extent states, everything worked out
fine.
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/file.c')
-rw-r--r-- | fs/btrfs/file.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index a7fd9f3a750..d146dde7efb 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -123,7 +123,8 @@ static noinline int dirty_and_release_pages(struct btrfs_trans_handle *trans, | |||
123 | root->sectorsize - 1) & ~((u64)root->sectorsize - 1); | 123 | root->sectorsize - 1) & ~((u64)root->sectorsize - 1); |
124 | 124 | ||
125 | end_of_last_block = start_pos + num_bytes - 1; | 125 | end_of_last_block = start_pos + num_bytes - 1; |
126 | err = btrfs_set_extent_delalloc(inode, start_pos, end_of_last_block); | 126 | err = btrfs_set_extent_delalloc(inode, start_pos, end_of_last_block, |
127 | NULL); | ||
127 | if (err) | 128 | if (err) |
128 | return err; | 129 | return err; |
129 | 130 | ||
@@ -753,6 +754,7 @@ static noinline int prepare_pages(struct btrfs_root *root, struct file *file, | |||
753 | loff_t pos, unsigned long first_index, | 754 | loff_t pos, unsigned long first_index, |
754 | unsigned long last_index, size_t write_bytes) | 755 | unsigned long last_index, size_t write_bytes) |
755 | { | 756 | { |
757 | struct extent_state *cached_state = NULL; | ||
756 | int i; | 758 | int i; |
757 | unsigned long index = pos >> PAGE_CACHE_SHIFT; | 759 | unsigned long index = pos >> PAGE_CACHE_SHIFT; |
758 | struct inode *inode = fdentry(file)->d_inode; | 760 | struct inode *inode = fdentry(file)->d_inode; |
@@ -781,16 +783,18 @@ again: | |||
781 | } | 783 | } |
782 | if (start_pos < inode->i_size) { | 784 | if (start_pos < inode->i_size) { |
783 | struct btrfs_ordered_extent *ordered; | 785 | struct btrfs_ordered_extent *ordered; |
784 | lock_extent(&BTRFS_I(inode)->io_tree, | 786 | lock_extent_bits(&BTRFS_I(inode)->io_tree, |
785 | start_pos, last_pos - 1, GFP_NOFS); | 787 | start_pos, last_pos - 1, 0, &cached_state, |
788 | GFP_NOFS); | ||
786 | ordered = btrfs_lookup_first_ordered_extent(inode, | 789 | ordered = btrfs_lookup_first_ordered_extent(inode, |
787 | last_pos - 1); | 790 | last_pos - 1); |
788 | if (ordered && | 791 | if (ordered && |
789 | ordered->file_offset + ordered->len > start_pos && | 792 | ordered->file_offset + ordered->len > start_pos && |
790 | ordered->file_offset < last_pos) { | 793 | ordered->file_offset < last_pos) { |
791 | btrfs_put_ordered_extent(ordered); | 794 | btrfs_put_ordered_extent(ordered); |
792 | unlock_extent(&BTRFS_I(inode)->io_tree, | 795 | unlock_extent_cached(&BTRFS_I(inode)->io_tree, |
793 | start_pos, last_pos - 1, GFP_NOFS); | 796 | start_pos, last_pos - 1, |
797 | &cached_state, GFP_NOFS); | ||
794 | for (i = 0; i < num_pages; i++) { | 798 | for (i = 0; i < num_pages; i++) { |
795 | unlock_page(pages[i]); | 799 | unlock_page(pages[i]); |
796 | page_cache_release(pages[i]); | 800 | page_cache_release(pages[i]); |
@@ -802,12 +806,13 @@ again: | |||
802 | if (ordered) | 806 | if (ordered) |
803 | btrfs_put_ordered_extent(ordered); | 807 | btrfs_put_ordered_extent(ordered); |
804 | 808 | ||
805 | clear_extent_bits(&BTRFS_I(inode)->io_tree, start_pos, | 809 | clear_extent_bit(&BTRFS_I(inode)->io_tree, start_pos, |
806 | last_pos - 1, EXTENT_DIRTY | EXTENT_DELALLOC | | 810 | last_pos - 1, EXTENT_DIRTY | EXTENT_DELALLOC | |
807 | EXTENT_DO_ACCOUNTING, | 811 | EXTENT_DO_ACCOUNTING, 0, 0, &cached_state, |
808 | GFP_NOFS); | 812 | GFP_NOFS); |
809 | unlock_extent(&BTRFS_I(inode)->io_tree, | 813 | unlock_extent_cached(&BTRFS_I(inode)->io_tree, |
810 | start_pos, last_pos - 1, GFP_NOFS); | 814 | start_pos, last_pos - 1, &cached_state, |
815 | GFP_NOFS); | ||
811 | } | 816 | } |
812 | for (i = 0; i < num_pages; i++) { | 817 | for (i = 0; i < num_pages; i++) { |
813 | clear_page_dirty_for_io(pages[i]); | 818 | clear_page_dirty_for_io(pages[i]); |