Fundamentals 16 min read

Linux I/O and File System Principles: A Comprehensive Technical Guide

The guide explains Linux’s unified VFS architecture, detailing how inodes and dentries map files to disk regions, describes superblock and data block layout, outlines ZFS’s pool, copy‑on‑write and ARC caching, covers block device types, I/O scheduling queues, and key performance metrics.

Tencent Cloud Developer
Tencent Cloud Developer
Tencent Cloud Developer
Linux I/O and File System Principles: A Comprehensive Technical Guide

This article provides an in-depth explanation of how Linux handles I/O operations when applications read and write files to disk, based on a detailed architectural diagram.

1. File System Overview

A file system is a mechanism for organizing and managing files on storage devices. Different organization methods produce different file systems such as Ext4, XFS, ZFS, and NFS. Linux virtualizes various file systems through VFS (Virtual File System) to provide a unified interface for developers using standard system calls like open, read, write, and close.

Linux implements "everything is a file" philosophy, managing not only regular files and directories but also block devices, sockets, and pipes through a unified file system. Two key data structures manage these different file types:

inode (index node) : Stores file metadata including inode number, file size, access permissions, modification dates, and data location. Each file has a one-to-one correspondence with its inode, which is persisted to disk.

dentry (directory entry) : Records file names, inode pointers, and relationships with other dentries. Unlike inodes, dentries are maintained in-memory as a kernel data structure (dentry cache).

2. File Storage on Disk

When formatting a disk, the file system divides it into three regions: Superblock, inode blocks, and data blocks. The Superblock contains critical filesystem metadata including total/used/free inode and data block counts, file system format, and ownership information. If the Superblock becomes corrupted, the file system cannot be mounted. Multiple Superblock copies exist for redundancy.

Files are stored through a hierarchical structure: dentry contains the file name and inode pointer, the inode points to specific data blocks in the inode blocks region, and those data blocks contain the actual file content. Logical block size is typically larger than physical block size (sector for HDD, page for SSD) to improve efficiency.

3. ZFS File System

ZFS uses a layered architecture: physical disks form vdevs, multiple vdevs form a zpool, and ZFS file systems are created on top of zpools. Key features include:

Pool Storage : Dynamic storage expansion as zpools can grow dynamically, with multiple file systems sharing the full zpool space without pre-allocation.

Transactional File System : Write operations are transactional using copy-on-write - data is written to a new location, then the old location is recycled, ensuring no partial writes occur during power failures.

ARC Cache : Adaptive Replacement Cache uses four lists (LRU, LFU, and their ghost lists) to dynamically balance between recency-based and frequency-based caching strategies.

4. Disk Types and Interfaces

Disks are categorized by storage medium (HDD/SSD) and interface (IDE, SCSI, SAS, SATA). In Linux, disks are managed as block devices with major and minor device numbers - for example, /dev/sda has major number 8 indicating an SD-type block device.

5. Generic Block Layer and I/O Scheduling

The Block Layer sits between the file system and disk drivers, supporting both single-queue and multi-queue (blkmq) scheduling since kernel 3.16. Single-queue schedulers include NOOP (FIFO), CFQ (Completely Fair Queueing), and Deadline. Multi-queue schedulers include BFQ (Budget Fair Queueing), Kyber, and mq-deadline.

6. Performance Metrics

Five key I/O performance metrics: utilization (ioutil), IOPS, throughput/bandwidth, response time, and saturation. Tools like iostat, pidstat, and iotop provide visibility into these metrics from /proc/diskstats.

I/OLinuxOperating SystemStorageFile SystemInodeBlock DeviceVFSZFS
Tencent Cloud Developer
Written by

Tencent Cloud Developer

Official Tencent Cloud community account that brings together developers, shares practical tech insights, and fosters an influential tech exchange community.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.