Fundamentals 16 min read

Unlocking Linux File System Secrets: Disk Structure, Inodes, and IO Performance

This article explores Linux file system fundamentals, covering physical disk layout, partition strategies, how the OS reduces random‑read latency, the real space cost of empty files and directories, inode usage, block allocation, and practical tips for improving disk I/O performance.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Unlocking Linux File System Secrets: Disk Structure, Inodes, and IO Performance

Disk Composition and Partitioning

The discussion starts with the physical structure of a mechanical hard disk, describing platters, heads, tracks, cylinders, and sectors. An example from fdisk shows a virtual machine with 255 heads, 3263 cylinders, 63 sectors per track, and a 512‑byte sector size, yielding a total capacity of roughly 26.8 GB.

Two partitioning schemes are compared: dividing by platter (head) ranges versus dividing by cylinder ranges. The article explains that modern operating systems prefer cylinder‑based partitioning because it minimizes head movement, reducing seek time and overall I/O latency.

Disk I/O Process

Each I/O operation consists of three steps: (1) seek – moving the head to the correct track, (2) rotational latency – waiting for the target sector to rotate under the head, and (3) transfer – reading or writing the data. Total I/O time = seek time + rotational delay + transfer time. Typical seek times are 3–15 ms, rotational delay for a 10 k RPM disk is about 6 ms, and transfer time is usually sub‑millisecond.

Directories and Files

Linux treats directories as special files that store metadata and a list of directory entries. Experiments with touch, df -i, and dumpe2fs reveal that an empty file still consumes an inode (commonly 256 bytes) even though its data block size is reported as 0 bytes.

Creating an empty directory consumes a full filesystem block (typically 4 KB) plus one inode. The block holds the directory entries, including file names. Adding many short‑named files increases the number of blocks the directory occupies; longer file names consume more space within those blocks but do not proportionally increase the block count.

Inode and Block Details

Inodes store file metadata such as permissions, owner, timestamps, and pointers to data blocks. Their size is set when the filesystem is formatted (e.g., 256 bytes on the author's ext filesystem). Directories also have an inode, so an empty directory occupies one block (4 KB) plus its inode.

File data is allocated in blocks, the smallest unit the kernel can assign. Even a file containing a single space character is allocated a full block (usually 4 KB) plus an inode. Consequently, a 1 KB file actually uses one 4 KB block and one inode.

Performance Implications

Reading a tiny amount of data (e.g., 2 bytes) still triggers a full block read, which explains why disk I/O appears slow. To improve performance, developers can pre‑allocate the expected file size (using fallocate or similar) so the kernel can allocate contiguous blocks, reducing future seek time.

Large numbers of files in a single directory increase inode consumption and directory‑block traversal time. The article advises keeping the number of entries per directory below ten thousand and monitoring inode usage with df -i to avoid running out of inodes despite having free disk space.

Practical Recommendations

Choose a block size that matches typical file sizes: larger blocks for big files, smaller blocks for many tiny files. Regularly check inode availability, and avoid over‑populating directories to maintain acceptable lookup performance.

Understanding these low‑level details helps developers write more efficient code, diagnose storage‑related issues, and make informed decisions when formatting or configuring Linux filesystems.

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.

Linuxfile systemPartitioningDisk I/OinodesFilesystem Fundamentals
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

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.