diff options
author | Filipe David Borba Manana <fdmanana@gmail.com> | 2014-01-07 06:42:27 -0500 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2014-01-28 16:20:23 -0500 |
commit | 1acae57b161ef1282f565ef907f72aeed0eb71d9 (patch) | |
tree | 7234dacef63e67640d780cfb82742762b5e00bfd /fs/btrfs/tree-log.c | |
parent | 90515e7f5d7d24cbb2a4038a3f1b5cfa2921aa17 (diff) |
Btrfs: faster file extent item replace operations
When writing to a file we drop existing file extent items that cover the
write range and then add a new file extent item that represents that write
range.
Before this change we were doing a tree lookup to remove the file extent
items, and then after we did another tree lookup to insert the new file
extent item.
Most of the time all the file extent items we need to drop are located
within a single leaf - this is the leaf where our new file extent item ends
up at. Therefore, in this common case just combine these 2 operations into
a single one.
By avoiding the second btree navigation for insertion of the new file extent
item, we reduce btree node/leaf lock acquisitions/releases, btree block/leaf
COW operations, CPU time on btree node/leaf key binary searches, etc.
Besides for file writes, this is an operation that happens for file fsync's
as well. However log btrees are much less likely to big as big as regular
fs btrees, therefore the impact of this change is smaller.
The following benchmark was performed against an SSD drive and a
HDD drive, both for random and sequential writes:
sysbench --test=fileio --file-num=4096 --file-total-size=8G \
--file-test-mode=[rndwr|seqwr] --num-threads=512 \
--file-block-size=8192 \ --max-requests=1000000 \
--file-fsync-freq=0 --file-io-mode=sync [prepare|run]
All results below are averages of 10 runs of the respective test.
** SSD sequential writes
Before this change: 225.88 Mb/sec
After this change: 277.26 Mb/sec
** SSD random writes
Before this change: 49.91 Mb/sec
After this change: 56.39 Mb/sec
** HDD sequential writes
Before this change: 68.53 Mb/sec
After this change: 69.87 Mb/sec
** HDD random writes
Before this change: 13.04 Mb/sec
After this change: 14.39 Mb/sec
Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs/tree-log.c')
-rw-r--r-- | fs/btrfs/tree-log.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index ba2f15109dac..b561e7a4007d 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c | |||
@@ -3495,21 +3495,27 @@ static int log_one_extent(struct btrfs_trans_handle *trans, | |||
3495 | int ret; | 3495 | int ret; |
3496 | int index = log->log_transid % 2; | 3496 | int index = log->log_transid % 2; |
3497 | bool skip_csum = BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM; | 3497 | bool skip_csum = BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM; |
3498 | 3498 | int extent_inserted = 0; | |
3499 | ret = __btrfs_drop_extents(trans, log, inode, path, em->start, | ||
3500 | em->start + em->len, NULL, 0); | ||
3501 | if (ret) | ||
3502 | return ret; | ||
3503 | 3499 | ||
3504 | INIT_LIST_HEAD(&ordered_sums); | 3500 | INIT_LIST_HEAD(&ordered_sums); |
3505 | btrfs_init_map_token(&token); | 3501 | btrfs_init_map_token(&token); |
3506 | key.objectid = btrfs_ino(inode); | ||
3507 | key.type = BTRFS_EXTENT_DATA_KEY; | ||
3508 | key.offset = em->start; | ||
3509 | 3502 | ||
3510 | ret = btrfs_insert_empty_item(trans, log, path, &key, sizeof(*fi)); | 3503 | ret = __btrfs_drop_extents(trans, log, inode, path, em->start, |
3504 | em->start + em->len, NULL, 0, 1, | ||
3505 | sizeof(*fi), &extent_inserted); | ||
3511 | if (ret) | 3506 | if (ret) |
3512 | return ret; | 3507 | return ret; |
3508 | |||
3509 | if (!extent_inserted) { | ||
3510 | key.objectid = btrfs_ino(inode); | ||
3511 | key.type = BTRFS_EXTENT_DATA_KEY; | ||
3512 | key.offset = em->start; | ||
3513 | |||
3514 | ret = btrfs_insert_empty_item(trans, log, path, &key, | ||
3515 | sizeof(*fi)); | ||
3516 | if (ret) | ||
3517 | return ret; | ||
3518 | } | ||
3513 | leaf = path->nodes[0]; | 3519 | leaf = path->nodes[0]; |
3514 | fi = btrfs_item_ptr(leaf, path->slots[0], | 3520 | fi = btrfs_item_ptr(leaf, path->slots[0], |
3515 | struct btrfs_file_extent_item); | 3521 | struct btrfs_file_extent_item); |