Fundamentals 16 min read

Understanding Linux Inodes, Dentries, and VFS: A Deep Dive into Filesystem Mechanics

This article explains how Linux manages disks and filesystems by detailing the roles of inodes and dentries, the structure of filesystem storage, the Virtual File System layer, various I/O classifications, and practical commands for observing filesystem performance and cache usage.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Understanding Linux Inodes, Dentries, and VFS: A Deep Dive into Filesystem Mechanics

Disk and Filesystem Basics

Disk management provides persistent storage, while the filesystem adds a hierarchical namespace for files. Linux treats every resource (regular files, directories, block devices, sockets, pipes) as a file.

Inode and Dentry

Each file is represented by two kernel data structures:

Inode : stores persistent metadata (inode number, size, permissions, timestamps, block locations) and occupies space on disk.

Dentry : stores the filename, a pointer to its inode, and links to other directory entries; dentries live in memory as a cache.

Multiple dentries (hard links) can point to the same inode, giving a file several names.

Filesystem Layout

When a disk is formatted, it is divided into three regions:

Superblock : global filesystem state.

Inode table : array of all inodes.

Data block area : stores file contents.

Files are stored in logical blocks (commonly 4 KB, i.e., eight 512 B sectors) to improve I/O efficiency.

Virtual File System (VFS)

VFS is an abstraction layer that defines common data structures and interfaces for all filesystem types. User processes and kernel subsystems interact with VFS instead of directly with a specific filesystem implementation.

Filesystem I/O Types

Typical file operations use system calls such as open(), read(), and write():

int open(const char *pathname, int flags, mode_t mode);
ssize_t read(int fd, void *buf, size_t count);
ssize_t write(int fd, const void *buf, size_t count);

I/O can be classified along four dimensions:

Buffered vs. Unbuffered : Buffered I/O uses the C library cache; unbuffered I/O bypasses it and calls the kernel directly.

Direct vs. Indirect : Direct I/O (e.g., O_DIRECT) skips the page cache; indirect I/O goes through the page cache.

Blocking vs. Non‑blocking : Blocking calls wait for completion; non‑blocking calls return immediately and later notify via polling or events (e.g., O_NONBLOCK).

Synchronous vs. Asynchronous : Synchronous I/O waits for the operation to finish; asynchronous I/O returns immediately and signals completion later (e.g., O_SYNC, O_DSYNC, O_ASYNC).

Performance Observation

Check filesystem capacity:

df /dev/vda1
Filesystem     1K-blocks    Used   Available Use% Mounted on
/dev/vda1      104846316 28228044 76618272 27% /

Human‑readable units:

df -h /dev/vda1
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 100G 27G 74G 27% /

Inode usage:

df -h -i /dev/vda1
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/vda1 50M 162K 50M 1% /

Cache statistics from /proc/meminfo:

cat /proc/meminfo | grep -E "SReclaimable|Cached"
Cached:          2014100 kB
SwapCached:        5316 kB
SReclaimable:    216128 kB

Directory‑entry and inode caches are managed by the slab allocator. Detailed slab statistics are available in /proc/slabinfo and can be summarized with slabtop:

# name    active_objs   num_objs   objsize   objperslab   pagesperslab : tunables
cat /proc/slabinfo | grep -E '^#|dentry|inode'

Typical output shows that dentry and inode_cache are the largest slab caches, together consuming roughly 60 MiB of memory.

Summary

Linux filesystems organize storage using a superblock, inode table, and data blocks. Inodes uniquely identify files, while dentries form the directory tree and are cached in memory. The Virtual File System layer provides a uniform interface for all filesystem types. Page cache, dentry cache, and inode cache mitigate disk latency, and the various I/O modes give developers fine‑grained control over performance characteristics.

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.

I/OLinuxVFSDentry
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.