fs/ext4/inode.c
Source file repositories/reference/linux-study-clean/fs/ext4/inode.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ext4/inode.c- Extension
.c- Size
- 202935 bytes
- Lines
- 6879
- 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/fs.hlinux/mount.hlinux/time.hlinux/highuid.hlinux/pagemap.hlinux/dax.hlinux/quotaops.hlinux/string.hlinux/buffer_head.hlinux/writeback.hlinux/folio_batch.hlinux/mpage.hlinux/rmap.hlinux/namei.hlinux/uio.hlinux/bio.hlinux/workqueue.hlinux/kernel.hlinux/printk.hlinux/slab.hlinux/bitops.hlinux/iomap.hlinux/iversion.hext4_jbd2.hxattr.hacl.htruncate.hkunit/static_stub.htrace/events/ext4.h
Detected Declarations
struct mpage_da_datafunction ext4_inode_csumfunction ext4_inode_csum_verifyfunction ext4_inode_csum_setfunction ext4_begin_ordered_truncatefunction ext4_inode_is_fast_symlinkfunction iputfunction ext4_discard_preallocationsfunction __check_block_validityfunction ext4_issue_zerooutfunction ext4_check_map_extents_envfunction ext4_check_map_extents_envfunction ext4_map_query_blocks_next_in_leaffunction ext4_map_query_blocksfunction ext4_map_create_blocksfunction ext4_map_blocksfunction ext4_update_bh_statefunction ext4_journal_ensure_extent_creditsfunction _ext4_get_blockfunction ext4_get_blockfunction ext4_get_block_unwrittenfunction ext4_bread_batchfunction ext4_walk_page_buffersfunction pagefunction do_journal_get_write_accessfunction ext4_block_write_beginfunction ext4_get_blockfunction write_end_fnfunction ext4_write_endfunction folio_zero_new_buffersfunction ext4_journalled_write_endfunction ext4_da_reserve_spacefunction ext4_da_release_spacefunction mpage_release_unused_pagesfunction ext4_print_free_blocksfunction ext4_clu_alloc_statefunction ext4_insert_delayed_blocksfunction ext4_da_map_blocksfunction pathfunction ext4_da_write_beginfunction mpage_folio_donefunction mpage_submit_foliofunction mpage_add_bh_to_extentfunction mpage_process_page_bufsfunction mpage_process_foliofunction extentfunction mpage_map_one_extentfunction mpage_submit_partial_folio
Annotated Snippet
struct mpage_da_data {
/* These are input fields for ext4_do_writepages() */
struct inode *inode;
struct writeback_control *wbc;
unsigned int can_map:1; /* Can writepages call map blocks? */
/* These are internal state of ext4_do_writepages() */
loff_t start_pos; /* The start pos to write */
loff_t next_pos; /* Current pos to examine */
loff_t end_pos; /* Last pos to examine */
/*
* Extent to map - this can be after start_pos because that can be
* fully mapped. We somewhat abuse m_flags to store whether the extent
* is delalloc or unwritten.
*/
struct ext4_map_blocks map;
struct ext4_io_submit io_submit; /* IO submission data */
unsigned int do_map:1;
unsigned int scanned_until_end:1;
unsigned int journalled_more_data:1;
};
static void mpage_release_unused_pages(struct mpage_da_data *mpd,
bool invalidate)
{
unsigned nr, i;
pgoff_t index, end;
struct folio_batch fbatch;
struct inode *inode = mpd->inode;
struct address_space *mapping = inode->i_mapping;
/* This is necessary when next_pos == 0. */
if (mpd->start_pos >= mpd->next_pos)
return;
mpd->scanned_until_end = 0;
if (invalidate) {
ext4_lblk_t start, last;
start = EXT4_B_TO_LBLK(inode, mpd->start_pos);
last = mpd->next_pos >> inode->i_blkbits;
/*
* avoid racing with extent status tree scans made by
* ext4_insert_delayed_block()
*/
down_write(&EXT4_I(inode)->i_data_sem);
ext4_es_remove_extent(inode, start, last - start);
up_write(&EXT4_I(inode)->i_data_sem);
}
folio_batch_init(&fbatch);
index = mpd->start_pos >> PAGE_SHIFT;
end = mpd->next_pos >> PAGE_SHIFT;
while (index < end) {
nr = filemap_get_folios(mapping, &index, end - 1, &fbatch);
if (nr == 0)
break;
for (i = 0; i < nr; i++) {
struct folio *folio = fbatch.folios[i];
if (folio_pos(folio) < mpd->start_pos)
continue;
if (folio_next_index(folio) > end)
continue;
BUG_ON(!folio_test_locked(folio));
BUG_ON(folio_test_writeback(folio));
if (invalidate) {
if (folio_mapped(folio)) {
folio_clear_dirty_for_io(folio);
/*
* Unmap folio from page
* tables to prevent
* subsequent accesses through
* stale PTEs. This ensures
* future accesses trigger new
* page faults rather than
* reusing the invalidated
* folio.
*/
unmap_mapping_pages(folio->mapping,
folio->index,
folio_nr_pages(folio), false);
}
block_invalidate_folio(folio, 0,
folio_size(folio));
folio_clear_uptodate(folio);
}
folio_unlock(folio);
}
Annotation
- Immediate include surface: `linux/fs.h`, `linux/mount.h`, `linux/time.h`, `linux/highuid.h`, `linux/pagemap.h`, `linux/dax.h`, `linux/quotaops.h`, `linux/string.h`.
- Detected declarations: `struct mpage_da_data`, `function ext4_inode_csum`, `function ext4_inode_csum_verify`, `function ext4_inode_csum_set`, `function ext4_begin_ordered_truncate`, `function ext4_inode_is_fast_symlink`, `function iput`, `function ext4_discard_preallocations`, `function __check_block_validity`, `function ext4_issue_zeroout`.
- 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.