fs/ext4/mballoc.c
Source file repositories/reference/linux-study-clean/fs/ext4/mballoc.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ext4/mballoc.c- Extension
.c- Size
- 209641 bytes
- Lines
- 7284
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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
ext4_jbd2.hmballoc.hlinux/log2.hlinux/module.hlinux/slab.hlinux/nospec.hlinux/backing-dev.hlinux/freezer.htrace/events/ext4.hkunit/static_stub.h
Detected Declarations
function ext4_get_discard_pa_seq_sumfunction mb_test_bitfunction mb_set_bitfunction mb_clear_bitfunction mb_test_and_clear_bitfunction mb_find_next_zero_bitfunction mb_find_next_bitfunction mb_free_blocks_doublefunction mb_mark_used_doublefunction mb_cmp_bitmapsfunction mb_group_bb_bitmap_allocfunction mb_group_bb_bitmap_freefunction mb_free_blocks_doublefunction mb_mark_used_doublefunction mb_cmp_bitmapsfunction mb_group_bb_bitmap_allocfunction mb_group_bb_bitmap_freefunction freefunction chunkfunction mb_avg_fragment_size_orderfunction mb_update_avg_fragment_sizefunction ext4_get_allocation_groups_countfunction ext4_mb_scan_groups_xa_rangefunction xa_for_each_rangefunction ext4_mb_scan_groups_largest_free_order_rangefunction ext4_mb_scan_groups_p2_alignedfunction ext4_mb_scan_groups_avg_frag_order_rangefunction ext4_mb_scan_groups_goal_fastfunction ext4_mb_scan_groups_best_availfunction should_optimize_scanfunction next_linear_groupfunction ext4_mb_scan_groups_linearfunction ext4_mb_scan_groupsfunction mb_set_largest_free_orderfunction ext4_mb_generate_buddyfunction mb_regenerate_buddyfunction ext4_mb_init_cachefunction ext4_mb_get_buddy_folio_lockfunction ext4_mb_put_buddy_folio_lockfunction ext4_mb_init_groupfunction ext4_mb_load_buddy_gfpfunction ext4_mb_load_buddyfunction ext4_mb_unload_buddyfunction mb_find_order_for_blockfunction mb_clear_bitsfunction mb_test_and_clear_bitsfunction mb_set_bitsfunction mb_buddy_adjust_border
Annotated Snippet
if (!mb_test_bit(first + i, e4b->bd_info->bb_bitmap)) {
ext4_fsblk_t blocknr;
blocknr = ext4_group_first_block_no(sb, e4b->bd_group);
blocknr += EXT4_C2B(EXT4_SB(sb), first + i);
ext4_mark_group_bitmap_corrupted(sb, e4b->bd_group,
EXT4_GROUP_INFO_BBITMAP_CORRUPT);
ext4_grp_locked_error(sb, e4b->bd_group,
inode ? inode->i_ino : 0,
blocknr,
"freeing block already freed "
"(bit %u)",
first + i);
}
mb_clear_bit(first + i, e4b->bd_info->bb_bitmap);
}
}
static void mb_mark_used_double(struct ext4_buddy *e4b, int first, int count)
{
int i;
if (unlikely(e4b->bd_info->bb_bitmap == NULL))
return;
assert_spin_locked(ext4_group_lock_ptr(e4b->bd_sb, e4b->bd_group));
for (i = 0; i < count; i++) {
BUG_ON(mb_test_bit(first + i, e4b->bd_info->bb_bitmap));
mb_set_bit(first + i, e4b->bd_info->bb_bitmap);
}
}
static void mb_cmp_bitmaps(struct ext4_buddy *e4b, void *bitmap)
{
if (unlikely(e4b->bd_info->bb_bitmap == NULL))
return;
if (memcmp(e4b->bd_info->bb_bitmap, bitmap, e4b->bd_sb->s_blocksize)) {
unsigned char *b1, *b2;
int i;
b1 = (unsigned char *) e4b->bd_info->bb_bitmap;
b2 = (unsigned char *) bitmap;
for (i = 0; i < e4b->bd_sb->s_blocksize; i++) {
if (b1[i] != b2[i]) {
ext4_msg(e4b->bd_sb, KERN_ERR,
"corruption in group %u "
"at byte %u(%u): %x in copy != %x "
"on disk/prealloc",
e4b->bd_group, i, i * 8, b1[i], b2[i]);
BUG();
}
}
}
}
static void mb_group_bb_bitmap_alloc(struct super_block *sb,
struct ext4_group_info *grp, ext4_group_t group)
{
struct buffer_head *bh;
grp->bb_bitmap = kmalloc(sb->s_blocksize, GFP_NOFS);
if (!grp->bb_bitmap)
return;
bh = ext4_read_block_bitmap(sb, group);
if (IS_ERR_OR_NULL(bh)) {
kfree(grp->bb_bitmap);
grp->bb_bitmap = NULL;
return;
}
memcpy(grp->bb_bitmap, bh->b_data, sb->s_blocksize);
put_bh(bh);
}
static void mb_group_bb_bitmap_free(struct ext4_group_info *grp)
{
kfree(grp->bb_bitmap);
}
#else
static inline void mb_free_blocks_double(struct inode *inode,
struct ext4_buddy *e4b, int first, int count)
{
return;
}
static inline void mb_mark_used_double(struct ext4_buddy *e4b,
int first, int count)
{
return;
}
static inline void mb_cmp_bitmaps(struct ext4_buddy *e4b, void *bitmap)
Annotation
- Immediate include surface: `ext4_jbd2.h`, `mballoc.h`, `linux/log2.h`, `linux/module.h`, `linux/slab.h`, `linux/nospec.h`, `linux/backing-dev.h`, `linux/freezer.h`.
- Detected declarations: `function ext4_get_discard_pa_seq_sum`, `function mb_test_bit`, `function mb_set_bit`, `function mb_clear_bit`, `function mb_test_and_clear_bit`, `function mb_find_next_zero_bit`, `function mb_find_next_bit`, `function mb_free_blocks_double`, `function mb_mark_used_double`, `function mb_cmp_bitmaps`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: integration 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.