This page provides a high-level technical orientation to the core local filesystems implemented in the Linux kernel. It maps high-level filesystem concepts (journaling, allocation, extent management) to their specific implementations within the fs/ directory.
Local filesystems translate VFS (Virtual File System) operations into physical storage layouts. While they share common VFS interfaces defined in include/linux/fs.h, their internal architectures vary significantly based on their design goals (e.g., performance, reliability, or flash-friendliness).
The following diagram bridges filesystem concepts to specific code entities across the major local filesystems.
Filesystem Subsystem Map
Sources: fs/ext4/inode.c22-53 fs/btrfs/inode.c38-75 fs/f2fs/f2fs.h179-198 fs/fuse/dev.c7-25
ext4 is a mature, journaling filesystem using an extent-based approach for tracking file data blocks. It relies on the JBD2 (Journaling Block Device) layer for metadata consistency fs/ext4/ext4_jbd2.h1
fs/ext4/inode.c, this includes inode checksum verification functions like ext4_inode_csum_verify fs/ext4/inode.c90-109 and eviction cleanup in ext4_evict_inode fs/ext4/inode.c169-170fs/ext4/mballoc.c optimizes contiguous block allocation, using different allocation criteria such as CR_POWER2_ALIGNED and CR_GOAL_LEN_FAST per fs/ext4/ext4.h136-176fs/ext4/extents.c. The function ext4_inode_is_fast_symlink fs/ext4/inode.c151-164 identifies symlinks with inline data.fs/ext4/ext4_jbd2.h.fs/ext4/fast_commit.c.For details, see ext4 Deep Dive: inodes, extents, fast_commit.
Sources: fs/ext4/inode.c22-164 fs/ext4/ext4.h136-176 fs/ext4/fast_commit.c1-100
btrfs is a Copy-on-Write filesystem emphasizing integrity, snapshots, and advanced volume management. It employs a unified B-tree structure for handling both metadata and data.
fs/btrfs/inode.c, with features including complex error reporting like print_data_reloc_error to decode checksum errors and backreferences fs/btrfs/inode.c214-230 and inode argument structures for retrieval fs/btrfs/inode.c78-81fs/btrfs/extent_io.c module handles all extent-related IO, including submitting bios and checksumming, providing functions like btrfs_read_extent_buffer defined also in fs/btrfs/disk-io.c fs/btrfs/disk-io.c214-253fsync, btrfs implements a log-tree replay mechanism in fs/btrfs/tree-log.c, managing staged replay phases (LOG_WALK_REPLAY_INODES, etc.) and maintaining state using walk_control fs/btrfs/tree-log.c88-159fs/btrfs/relocation.c where the reloc_control structure tracks relocation state fs/btrfs/relocation.c146-183fs/btrfs/qgroup.c and fs/btrfs/zoned.c, respectively.For details, see btrfs Deep Dive: copy-on-write trees, logging, and zoned mode.
Sources: fs/btrfs/inode.c78-230 fs/btrfs/extent_io.c1-150 fs/btrfs/tree-log.c88-159 fs/btrfs/relocation.c146-183 fs/btrfs/qgroup.c1-100 fs/btrfs/zoned.c1-75
xfs is engineered for high-performance and scalability, using Allocation Groups (AGs) to parallelize metadata operations on large filesystems.
fs/xfs/xfs_buf.c manages xfs_buf structures that cache metadata buffers and synchronize I/O.fs/xfs/xfs_zone_gc.c, where xfs_gc_bio tracks GC IO operations fs/xfs/xfs_zone_gc.c29-110fs/xfs/xfs_super.c manages mount and superblock lifecycles.fs/xfs/xfs_trace.h for observability.For details, see xfs Deep Dive: buffers, zones, and health monitoring.
Sources: fs/xfs/xfs_zone_gc.c29-110 fs/xfs/xfs_trace.h1-40
f2fs is optimized for flash devices, utilizing a log-structured design tailored for NAND flash characteristics.
fs/f2fs/node.c to track nodes efficiently fs/f2fs/node.c223-240fs/f2fs/segment.c and fs/f2fs/gc.c, reclaiming blocks to sustain write performance fs/f2fs/super.c38fs/f2fs/compress.c; f2fs_is_compressed_page identifies compressed pages during reads in fs/f2fs/data.c fs/f2fs/data.c162fs/f2fs/super.c) integrates fault injection utilities for testing errors like block allocation failures (FAULT_BLOCK) and write IO errors (FAULT_WRITE_IO), with the fault type array defined in fs/f2fs/f2fs.h:42-70 fs/f2fs/super.c48-75 and fs/f2fs/f2fs.h42-70bio_post_read_ctx structure in fs/f2fs/data.c which handles finishing and verification of bios fs/f2fs/data.c121-195For details, see f2fs Deep Dive: NAT/SIT, segments, GC, compression.
Sources: fs/f2fs/node.c223-240 fs/f2fs/gc.c1-80 fs/f2fs/data.c121-195 fs/f2fs/super.c48-75 fs/f2fs/f2fs.h42-70
FUSE provides a kernel interface to implement filesystems in userspace, with the kernel component managing communication through /dev/fuse.
fuse_req structures in fs/fuse/dev.c, which handle request lifecycle states such as pending and background execution. Functions like fuse_request_alloc and fuse_get_req are key fs/fuse/dev.c35-147io_uring support found in fs/fuse/dev_uring.c.fs/fuse/file.c using functions like fuse_do_open and fuse_finish_open fs/fuse/file.c189-235Sources: fs/fuse/dev.c35-147 fs/fuse/file.c189-235 fs/fuse/dev_uring.c44-59
fs/erofs/.Sources: fs/gfs2/glock.c186-191
Local filesystems integrate with the kernel's tracing framework to expose internal state, performance metrics, and debugging information.
Filesystem Tracepoint Integration
| Filesystem | Key Tracepoint Hook | Code Location |
|---|---|---|
| ext4 | trace_ext4_begin_ordered_truncate | fs/ext4/inode.c133 |
| f2fs | trace_f2fs_init_bioset | fs/f2fs/data.c29 |
| fuse | trace_fuse_request_send | fs/fuse/dev.c268 |
| btrfs | trace_btrfs_transaction_commit | fs/btrfs/transaction.c2463 |
| gfs2 | trace_gfs2_glock_hold | fs/gfs2/glock.c186-191 |
| xfs | xfs_gc tracepoints | fs/xfs/xfs_zone_gc.c29-52 |
This page is a parent overview. For a deep dive into each filesystem’s internal core logic and major subsystems, follow the links below:
Sources:
fs/ext4/inode.cfs/ext4/ext4.hfs/ext4/fast_commit.cfs/btrfs/inode.cfs/btrfs/extent_io.cfs/btrfs/tree-log.cfs/btrfs/relocation.cfs/btrfs/qgroup.cfs/btrfs/zoned.cfs/f2fs/f2fs.hfs/f2fs/data.cfs/f2fs/super.cfs/fuse/dev.cfs/fuse/file.cfs/fuse/dev_uring.cfs/gfs2/glock.cfs/xfs/xfs_zone_gc.cfs/xfs/xfs_trace.hRefresh this wiki
This wiki was recently refreshed. Please wait 1 day to refresh again.