diff options
author | Josef Bacik <jbacik@fusionio.com> | 2012-08-17 13:14:17 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@fusionio.com> | 2012-10-01 15:19:03 -0400 |
commit | 5dc562c541e1026df9d43913c2f6b91156e22d32 (patch) | |
tree | a7768100e81b756f2a3edbfcaf99ad77ca7ed605 /fs/btrfs/extent_map.h | |
parent | 224ecce517af3a952321202cdf304c12e138caca (diff) |
Btrfs: turbo charge fsync
At least for the vm workload. Currently on fsync we will
1) Truncate all items in the log tree for the given inode if they exist
and
2) Copy all items for a given inode into the log
The problem with this is that for things like VMs you can have lots of
extents from the fragmented writing behavior, and worst yet you may have
only modified a few extents, not the entire thing. This patch fixes this
problem by tracking which transid modified our extent, and then when we do
the tree logging we find all of the extents we've modified in our current
transaction, sort them and commit them. We also only truncate up to the
xattrs of the inode and copy that stuff in normally, and then just drop any
extents in the range we have that exist in the log already. Here are some
numbers of a 50 meg fio job that does random writes and fsync()s after every
write
Original Patched
SATA drive 82KB/s 140KB/s
Fusion drive 431KB/s 2532KB/s
So around 2-6 times faster depending on your hardware. There are a few
corner cases, for example if you truncate at all we have to do it the old
way since there is no way to be sure what is in the log is ok. This
probably could be done smarter, but if you write-fsync-truncate-write-fsync
you deserve what you get. All this work is in RAM of course so if your
inode gets evicted from cache and you read it in and fsync it we'll do it
the slow way if we are still in the same transaction that we last modified
the inode in.
The biggest cool part of this is that it requires no changes to the recovery
code, so if you fsync with this patch and crash and load an old kernel, it
will run the recovery and be a-ok. I have tested this pretty thoroughly
with an fsync tester and everything comes back fine, as well as xfstests.
Thanks,
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Diffstat (limited to 'fs/btrfs/extent_map.h')
-rw-r--r-- | fs/btrfs/extent_map.h | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/fs/btrfs/extent_map.h b/fs/btrfs/extent_map.h index 1195f09761fe..2388a60bd6e3 100644 --- a/fs/btrfs/extent_map.h +++ b/fs/btrfs/extent_map.h | |||
@@ -23,15 +23,18 @@ struct extent_map { | |||
23 | u64 orig_start; | 23 | u64 orig_start; |
24 | u64 block_start; | 24 | u64 block_start; |
25 | u64 block_len; | 25 | u64 block_len; |
26 | u64 generation; | ||
26 | unsigned long flags; | 27 | unsigned long flags; |
27 | struct block_device *bdev; | 28 | struct block_device *bdev; |
28 | atomic_t refs; | 29 | atomic_t refs; |
29 | unsigned int in_tree; | 30 | unsigned int in_tree; |
30 | unsigned int compress_type; | 31 | unsigned int compress_type; |
32 | struct list_head list; | ||
31 | }; | 33 | }; |
32 | 34 | ||
33 | struct extent_map_tree { | 35 | struct extent_map_tree { |
34 | struct rb_root map; | 36 | struct rb_root map; |
37 | struct list_head modified_extents; | ||
35 | rwlock_t lock; | 38 | rwlock_t lock; |
36 | }; | 39 | }; |
37 | 40 | ||
@@ -60,7 +63,7 @@ struct extent_map *alloc_extent_map(void); | |||
60 | void free_extent_map(struct extent_map *em); | 63 | void free_extent_map(struct extent_map *em); |
61 | int __init extent_map_init(void); | 64 | int __init extent_map_init(void); |
62 | void extent_map_exit(void); | 65 | void extent_map_exit(void); |
63 | int unpin_extent_cache(struct extent_map_tree *tree, u64 start, u64 len); | 66 | int unpin_extent_cache(struct extent_map_tree *tree, u64 start, u64 len, u64 gen); |
64 | struct extent_map *search_extent_mapping(struct extent_map_tree *tree, | 67 | struct extent_map *search_extent_mapping(struct extent_map_tree *tree, |
65 | u64 start, u64 len); | 68 | u64 start, u64 len); |
66 | #endif | 69 | #endif |