diff options
author | Josef Bacik <josef@redhat.com> | 2010-02-02 16:48:28 -0500 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2010-03-15 11:00:12 -0400 |
commit | 49958fd7dbb83cd4d65179d025940e01fe1fbacd (patch) | |
tree | 4a29e47c0935375968971450a2f2949bbd3cdd43 /fs/btrfs | |
parent | 4125bf761cd0786e1163e024c7c809ce2cc625bc (diff) |
Btrfs: change the ordered tree to use a spinlock instead of a mutex
The ordered tree used to need a mutex, but currently all we use it for is to
protect the rb_tree, and a spin_lock is just fine for that. Using a spin_lock
instead makes dbench run a little faster, 58 mb/s instead of 51 mb/s, and have
less latency, 3445.138 ms instead of 3820.633 ms.
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/ordered-data.c | 34 | ||||
-rw-r--r-- | fs/btrfs/ordered-data.h | 4 |
2 files changed, 19 insertions, 19 deletions
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index 5c2a9e78a949..d56f732ba95e 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c | |||
@@ -174,7 +174,6 @@ int btrfs_add_ordered_extent(struct inode *inode, u64 file_offset, | |||
174 | if (!entry) | 174 | if (!entry) |
175 | return -ENOMEM; | 175 | return -ENOMEM; |
176 | 176 | ||
177 | mutex_lock(&tree->mutex); | ||
178 | entry->file_offset = file_offset; | 177 | entry->file_offset = file_offset; |
179 | entry->start = start; | 178 | entry->start = start; |
180 | entry->len = len; | 179 | entry->len = len; |
@@ -190,16 +189,17 @@ int btrfs_add_ordered_extent(struct inode *inode, u64 file_offset, | |||
190 | INIT_LIST_HEAD(&entry->list); | 189 | INIT_LIST_HEAD(&entry->list); |
191 | INIT_LIST_HEAD(&entry->root_extent_list); | 190 | INIT_LIST_HEAD(&entry->root_extent_list); |
192 | 191 | ||
192 | spin_lock(&tree->lock); | ||
193 | node = tree_insert(&tree->tree, file_offset, | 193 | node = tree_insert(&tree->tree, file_offset, |
194 | &entry->rb_node); | 194 | &entry->rb_node); |
195 | BUG_ON(node); | 195 | BUG_ON(node); |
196 | spin_unlock(&tree->lock); | ||
196 | 197 | ||
197 | spin_lock(&BTRFS_I(inode)->root->fs_info->ordered_extent_lock); | 198 | spin_lock(&BTRFS_I(inode)->root->fs_info->ordered_extent_lock); |
198 | list_add_tail(&entry->root_extent_list, | 199 | list_add_tail(&entry->root_extent_list, |
199 | &BTRFS_I(inode)->root->fs_info->ordered_extents); | 200 | &BTRFS_I(inode)->root->fs_info->ordered_extents); |
200 | spin_unlock(&BTRFS_I(inode)->root->fs_info->ordered_extent_lock); | 201 | spin_unlock(&BTRFS_I(inode)->root->fs_info->ordered_extent_lock); |
201 | 202 | ||
202 | mutex_unlock(&tree->mutex); | ||
203 | BUG_ON(node); | 203 | BUG_ON(node); |
204 | return 0; | 204 | return 0; |
205 | } | 205 | } |
@@ -216,9 +216,9 @@ int btrfs_add_ordered_sum(struct inode *inode, | |||
216 | struct btrfs_ordered_inode_tree *tree; | 216 | struct btrfs_ordered_inode_tree *tree; |
217 | 217 | ||
218 | tree = &BTRFS_I(inode)->ordered_tree; | 218 | tree = &BTRFS_I(inode)->ordered_tree; |
219 | mutex_lock(&tree->mutex); | 219 | spin_lock(&tree->lock); |
220 | list_add_tail(&sum->list, &entry->list); | 220 | list_add_tail(&sum->list, &entry->list); |
221 | mutex_unlock(&tree->mutex); | 221 | spin_unlock(&tree->lock); |
222 | return 0; | 222 | return 0; |
223 | } | 223 | } |
224 | 224 | ||
@@ -240,7 +240,7 @@ int btrfs_dec_test_ordered_pending(struct inode *inode, | |||
240 | int ret; | 240 | int ret; |
241 | 241 | ||
242 | tree = &BTRFS_I(inode)->ordered_tree; | 242 | tree = &BTRFS_I(inode)->ordered_tree; |
243 | mutex_lock(&tree->mutex); | 243 | spin_lock(&tree->lock); |
244 | node = tree_search(tree, file_offset); | 244 | node = tree_search(tree, file_offset); |
245 | if (!node) { | 245 | if (!node) { |
246 | ret = 1; | 246 | ret = 1; |
@@ -264,7 +264,7 @@ int btrfs_dec_test_ordered_pending(struct inode *inode, | |||
264 | else | 264 | else |
265 | ret = 1; | 265 | ret = 1; |
266 | out: | 266 | out: |
267 | mutex_unlock(&tree->mutex); | 267 | spin_unlock(&tree->lock); |
268 | return ret == 0; | 268 | return ret == 0; |
269 | } | 269 | } |
270 | 270 | ||
@@ -291,7 +291,7 @@ int btrfs_put_ordered_extent(struct btrfs_ordered_extent *entry) | |||
291 | 291 | ||
292 | /* | 292 | /* |
293 | * remove an ordered extent from the tree. No references are dropped | 293 | * remove an ordered extent from the tree. No references are dropped |
294 | * and you must wake_up entry->wait. You must hold the tree mutex | 294 | * and you must wake_up entry->wait. You must hold the tree lock |
295 | * while you call this function. | 295 | * while you call this function. |
296 | */ | 296 | */ |
297 | static int __btrfs_remove_ordered_extent(struct inode *inode, | 297 | static int __btrfs_remove_ordered_extent(struct inode *inode, |
@@ -340,9 +340,9 @@ int btrfs_remove_ordered_extent(struct inode *inode, | |||
340 | int ret; | 340 | int ret; |
341 | 341 | ||
342 | tree = &BTRFS_I(inode)->ordered_tree; | 342 | tree = &BTRFS_I(inode)->ordered_tree; |
343 | mutex_lock(&tree->mutex); | 343 | spin_lock(&tree->lock); |
344 | ret = __btrfs_remove_ordered_extent(inode, entry); | 344 | ret = __btrfs_remove_ordered_extent(inode, entry); |
345 | mutex_unlock(&tree->mutex); | 345 | spin_unlock(&tree->lock); |
346 | wake_up(&entry->wait); | 346 | wake_up(&entry->wait); |
347 | 347 | ||
348 | return ret; | 348 | return ret; |
@@ -567,7 +567,7 @@ struct btrfs_ordered_extent *btrfs_lookup_ordered_extent(struct inode *inode, | |||
567 | struct btrfs_ordered_extent *entry = NULL; | 567 | struct btrfs_ordered_extent *entry = NULL; |
568 | 568 | ||
569 | tree = &BTRFS_I(inode)->ordered_tree; | 569 | tree = &BTRFS_I(inode)->ordered_tree; |
570 | mutex_lock(&tree->mutex); | 570 | spin_lock(&tree->lock); |
571 | node = tree_search(tree, file_offset); | 571 | node = tree_search(tree, file_offset); |
572 | if (!node) | 572 | if (!node) |
573 | goto out; | 573 | goto out; |
@@ -578,7 +578,7 @@ struct btrfs_ordered_extent *btrfs_lookup_ordered_extent(struct inode *inode, | |||
578 | if (entry) | 578 | if (entry) |
579 | atomic_inc(&entry->refs); | 579 | atomic_inc(&entry->refs); |
580 | out: | 580 | out: |
581 | mutex_unlock(&tree->mutex); | 581 | spin_unlock(&tree->lock); |
582 | return entry; | 582 | return entry; |
583 | } | 583 | } |
584 | 584 | ||
@@ -594,7 +594,7 @@ btrfs_lookup_first_ordered_extent(struct inode *inode, u64 file_offset) | |||
594 | struct btrfs_ordered_extent *entry = NULL; | 594 | struct btrfs_ordered_extent *entry = NULL; |
595 | 595 | ||
596 | tree = &BTRFS_I(inode)->ordered_tree; | 596 | tree = &BTRFS_I(inode)->ordered_tree; |
597 | mutex_lock(&tree->mutex); | 597 | spin_lock(&tree->lock); |
598 | node = tree_search(tree, file_offset); | 598 | node = tree_search(tree, file_offset); |
599 | if (!node) | 599 | if (!node) |
600 | goto out; | 600 | goto out; |
@@ -602,7 +602,7 @@ btrfs_lookup_first_ordered_extent(struct inode *inode, u64 file_offset) | |||
602 | entry = rb_entry(node, struct btrfs_ordered_extent, rb_node); | 602 | entry = rb_entry(node, struct btrfs_ordered_extent, rb_node); |
603 | atomic_inc(&entry->refs); | 603 | atomic_inc(&entry->refs); |
604 | out: | 604 | out: |
605 | mutex_unlock(&tree->mutex); | 605 | spin_unlock(&tree->lock); |
606 | return entry; | 606 | return entry; |
607 | } | 607 | } |
608 | 608 | ||
@@ -629,7 +629,7 @@ int btrfs_ordered_update_i_size(struct inode *inode, u64 offset, | |||
629 | else | 629 | else |
630 | offset = ALIGN(offset, BTRFS_I(inode)->root->sectorsize); | 630 | offset = ALIGN(offset, BTRFS_I(inode)->root->sectorsize); |
631 | 631 | ||
632 | mutex_lock(&tree->mutex); | 632 | spin_lock(&tree->lock); |
633 | disk_i_size = BTRFS_I(inode)->disk_i_size; | 633 | disk_i_size = BTRFS_I(inode)->disk_i_size; |
634 | 634 | ||
635 | /* truncate file */ | 635 | /* truncate file */ |
@@ -735,7 +735,7 @@ out: | |||
735 | */ | 735 | */ |
736 | if (ordered) | 736 | if (ordered) |
737 | __btrfs_remove_ordered_extent(inode, ordered); | 737 | __btrfs_remove_ordered_extent(inode, ordered); |
738 | mutex_unlock(&tree->mutex); | 738 | spin_unlock(&tree->lock); |
739 | if (ordered) | 739 | if (ordered) |
740 | wake_up(&ordered->wait); | 740 | wake_up(&ordered->wait); |
741 | return ret; | 741 | return ret; |
@@ -762,7 +762,7 @@ int btrfs_find_ordered_sum(struct inode *inode, u64 offset, u64 disk_bytenr, | |||
762 | if (!ordered) | 762 | if (!ordered) |
763 | return 1; | 763 | return 1; |
764 | 764 | ||
765 | mutex_lock(&tree->mutex); | 765 | spin_lock(&tree->lock); |
766 | list_for_each_entry_reverse(ordered_sum, &ordered->list, list) { | 766 | list_for_each_entry_reverse(ordered_sum, &ordered->list, list) { |
767 | if (disk_bytenr >= ordered_sum->bytenr) { | 767 | if (disk_bytenr >= ordered_sum->bytenr) { |
768 | num_sectors = ordered_sum->len / sectorsize; | 768 | num_sectors = ordered_sum->len / sectorsize; |
@@ -777,7 +777,7 @@ int btrfs_find_ordered_sum(struct inode *inode, u64 offset, u64 disk_bytenr, | |||
777 | } | 777 | } |
778 | } | 778 | } |
779 | out: | 779 | out: |
780 | mutex_unlock(&tree->mutex); | 780 | spin_unlock(&tree->lock); |
781 | btrfs_put_ordered_extent(ordered); | 781 | btrfs_put_ordered_extent(ordered); |
782 | return ret; | 782 | return ret; |
783 | } | 783 | } |
diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h index 9116c6d0c5a9..bfbcebbb0adc 100644 --- a/fs/btrfs/ordered-data.h +++ b/fs/btrfs/ordered-data.h | |||
@@ -21,7 +21,7 @@ | |||
21 | 21 | ||
22 | /* one of these per inode */ | 22 | /* one of these per inode */ |
23 | struct btrfs_ordered_inode_tree { | 23 | struct btrfs_ordered_inode_tree { |
24 | struct mutex mutex; | 24 | spinlock_t lock; |
25 | struct rb_root tree; | 25 | struct rb_root tree; |
26 | struct rb_node *last; | 26 | struct rb_node *last; |
27 | }; | 27 | }; |
@@ -128,7 +128,7 @@ static inline int btrfs_ordered_sum_size(struct btrfs_root *root, | |||
128 | static inline void | 128 | static inline void |
129 | btrfs_ordered_inode_tree_init(struct btrfs_ordered_inode_tree *t) | 129 | btrfs_ordered_inode_tree_init(struct btrfs_ordered_inode_tree *t) |
130 | { | 130 | { |
131 | mutex_init(&t->mutex); | 131 | spin_lock_init(&t->lock); |
132 | t->tree = RB_ROOT; | 132 | t->tree = RB_ROOT; |
133 | t->last = NULL; | 133 | t->last = NULL; |
134 | } | 134 | } |