Skip to content

Commit 5d13a98

Browse files
committed
Btrfs: readahead checksums during btrfs_finish_ordered_io
This reads in blocks in the checksum btree before starting the transaction in btrfs_finish_ordered_io. It makes it much more likely we'll be able to do operations inside the transaction without needing any btree reads, which limits transaction latencies overall. Signed-off-by: Chris Mason <chris.mason@oracle.com>
1 parent b947343 commit 5d13a98

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

fs/btrfs/inode.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,6 +1497,30 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans,
14971497
return 0;
14981498
}
14991499

1500+
/*
1501+
* helper function for btrfs_finish_ordered_io, this
1502+
* just reads in some of the csum leaves to prime them into ram
1503+
* before we start the transaction. It limits the amount of btree
1504+
* reads required while inside the transaction.
1505+
*/
1506+
static noinline void reada_csum(struct btrfs_root *root,
1507+
struct btrfs_path *path,
1508+
struct btrfs_ordered_extent *ordered_extent)
1509+
{
1510+
struct btrfs_ordered_sum *sum;
1511+
u64 bytenr;
1512+
1513+
sum = list_entry(ordered_extent->list.next, struct btrfs_ordered_sum,
1514+
list);
1515+
bytenr = sum->sums[0].bytenr;
1516+
1517+
/*
1518+
* we don't care about the results, the point of this search is
1519+
* just to get the btree leaves into ram
1520+
*/
1521+
btrfs_lookup_csum(NULL, root->fs_info->csum_root, path, bytenr, 0);
1522+
}
1523+
15001524
/* as ordered data IO finishes, this gets called so we can finish
15011525
* an ordered extent if the range of bytes in the file it covers are
15021526
* fully written.
@@ -1505,7 +1529,7 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end)
15051529
{
15061530
struct btrfs_root *root = BTRFS_I(inode)->root;
15071531
struct btrfs_trans_handle *trans;
1508-
struct btrfs_ordered_extent *ordered_extent;
1532+
struct btrfs_ordered_extent *ordered_extent = NULL;
15091533
struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
15101534
struct btrfs_path *path;
15111535
int compressed = 0;
@@ -1528,13 +1552,20 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end)
15281552
ret = btrfs_lookup_file_extent(NULL, root, path,
15291553
inode->i_ino,
15301554
start, 0);
1555+
ordered_extent = btrfs_lookup_ordered_extent(inode,
1556+
start);
1557+
if (!list_empty(&ordered_extent->list)) {
1558+
btrfs_release_path(root, path);
1559+
reada_csum(root, path, ordered_extent);
1560+
}
15311561
btrfs_free_path(path);
15321562
}
15331563
}
15341564

15351565
trans = btrfs_join_transaction(root, 1);
15361566

1537-
ordered_extent = btrfs_lookup_ordered_extent(inode, start);
1567+
if (!ordered_extent)
1568+
ordered_extent = btrfs_lookup_ordered_extent(inode, start);
15381569
BUG_ON(!ordered_extent);
15391570
if (test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags))
15401571
goto nocow;

0 commit comments

Comments
 (0)