fs/btrfs/delayed-ref.c
Source file repositories/reference/linux-study-clean/fs/btrfs/delayed-ref.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/delayed-ref.c- Extension
.c- Size
- 41158 bytes
- Lines
- 1407
- 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/slab.hlinux/sort.hmessages.hctree.hdelayed-ref.hextent-tree.htransaction.hqgroup.hspace-info.htree-mod-log.hfs.h
Detected Declarations
function btrfs_check_space_for_delayed_refsfunction btrfs_delayed_refs_rsv_releasefunction btrfs_update_delayed_refs_rsvfunction btrfs_inc_delayed_refs_rsv_bg_insertsfunction btrfs_dec_delayed_refs_rsv_bg_insertsfunction btrfs_inc_delayed_refs_rsv_bg_updatesfunction btrfs_dec_delayed_refs_rsv_bg_updatesfunction btrfs_zoned_cap_metadata_reservationfunction btrfs_delayed_refs_rsv_refillfunction comp_data_refsfunction comp_refsfunction cmp_refs_nodefunction tree_insertfunction btrfs_delayed_ref_lockfunction drop_delayed_reffunction merge_reffunction btrfs_merge_delayed_refsfunction btrfs_check_delayed_seqfunction btrfs_unselect_ref_headfunction btrfs_delete_ref_headfunction onefunction update_existing_head_reffunction add_delayed_ref_headfunction init_delayed_ref_headfunction kfreefunction reffunction init_delayed_ref_commonfunction btrfs_init_tree_reffunction btrfs_init_data_reffunction add_delayed_reffunction btrfs_add_delayed_tree_reffunction btrfs_add_delayed_data_reffunction btrfs_add_delayed_extent_opfunction btrfs_put_delayed_reffunction btrfs_find_delayed_ref_headfunction find_compfunction btrfs_find_delayed_tree_reffunction btrfs_destroy_delayed_refsfunction btrfs_delayed_ref_exitfunction btrfs_delayed_ref_init
Annotated Snippet
if (num_bytes >= needed) {
block_rsv->reserved += needed;
block_rsv->full = true;
to_free = num_bytes - needed;
refilled_bytes = needed;
} else {
block_rsv->reserved += num_bytes;
to_free = 0;
refilled_bytes = num_bytes;
}
} else {
to_free = num_bytes;
refilled_bytes = 0;
}
spin_unlock(&block_rsv->lock);
if (to_free > 0)
btrfs_space_info_free_bytes_may_use(space_info, to_free);
if (refilled_bytes > 0)
trace_btrfs_space_reservation(fs_info, "delayed_refs_rsv", 0,
refilled_bytes, 1);
return 0;
}
/*
* compare two delayed data backrefs with same bytenr and type
*/
static int comp_data_refs(const struct btrfs_delayed_ref_node *ref1,
const struct btrfs_delayed_ref_node *ref2)
{
if (ref1->data_ref.objectid < ref2->data_ref.objectid)
return -1;
if (ref1->data_ref.objectid > ref2->data_ref.objectid)
return 1;
if (ref1->data_ref.offset < ref2->data_ref.offset)
return -1;
if (ref1->data_ref.offset > ref2->data_ref.offset)
return 1;
return 0;
}
static int comp_refs(const struct btrfs_delayed_ref_node *ref1,
const struct btrfs_delayed_ref_node *ref2,
bool check_seq)
{
int ret = 0;
if (ref1->type < ref2->type)
return -1;
if (ref1->type > ref2->type)
return 1;
if (ref1->type == BTRFS_SHARED_BLOCK_REF_KEY ||
ref1->type == BTRFS_SHARED_DATA_REF_KEY) {
if (ref1->parent < ref2->parent)
return -1;
if (ref1->parent > ref2->parent)
return 1;
} else {
if (ref1->ref_root < ref2->ref_root)
return -1;
if (ref1->ref_root > ref2->ref_root)
return 1;
if (ref1->type == BTRFS_EXTENT_DATA_REF_KEY)
ret = comp_data_refs(ref1, ref2);
}
if (ret)
return ret;
if (check_seq) {
if (ref1->seq < ref2->seq)
return -1;
if (ref1->seq > ref2->seq)
return 1;
}
return 0;
}
static int cmp_refs_node(const struct rb_node *new, const struct rb_node *exist)
{
const struct btrfs_delayed_ref_node *new_node =
rb_entry(new, struct btrfs_delayed_ref_node, ref_node);
const struct btrfs_delayed_ref_node *exist_node =
rb_entry(exist, struct btrfs_delayed_ref_node, ref_node);
return comp_refs(new_node, exist_node, true);
}
static struct btrfs_delayed_ref_node* tree_insert(struct rb_root_cached *root,
struct btrfs_delayed_ref_node *ins)
{
Annotation
- Immediate include surface: `linux/sched.h`, `linux/slab.h`, `linux/sort.h`, `messages.h`, `ctree.h`, `delayed-ref.h`, `extent-tree.h`, `transaction.h`.
- Detected declarations: `function btrfs_check_space_for_delayed_refs`, `function btrfs_delayed_refs_rsv_release`, `function btrfs_update_delayed_refs_rsv`, `function btrfs_inc_delayed_refs_rsv_bg_inserts`, `function btrfs_dec_delayed_refs_rsv_bg_inserts`, `function btrfs_inc_delayed_refs_rsv_bg_updates`, `function btrfs_dec_delayed_refs_rsv_bg_updates`, `function btrfs_zoned_cap_metadata_reservation`, `function btrfs_delayed_refs_rsv_refill`, `function comp_data_refs`.
- 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.