fs/btrfs/free-space-cache.c
Source file repositories/reference/linux-study-clean/fs/btrfs/free-space-cache.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/free-space-cache.c- Extension
.c- Size
- 118984 bytes
- Lines
- 4388
- 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/pagemap.hlinux/sched.hlinux/sched/signal.hlinux/slab.hlinux/math64.hlinux/ratelimit.hlinux/error-injection.hlinux/sched/mm.hlinux/string_choices.hextent-tree.hfs.hmessages.hmisc.hfree-space-cache.htransaction.hdisk-io.hextent_io.hspace-info.hblock-group.hdiscard.hsubpage.hinode-item.haccessors.hfile-item.hfile.hsuper.hrelocation.h
Detected Declarations
struct btrfs_trim_rangefunction btrfs_crc32c_finalfunction __btrfs_remove_free_space_cachefunction __create_free_space_inodefunction create_free_space_inodefunction btrfs_remove_free_space_inodefunction btrfs_truncate_free_space_cachefunction readahead_cachefunction io_ctl_initfunction io_ctl_freefunction io_ctl_unmap_pagefunction io_ctl_map_pagefunction io_ctl_drop_pagesfunction io_ctl_prepare_pagesfunction io_ctl_set_generationfunction io_ctl_check_generationfunction io_ctl_set_crcfunction io_ctl_check_crcfunction io_ctl_add_entryfunction io_ctl_add_bitmapfunction io_ctl_zero_remaining_pagesfunction io_ctl_read_entryfunction io_ctl_read_bitmapfunction recalculate_thresholdsfunction __load_free_space_cachefunction copy_free_space_cachefunction load_free_space_cachefunction write_cache_extent_entriesfunction update_cache_itemfunction write_pinned_extent_entriesfunction write_bitmap_entriesfunction flush_dirty_cachefunction cleanup_bitmap_listfunction cleanup_write_cache_enospcfunction __btrfs_wait_cache_iofunction btrfs_wait_cache_iofunction __btrfs_write_out_cachefunction btrfs_write_out_cachefunction offset_to_bitfunction bytes_to_bitsfunction offset_to_bitmapfunction tree_insert_offsetfunction find_free_spacefunction entry_lessfunction tree_search_offsetfunction unlink_free_spacefunction link_free_spacefunction relink_bitmap_entry
Annotated Snippet
struct btrfs_trim_range {
u64 start;
u64 bytes;
struct list_head list;
};
static int link_free_space(struct btrfs_free_space_ctl *ctl,
struct btrfs_free_space *info);
static void unlink_free_space(struct btrfs_free_space_ctl *ctl,
struct btrfs_free_space *info, bool update_stat);
static int search_bitmap(struct btrfs_free_space_ctl *ctl,
struct btrfs_free_space *bitmap_info, u64 *offset,
u64 *bytes, bool for_alloc);
static void free_bitmap(struct btrfs_free_space_ctl *ctl,
struct btrfs_free_space *bitmap_info);
static void bitmap_clear_bits(struct btrfs_free_space_ctl *ctl,
struct btrfs_free_space *info, u64 offset,
u64 bytes, bool update_stats);
static void btrfs_crc32c_final(u32 crc, u8 *result)
{
put_unaligned_le32(~crc, result);
}
static void __btrfs_remove_free_space_cache(struct btrfs_free_space_ctl *ctl)
{
struct btrfs_free_space *info;
struct rb_node *node;
while ((node = rb_last(&ctl->free_space_offset)) != NULL) {
info = rb_entry(node, struct btrfs_free_space, offset_index);
if (!info->bitmap) {
unlink_free_space(ctl, info, true);
kmem_cache_free(btrfs_free_space_cachep, info);
} else {
free_bitmap(ctl, info);
}
cond_resched_lock(&ctl->tree_lock);
}
}
static struct inode *__lookup_free_space_inode(struct btrfs_root *root,
struct btrfs_path *path,
u64 offset)
{
struct btrfs_key key;
struct btrfs_key location;
struct btrfs_disk_key disk_key;
struct btrfs_free_space_header *header;
struct extent_buffer *leaf;
struct btrfs_inode *inode;
unsigned nofs_flag;
int ret;
key.objectid = BTRFS_FREE_SPACE_OBJECTID;
key.type = 0;
key.offset = offset;
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
if (ret < 0)
return ERR_PTR(ret);
if (ret > 0) {
btrfs_release_path(path);
return ERR_PTR(-ENOENT);
}
leaf = path->nodes[0];
header = btrfs_item_ptr(leaf, path->slots[0],
struct btrfs_free_space_header);
btrfs_free_space_key(leaf, header, &disk_key);
btrfs_disk_key_to_cpu(&location, &disk_key);
btrfs_release_path(path);
/*
* We are often under a trans handle at this point, so we need to make
* sure NOFS is set to keep us from deadlocking.
*/
nofs_flag = memalloc_nofs_save();
inode = btrfs_iget_path(location.objectid, root, path);
btrfs_release_path(path);
memalloc_nofs_restore(nofs_flag);
if (IS_ERR(inode))
return ERR_CAST(inode);
mapping_set_gfp_mask(inode->vfs_inode.i_mapping,
mapping_gfp_constraint(inode->vfs_inode.i_mapping,
~(__GFP_FS | __GFP_HIGHMEM)));
return &inode->vfs_inode;
Annotation
- Immediate include surface: `linux/pagemap.h`, `linux/sched.h`, `linux/sched/signal.h`, `linux/slab.h`, `linux/math64.h`, `linux/ratelimit.h`, `linux/error-injection.h`, `linux/sched/mm.h`.
- Detected declarations: `struct btrfs_trim_range`, `function btrfs_crc32c_final`, `function __btrfs_remove_free_space_cache`, `function __create_free_space_inode`, `function create_free_space_inode`, `function btrfs_remove_free_space_inode`, `function btrfs_truncate_free_space_cache`, `function readahead_cache`, `function io_ctl_init`, `function io_ctl_free`.
- 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.