fs/btrfs/relocation.c
Source file repositories/reference/linux-study-clean/fs/btrfs/relocation.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/relocation.c- Extension
.c- Size
- 159270 bytes
- Lines
- 6191
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/sched.hlinux/pagemap.hlinux/writeback.hlinux/blkdev.hlinux/rbtree.hlinux/slab.hlinux/error-injection.hctree.hdisk-io.htransaction.hvolumes.hlocking.hbtrfs_inode.hasync-thread.hfree-space-cache.hqgroup.hprint-tree.hdelalloc-space.hblock-group.hbackref.hmisc.hsubpage.hzoned.hinode-item.hspace-info.hfs.haccessors.hextent-tree.hroot-tree.hfile-item.hrelocation.hsuper.h
Detected Declarations
struct mapping_nodestruct mapping_treestruct tree_blockstruct file_extent_clusterstruct reloc_controlstruct space_runstruct reloc_io_privateenum reloc_stagefunction free_reloc_rootsfunction put_reloc_controlfunction __del_reloc_rootfunction mark_block_processedfunction reloc_root_is_deadfunction have_reloc_rootfunction btrfs_should_ignore_reloc_rootfunction orphanfunction __add_reloc_rootfunction __update_reloc_rootfunction btrfs_init_reloc_rootfunction btrfs_update_reloc_rootfunction get_new_locationfunction writebackfunction replace_file_extentsfunction memcmp_node_keysfunction replace_pathfunction walk_up_reloc_treefunction walk_down_reloc_treefunction invalidate_extent_cachefunction find_next_keyfunction insert_dirty_subvolfunction clean_dirty_subvolsfunction list_for_each_entry_safefunction merge_reloc_rootfunction prepare_to_mergefunction merge_reloc_rootsfunction prepare_to_mergefunction record_reloc_root_in_transfunction calcu_metadata_sizefunction refill_metadata_spacefunction reserve_metadata_spacefunction do_relocationfunction link_to_upperfunction finish_pending_nodesfunction update_processed_blocksfunction tree_block_processedfunction get_tree_block_keyfunction relocate_tree_blockfunction relocate_cowonly_block
Annotated Snippet
struct mapping_node {
union {
/* Use rb_simple_node for search/insert */
struct {
struct rb_node rb_node;
u64 bytenr;
};
struct rb_simple_node simple_node;
};
void *data;
};
struct mapping_tree {
struct rb_root rb_root;
spinlock_t lock;
};
/*
* present a tree block to process
*/
struct tree_block {
union {
/* Use rb_simple_node for search/insert */
struct {
struct rb_node rb_node;
u64 bytenr;
};
struct rb_simple_node simple_node;
};
u64 owner;
struct btrfs_key key;
u8 level;
bool key_ready;
};
#define MAX_EXTENTS 128
struct file_extent_cluster {
u64 start;
u64 end;
u64 boundary[MAX_EXTENTS];
unsigned int nr;
u64 owning_root;
};
/* Stages of data relocation. */
enum reloc_stage {
MOVE_DATA_EXTENTS,
UPDATE_DATA_PTRS
};
struct reloc_control {
/* block group to relocate */
struct btrfs_block_group *block_group;
/* extent tree */
struct btrfs_root *extent_root;
/* inode for moving data */
struct inode *data_inode;
struct btrfs_block_rsv *block_rsv;
struct btrfs_backref_cache backref_cache;
struct file_extent_cluster cluster;
/* tree blocks have been processed */
struct extent_io_tree processed_blocks;
/* map start of tree root to corresponding reloc tree */
struct mapping_tree reloc_root_tree;
/* list of reloc trees */
struct list_head reloc_roots;
/* list of subvolume trees that get relocated */
struct list_head dirty_subvol_roots;
/* size of metadata reservation for merging reloc trees */
u64 merging_rsv_size;
/* size of relocated tree nodes */
u64 nodes_relocated;
/* reserved size for block group relocation*/
u64 reserved_bytes;
u64 search_start;
u64 extents_found;
enum reloc_stage stage;
bool create_reloc_tree;
bool merge_reloc_tree;
bool found_file_extent;
refcount_t refs;
Annotation
- Immediate include surface: `linux/sched.h`, `linux/pagemap.h`, `linux/writeback.h`, `linux/blkdev.h`, `linux/rbtree.h`, `linux/slab.h`, `linux/error-injection.h`, `ctree.h`.
- Detected declarations: `struct mapping_node`, `struct mapping_tree`, `struct tree_block`, `struct file_extent_cluster`, `struct reloc_control`, `struct space_run`, `struct reloc_io_private`, `enum reloc_stage`, `function free_reloc_roots`, `function put_reloc_control`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.