fs/btrfs/space-info.c
Source file repositories/reference/linux-study-clean/fs/btrfs/space-info.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/space-info.c- Extension
.c- Size
- 73832 bytes
- Lines
- 2268
- 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/spinlock.hlinux/minmax.hmisc.hctree.hspace-info.hsysfs.hvolumes.hfree-space-cache.hordered-data.htransaction.hblock-group.hfs.haccessors.hextent-tree.hzoned.hdelayed-inode.h
Detected Declarations
struct reserve_ticketfunction btrfs_clear_space_info_fullfunction valuefunction btrfs_update_space_info_chunk_sizefunction init_space_infofunction create_space_info_sub_groupfunction create_space_infofunction btrfs_init_space_infofunction btrfs_add_bg_to_space_infofunction list_for_each_entryfunction calc_effective_data_chunk_sizefunction calc_available_free_spacefunction check_can_overcommitfunction can_overcommitfunction btrfs_can_overcommitfunction remove_ticketfunction btrfs_try_granting_ticketsfunction dump_global_block_rsvfunction __btrfs_dump_space_infofunction btrfs_dump_space_infofunction calc_reclaim_items_nrfunction shrink_delallocfunction flush_spacefunction btrfs_calc_reclaim_metadata_sizefunction need_preemptive_reclaimfunction steal_from_global_rsvfunction maybe_fail_all_ticketsfunction do_async_reclaim_metadata_spacefunction btrfs_async_reclaim_metadata_spacefunction btrfs_preempt_reclaim_metadata_spacefunction btrfs_block_rsv_reservedfunction btrfs_block_rsv_reservedfunction do_async_reclaim_data_spacefunction btrfs_async_reclaim_data_spacefunction btrfs_init_async_reclaim_workfunction is_ticket_servedfunction priority_reclaim_metadata_spacefunction priority_reclaim_data_spacefunction wait_reserve_ticketfunction handle_reserve_ticketfunction is_normal_flushingfunction maybe_clamp_preemptfunction can_stealfunction can_ticketfunction reserve_bytesfunction handlefunction spacefunction btrfs_reserve_metadata_bytes
Annotated Snippet
struct reserve_ticket {
u64 bytes;
int error;
bool steal;
struct list_head list;
wait_queue_head_t wait;
spinlock_t lock;
};
/*
* after adding space to the filesystem, we need to clear the full flags
* on all the space infos.
*/
void btrfs_clear_space_info_full(struct btrfs_fs_info *info)
{
struct list_head *head = &info->space_info;
struct btrfs_space_info *found;
list_for_each_entry(found, head, list)
found->full = false;
}
/*
* Block groups with more than this value (percents) of unusable space will be
* scheduled for background reclaim.
*/
#define BTRFS_DEFAULT_ZONED_RECLAIM_THRESH (75)
#define BTRFS_UNALLOC_BLOCK_GROUP_TARGET (10ULL)
#define BTRFS_ZONED_SYNC_RECLAIM_BATCH (5)
/*
* Calculate chunk size depending on volume type (regular or zoned).
*/
static u64 calc_chunk_size(const struct btrfs_fs_info *fs_info, u64 flags)
{
if (btrfs_is_zoned(fs_info))
return fs_info->zone_size;
ASSERT(flags & BTRFS_BLOCK_GROUP_TYPE_MASK, "flags=%llu", flags);
if (flags & BTRFS_BLOCK_GROUP_DATA)
return BTRFS_MAX_DATA_CHUNK_SIZE;
else if (flags & (BTRFS_BLOCK_GROUP_SYSTEM | BTRFS_BLOCK_GROUP_METADATA_REMAP))
return SZ_32M;
/* Handle BTRFS_BLOCK_GROUP_METADATA */
if (fs_info->fs_devices->total_rw_bytes > 50ULL * SZ_1G)
return SZ_1G;
return SZ_256M;
}
/*
* Update default chunk size.
*/
void btrfs_update_space_info_chunk_size(struct btrfs_space_info *space_info,
u64 chunk_size)
{
WRITE_ONCE(space_info->chunk_size, chunk_size);
}
static void init_space_info(struct btrfs_fs_info *info,
struct btrfs_space_info *space_info, u64 flags)
{
space_info->fs_info = info;
for (int i = 0; i < BTRFS_NR_RAID_TYPES; i++)
INIT_LIST_HEAD(&space_info->block_groups[i]);
init_rwsem(&space_info->groups_sem);
spin_lock_init(&space_info->lock);
space_info->flags = flags & BTRFS_BLOCK_GROUP_TYPE_MASK;
space_info->force_alloc = CHUNK_ALLOC_NO_FORCE;
INIT_LIST_HEAD(&space_info->ro_bgs);
INIT_LIST_HEAD(&space_info->tickets);
INIT_LIST_HEAD(&space_info->priority_tickets);
space_info->clamp = 1;
btrfs_update_space_info_chunk_size(space_info, calc_chunk_size(info, flags));
space_info->subgroup_id = BTRFS_SUB_GROUP_PRIMARY;
if (btrfs_is_zoned(info))
space_info->bg_reclaim_threshold = BTRFS_DEFAULT_ZONED_RECLAIM_THRESH;
}
static int create_space_info_sub_group(struct btrfs_space_info *parent, u64 flags,
enum btrfs_space_info_sub_group id, int index)
{
struct btrfs_fs_info *fs_info = parent->fs_info;
struct btrfs_space_info *sub_group;
int ret;
Annotation
- Immediate include surface: `linux/spinlock.h`, `linux/minmax.h`, `misc.h`, `ctree.h`, `space-info.h`, `sysfs.h`, `volumes.h`, `free-space-cache.h`.
- Detected declarations: `struct reserve_ticket`, `function btrfs_clear_space_info_full`, `function value`, `function btrfs_update_space_info_chunk_size`, `function init_space_info`, `function create_space_info_sub_group`, `function create_space_info`, `function btrfs_init_space_info`, `function btrfs_add_bg_to_space_info`, `function list_for_each_entry`.
- 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.