aboutsummaryrefslogtreecommitdiff
path: root/fs/btrfs/file-item.c
diff options
context:
space:
mode:
authorGravatar Christoph Hellwig <hch@lst.de> 2023-05-24 17:03:08 +0200
committerGravatar David Sterba <dsterba@suse.com> 2023-06-19 13:59:32 +0200
commitcbfce4c7fbde23cc8bcba44822a58c728caf6ec9 (patch)
tree3cc7a0c85483da01f45d0eaef58e8c325e56b5d0 /fs/btrfs/file-item.c
parentbtrfs: rename the bytenr field in struct btrfs_ordered_sum to logical (diff)
downloadlinux-cbfce4c7fbde23cc8bcba44822a58c728caf6ec9.tar.gz
linux-cbfce4c7fbde23cc8bcba44822a58c728caf6ec9.tar.bz2
linux-cbfce4c7fbde23cc8bcba44822a58c728caf6ec9.zip
btrfs: optimize the logical to physical mapping for zoned writes
The current code to store the final logical to physical mapping for a zone append write in the extent tree is rather inefficient. It first has to split the ordered extent so that there is one ordered extent per bio, so that it can look up the ordered extent on I/O completion in btrfs_record_physical_zoned and store the physical LBA returned by the block driver in the ordered extent. btrfs_rewrite_logical_zoned then has to do a lookup in the chunk tree to see what physical address the logical address for this bio / ordered extent is mapped to, and then rewrite it in the extent tree. To optimize this process, we can store the physical address assigned in the chunk tree to the original logical address and a pointer to btrfs_ordered_sum structure the in the btrfs_bio structure, and then use this information to rewrite the logical address in the btrfs_ordered_sum structure directly at I/O completion time in btrfs_record_physical_zoned. btrfs_rewrite_logical_zoned then simply updates the logical address in the extent tree and the ordered_extent itself. The code in btrfs_rewrite_logical_zoned now runs for all data I/O completions in zoned file systems, which is fine as there is no remapping to do for non-append writes to conventional zones or for relocation, and the overhead for quickly breaking out of the loop is very low. Because zoned file systems now need the ordered_sums structure to record the actual write location returned by zone append, allocate dummy structures without the csum array for them when the I/O doesn't use checksums, and free them when completing the ordered_extent. Note that the btrfs_bio doesn't grow as the new field are places into a union that is so far not used for data writes and has plenty of space left in it. Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/file-item.c')
-rw-r--r--fs/btrfs/file-item.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index 415e50904db3..0cb4a9921d21 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -818,12 +818,42 @@ blk_status_t btrfs_csum_one_bio(struct btrfs_bio *bbio)
}
this_sum_bytes = 0;
+
+ /*
+ * The ->sums assignment is for zoned writes, where a bio never spans
+ * ordered extents and is only done unconditionally because that's cheaper
+ * than a branch.
+ */
+ bbio->sums = sums;
btrfs_add_ordered_sum(ordered, sums);
btrfs_put_ordered_extent(ordered);
return 0;
}
/*
+ * Nodatasum I/O on zoned file systems still requires an btrfs_ordered_sum to
+ * record the updated logical address on Zone Append completion.
+ * Allocate just the structure with an empty sums array here for that case.
+ */
+blk_status_t btrfs_alloc_dummy_sum(struct btrfs_bio *bbio)
+{
+ struct btrfs_ordered_extent *ordered =
+ btrfs_lookup_ordered_extent(bbio->inode, bbio->file_offset);
+
+ if (WARN_ON_ONCE(!ordered))
+ return BLK_STS_IOERR;
+
+ bbio->sums = kmalloc(sizeof(*bbio->sums), GFP_NOFS);
+ if (!bbio->sums)
+ return BLK_STS_RESOURCE;
+ bbio->sums->len = bbio->bio.bi_iter.bi_size;
+ bbio->sums->logical = bbio->bio.bi_iter.bi_sector << SECTOR_SHIFT;
+ btrfs_add_ordered_sum(ordered, bbio->sums);
+ btrfs_put_ordered_extent(ordered);
+ return 0;
+}
+
+/*
* Remove one checksum overlapping a range.
*
* This expects the key to describe the csum pointed to by the path, and it