Operations 31 min read

Mastering Linux Disk I/O: Principles, Metrics, and Optimization Strategies

This comprehensive guide explains Linux disk I/O fundamentals, compares HDD and SSD characteristics, details file system structures, outlines I/O operation flow, introduces key performance metrics like IOPS, throughput and latency, and provides practical testing tools and optimization techniques for both applications and storage layers.

Deepin Linux
Deepin Linux
Deepin Linux
Mastering Linux Disk I/O: Principles, Metrics, and Optimization Strategies

Part1 Linux Disk I/O Working Principles

1.1 Disk Types and Characteristics

Linux systems use mechanical hard drives (HDD) and solid‑state drives (SSD). HDDs rely on rotating platters and moving read/write heads, offering sequential speeds of 100‑200 MB/s and much lower random performance. SSDs store data in NAND flash, delivering sequential speeds of 3 GB/s (NVMe) and far superior random I/O, though they have limited write cycles and higher cost per capacity.

1.2 File System Mechanism

The file system organizes files like a library. An inode acts as a file’s identity card, storing metadata such as size, permissions, timestamps, and block locations. A dentry (directory entry) is the file’s name card, linking a name to an inode and forming the directory tree. The Virtual File System (VFS) provides a uniform interface for various concrete file systems (e.g., EXT4, XFS, Btrfs), allowing applications to use generic system calls (open, read, write) without caring about underlying implementations.

Disk‑based file systems (e.g., EXT4, XFS, OverlayFS) store data on local disks.

Memory‑based (virtual) file systems (e.g., /proc) reside entirely in RAM.

Network file systems (e.g., NFS, SMB, iSCSI) access remote storage.

1.3 I/O Operation Flow Analysis

When an application reads a file, the kernel first checks the page cache. If the data is cached, it is copied directly to user space. Otherwise a page fault triggers a disk read: the file system locates the data, the disk performs the I/O (mechanical seek for HDD, electronic read for SSD), and the data is placed in the page cache before being copied to the application. Writes are buffered as dirty pages and flushed to disk later, reducing the number of actual I/O operations but risking data loss on crashes.

Part2 Key Metrics for Disk I/O Performance

2.1 IOPS (Input/Output Operations Per Second)

IOPS measures how many I/O requests a storage device can handle per second, reflecting random read/write capability. High IOPS are crucial for databases and virtualized environments where many small, non‑sequential operations occur.

2.2 Throughput

Throughput (bytes per second) indicates the volume of data transferred over time, essential for sequential workloads such as video streaming or large file backups. SSDs and high‑speed interfaces (NVMe) provide far higher throughput than HDDs.

2.3 Latency

Latency is the time from issuing an I/O request to receiving the response. High latency harms real‑time systems like trading platforms or games. Mechanical drives suffer from seek and rotational delays, while SSDs have lower but non‑zero controller and NAND latency.

Part3 Practical Disk I/O Performance Testing Tools

3.1 fio (Flexible I/O Tester)

fio is a powerful, cross‑platform I/O benchmark that can simulate various workloads. It supports many engines (sync, mmap, libaio) and I/O patterns (randread, randwrite, read, write, randrw).

# 使用fio进行磁盘I/O测试
fio --name=test --ioengine=libaio --iodepth=4 --rw=readwrite --bs=4k --size=1G --numjobs=1

Examples include sequential read tests and mixed random read/write workloads, adjusting parameters such as block size, queue depth, and runtime to model real‑world scenarios.

3.2 iostat (I/O Statistics)

iostat, part of the sysstat package, reports per‑device I/O statistics, including request rates, average wait time, and utilization percentage.

# 安装iostat(以CentOS为例)
sudo yum install sysstat

# 使用iostat查看磁盘I/O性能
iostat -mx 1

High "% util" or large "await" values indicate bottlenecks, prompting further tuning.

Part4 Linux Disk I/O Performance Optimization Strategies

4.1 Application‑Level Optimization

Prefer sequential I/O over random I/O, batch small operations into larger ones, and reduce unnecessary file opens/closes. Use asynchronous I/O (e.g., libaio) to overlap computation with I/O, and employ in‑memory caches (Memcached, Redis) to avoid disk access for hot data.

4.2 File System‑Level Optimization

Select an appropriate file system: EXT4 for general use, XFS for large files and high concurrency, Btrfs for snapshots and compression. Mount options like noatime and nodiratime suppress timestamp updates, reducing write traffic. Tune EXT4 journaling with tune2fs -o journal_data_writeback or adjust journal size to balance safety and speed.

4.3 Disk‑Level Optimization

Upgrade HDDs to SSDs for dramatic latency and IOPS gains. Configure RAID levels to match workload needs: RAID 0 for maximum throughput, RAID 1 for redundancy, RAID 5/10 for a balance of performance and fault tolerance. Choose an I/O scheduler suited to the storage medium— noop for SSDs, deadline for databases, or cfq for general purpose.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

performanceoptimizationLinuxDisk I/Ofioiostat
Deepin Linux
Written by

Deepin Linux

Research areas: Windows & Linux platforms, C/C++ backend development, embedded systems and Linux kernel, etc.

0 followers
Reader feedback

How this landed with the community

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.