Skip to content

Commit 319d91e

Browse files
adam900710kdave
authored andcommitted
btrfs: add extra comments on extent_map members
The extent_map structure is very critical to btrfs, as it is involved for both read and write paths. Unfortunately the structure is not properly explained, making it pretty hard to understand nor to do further improvement. This patch adds extra comments explaining the major members based on my code reading. Hopefully we can find more members to cleanup in the future. Reviewed-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 30704a0 commit 319d91e

1 file changed

Lines changed: 54 additions & 1 deletion

File tree

fs/btrfs/extent_map.h

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,72 @@ enum {
3535
};
3636

3737
/*
38+
* This structure represents file extents and holes.
39+
*
40+
* Unlike on-disk file extent items, extent maps can be merged to save memory.
41+
* This means members only match file extent items before any merging.
42+
*
3843
* Keep this structure as compact as possible, as we can have really large
3944
* amounts of allocated extent maps at any time.
4045
*/
4146
struct extent_map {
4247
struct rb_node rb_node;
4348

44-
/* all of these are in bytes */
49+
/* All of these are in bytes. */
50+
51+
/* File offset matching the offset of a BTRFS_EXTENT_ITEM_KEY key. */
4552
u64 start;
53+
54+
/*
55+
* Length of the file extent.
56+
*
57+
* For non-inlined file extents it's btrfs_file_extent_item::num_bytes.
58+
* For inline extents it's sectorsize, since inline data starts at
59+
* offsetof(struct btrfs_file_extent_item, disk_bytenr) thus
60+
* btrfs_file_extent_item::num_bytes is not valid.
61+
*/
4662
u64 len;
63+
64+
/*
65+
* The file offset of the original file extent before splitting.
66+
*
67+
* This is an in-memory only member, matching
68+
* extent_map::start - btrfs_file_extent_item::offset for
69+
* regular/preallocated extents. EXTENT_MAP_HOLE otherwise.
70+
*/
4771
u64 orig_start;
72+
73+
/*
74+
* The full on-disk extent length, matching
75+
* btrfs_file_extent_item::disk_num_bytes.
76+
*/
4877
u64 orig_block_len;
78+
79+
/*
80+
* The decompressed size of the whole on-disk extent, matching
81+
* btrfs_file_extent_item::ram_bytes.
82+
*/
4983
u64 ram_bytes;
84+
85+
/*
86+
* The on-disk logical bytenr for the file extent.
87+
*
88+
* For compressed extents it matches btrfs_file_extent_item::disk_bytenr.
89+
* For uncompressed extents it matches
90+
* btrfs_file_extent_item::disk_bytenr + btrfs_file_extent_item::offset
91+
*
92+
* For holes it is EXTENT_MAP_HOLE and for inline extents it is
93+
* EXTENT_MAP_INLINE.
94+
*/
5095
u64 block_start;
96+
97+
/*
98+
* The on-disk length for the file extent.
99+
*
100+
* For compressed extents it matches btrfs_file_extent_item::disk_num_bytes.
101+
* For uncompressed extents it matches extent_map::len.
102+
* For holes and inline extents it's -1 and shouldn't be used.
103+
*/
51104
u64 block_len;
52105

53106
/*

0 commit comments

Comments
 (0)