Skip to content

Commit

Permalink
btrfs: relocation: Add introduction of how relocation works
Browse files Browse the repository at this point in the history
Relocation is one of the most complex part of btrfs, while it's also the
foundation stone for online resizing, profile converting.

For such a complex facility, we should at least have some introduction
to it.

This patch will add an basic introduction at pretty a high level,
explaining:

- What relocation does
- How relocation is done
  Only mentioning how data reloc tree and reloc tree are involved in the
  operation.
  No details like the backref cache, or the data reloc tree contents.
- Which function to refer.

More detailed comments will be added for reloc tree creation, data reloc
tree creation and backref cache.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
Qu Wenruo authored and David Sterba committed Mar 23, 2020
1 parent 42836cf commit 0c89138
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions fs/btrfs/relocation.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,53 @@
#include "delalloc-space.h"
#include "block-group.h"

/*
* Relocation overview
*
* [What does relocation do]
*
* The objective of relocation is to relocate all extents of the target block
* group to other block groups.
* This is utilized by resize (shrink only), profile converting, compacting
* space, or balance routine to spread chunks over devices.
*
* Before | After
* ------------------------------------------------------------------
* BG A: 10 data extents | BG A: deleted
* BG B: 2 data extents | BG B: 10 data extents (2 old + 8 relocated)
* BG C: 1 extents | BG C: 3 data extents (1 old + 2 relocated)
*
* [How does relocation work]
*
* 1. Mark the target block group read-only
* New extents won't be allocated from the target block group.
*
* 2.1 Record each extent in the target block group
* To build a proper map of extents to be relocated.
*
* 2.2 Build data reloc tree and reloc trees
* Data reloc tree will contain an inode, recording all newly relocated
* data extents.
* There will be only one data reloc tree for one data block group.
*
* Reloc tree will be a special snapshot of its source tree, containing
* relocated tree blocks.
* Each tree referring to a tree block in target block group will get its
* reloc tree built.
*
* 2.3 Swap source tree with its corresponding reloc tree
* Each involved tree only refers to new extents after swap.
*
* 3. Cleanup reloc trees and data reloc tree.
* As old extents in the target block group are still referenced by reloc
* trees, we need to clean them up before really freeing the target block
* group.
*
* The main complexity is in steps 2.2 and 2.3.
*
* The entry point of relocation is relocate_block_group() function.
*/

/*
* backref_node, mapping_node and tree_block start with this
*/
Expand Down

0 comments on commit 0c89138

Please sign in to comment.