Introduction
Open a terminal and type cat /etc/hostname.
Now try cat /proc/cpuinfo.
Then plug in an old USB stick and cat whatever file you find on it.
The first file lives on your SSD, probably in an ext4 or Btrfs partition.
The second one exists nowhere on disk: the kernel generates it every time you read it.
The third one sits on a FAT32 stick that Windows formatted fifteen years ago.
Three files, three completely different worlds, and yet cat treats them exactly the same.
It calls open(), read(), close(), and it works.
Not a single line of code in cat knows what a FAT allocation table or an ext4 extent tree looks like.
The layer that makes this possible is called the Virtual File System, or VFS. It is one of the oldest abstractions in the Linux kernel, and in my opinion one of the most elegant. It is also the reason why “everything is a file” is more than a UNIX slogan.
In this article I want to explain what problem the VFS solves, where the idea comes from, how it is implemented, and what it costs us.
Note
Code excerpts in this article are simplified and based on a recent Linux kernel (6.x). Function and structure names change over time, but the architecture described here has been stable for decades.
One tree, many filesystems
Let us state the problem first.
A filesystem is a data structure laid out on a storage device to organize bytes into files and directories. Every filesystem makes different design choices. ext4 tracks file data with extent trees and preallocated inode tables. XFS is built around B+ trees and allocation groups. FAT32 uses a simple allocation table and has no notion of permissions at all. Btrfs and ZFS are copy-on-write systems with built-in checksumming. NFS is not even a disk format, it is a network protocol.
You can see how many filesystems your kernel knows about right now:
|
|
The kernel source tree contains more than fifty filesystem implementations under fs/, and a few more live elsewhere, such as tmpfs in mm/ and cgroup in kernel/.
And a typical desktop has well over a dozen of them mounted at the same time (run findmnt to see yours): ext4 for the root partition, vfat for the EFI partition, tmpfs for /run (and often /tmp), proc for /proc, sysfs for /sys, devtmpfs for /dev, cgroup2 for /sys/fs/cgroup, maybe NFS or SMB for a network share, and many more.
Despite this diversity, UNIX systems present a single tree to user space.
There is no C: or D: drive.
Every filesystem is mounted somewhere in one hierarchy starting at /, and a path like /home/user/report.pdf may cross three different filesystems without the user ever noticing.
So the kernel has a real engineering problem on its hands. How do you let dozens of radically different on-disk (and not-on-disk) formats coexist behind one uniform tree and one set of system calls?
A thought experiment: life without the VFS
Imagine for a moment that Linux had no VFS.
Every program would need to know which filesystem it is talking to.
The C library would ship with open_ext4(), open_fat() and read_nfs(), and your code would look like this:
|
|
Every new filesystem would require patching every application, or at least the C library.
Shell redirection, pipes and cp would need format-specific logic.
Backup tools would break with each new kernel release.
This is not a strawman, by the way.
Early operating systems really worked like this.
MS-DOS was welded to FAT, its default and native filesystem.
The original UNIX kernel was welded to its native filesystem too: the implementation of open() and read() manipulated its on-disk structures directly, so supporting a second format meant surgery in the heart of the kernel.
You can still read this code in the UNIX V6 sources from 1975: open() calls namei() in nami.c, which reads raw directory blocks and parses their fixed 16-byte entries, and iget() in iget.c finds an inode on disk with a hard-coded formula, bread(dev, ldiv(ino+31,16)).
Splitting that code into a generic part and a filesystem-specific part is the very first design goal listed in Sun’s vnode paper.
The idea that solved this is one of the oldest tricks in software engineering: add a layer of indirection. Define an abstract model of what “a filesystem” is, write the system calls against that model, and let each concrete filesystem plug into it.
That layer is the VFS.
A bit of history: from vnodes to Linux
The VFS was not invented by Linux, far from it.
In 1985, Sun Microsystems needed its brand new Network File System (NFS) to coexist with the local Berkeley FFS filesystem inside SunOS. Steve Kleiman’s 1986 USENIX paper, “Vnodes: An Architecture for Multiple File System Types in Sun UNIX”, describes their solution: split the kernel’s file code into a filesystem-independent layer and a set of filesystem-dependent modules, connected by tables of function pointers. Each open file was represented by a vnode (virtual node) whose operations were provided by the concrete filesystem.
The design worked so well that it spread to System V Release 4, the BSD family, and pretty much every serious UNIX of the era.
Linux picked up the same idea very early. The first releases of Linux in 1991 only supported the Minix filesystem, with its painful limits: 14-character file names and 64 MB per partition. To make room for new filesystems without throwing away Minix support, a VFS layer was introduced in early 1992. Linus announced the first “VFS-stubs”, based on patches by Chris Provenzano, for Linux 0.95 on the mailing list in March 1992, calling the VFS “easily the biggest patch to date”. The ext filesystem followed in April 1992 and was added to Linux 0.96c, as told by its authors. Since then, every filesystem Linux has ever supported, from ext2 in 1993 to bcachefs in 2024, has been a plugin behind that interface.
Info
NFS is the reason your open() calls go through a virtual layer today.
The abstraction was born from the need to make the network look like a disk, and that ambition shaped everything that followed.
The VFS from 10,000 feet
Conceptually, the VFS sits between the system call interface and the concrete filesystems:
|
|
User space only ever talks to the top layer. The VFS implements everything that is common to all filesystems: resolving paths, checking permissions, managing open file descriptions, caching. Everything that is format-specific, like finding a file’s data on disk or allocating blocks, is delegated to the layer below.
For this delegation to work, the VFS defines a common language: a small set of kernel objects that every filesystem must speak.
The four objects of the VFS
The VFS models any filesystem with four main structures, defined in include/linux/fs.h and documented in Documentation/filesystems/vfs.rst.
The first one is the superblock (struct super_block).
It represents a mounted filesystem instance as a whole: its block size, its limits, its root, and the methods to allocate or write back inodes.
For on-disk filesystems it usually mirrors a header stored at a well-known location on the partition.
Then comes the inode (struct inode), which represents a single filesystem object: a regular file, a directory, a symlink, a device node.
It carries the metadata (owner, permissions, size, timestamps) but, famously, not the file name.
The name lives in the dentry (struct dentry, for directory entry).
A dentry represents one component of a path, like home or report.pdf, and maps that name to an inode.
Dentries exist to make path resolution fast: they live in a dedicated cache and have no direct on-disk equivalent.
Finally, the file (struct file) represents a file opened by a process, with the current read/write offset, the access mode, and a pointer to the dentry.
Your integer file descriptor is nothing more than an index into a per-process table of struct file pointers.
The trick that connects these abstract objects to concrete code is the same one Sun used in 1985: tables of function pointers, which is basically how you do object-oriented programming in C.
Each object embeds a pointer to an operations table filled in by the filesystem.
Here is what ext4 plugs into the VFS for regular files, simplified from fs/ext4/file.c:
|
|
When a process reads from a file, the VFS simply calls file->f_op->read_iter(...) without knowing, or caring, where that pointer leads.
If the file is on ext4, the call lands in ext4_file_read_iter().
If it is on NFS, the same call lands in a function that sends a request over the network.
If you prefer object-oriented vocabulary: read_iter is a virtual method, and ext4, NFS and vfat are subclasses that override it.
Writing a filesystem for Linux therefore means one thing: filling these tables. This is exactly what you do when you implement your own filesystem with FUSE, just from user space.
Following a read() through the kernel
Theory is nice, but let us follow a real system call from top to bottom. If you want to read along, every link in this section points to the Linux 6.12 source code on Elixir. Suppose a process runs:
|
|
First, path resolution.
open() enters the kernel and reaches path_openat() in fs/namei.c, which drives the open and hands the path off to the VFS path walker (link_path_walk()).
The path is split into components: home, user, notes.txt.
For each component, the VFS first looks into the dentry cache (lookup_fast()).
On a miss, it calls the parent directory’s inode->i_op->lookup() method, and the concrete filesystem reads its on-disk structures to find the child inode.
If the walk crosses a mount point, the VFS transparently switches to the superblock of the mounted filesystem (handle_mounts()).
This is how one tree can span many filesystems.
Second, opening.
The VFS checks permissions against the inode (may_open()), allocates a struct file, calls the filesystem’s open method if it has one (do_dentry_open()), and installs the file into the process’s descriptor table (fd_install()).
The integer you receive is the index of that slot.
Third, reading.
read(fd, ...) looks up the struct file (ksys_read()), then the VFS calls file->f_op->read_iter().
For most disk filesystems this lands in generic VFS helper code that checks the page cache first: ext4’s ext4_file_read_iter(), for example, goes through generic_file_read_iter() to filemap_read().
If the data is already cached in RAM, it is copied to user space and no disk I/O happens at all.
Only on a cache miss does the filesystem’s own code get asked to fetch the blocks from the device, through its read_folio() method.
Notice how much work the VFS did for the filesystem here: path splitting, caching, permission checks, offset management, page cache handling.
A concrete filesystem only answers narrow questions like “what is the inode of notes.txt inside this directory?” and “fetch these blocks”.
That is the second big reason Linux needs a VFS.
Not just uniformity, but massive code reuse: every filesystem gets a battle-tested cache and POSIX-compliant behaviour for free, and a bug fixed in the VFS is fixed for all of them at once.
Tip
You can watch the VFS in action with strace cat /proc/cpuinfo: you will see plain openat() and read() calls, indistinguishable from reads of a real disk file.
Everything is a file, because of the VFS
Once the kernel routes every file operation through virtual method tables, something interesting becomes possible: implementing the interface without any disk at all.
Nothing forces read_iter() to fetch data from a device.
It can compute its answer, forward it over a network, or pull it from kernel memory.
Linux exploits this everywhere:
- procfs (
/proc) exposes processes and kernel state as files.cat /proc/cpuinforuns a kernel function that formats CPU data on demand. - sysfs (
/sys) exposes the device model: every USB port, network card and LED brightness knob is a file. - tmpfs (
/run,/dev/shm, often/tmp) stores files purely in the page cache, which gives you a RAM disk for free. - devtmpfs (
/dev) gives hardware a file name: it creates the/dev/sdanode so you can open it, and the kernel routes the actual reads and writes down to the block layer from there. - FUSE forwards every operation to a user-space process, which is how
sshfscan mount a remote server over SSH without one line of new kernel code. - Network filesystems like NFS, SMB and 9p translate file operations into network messages.
I find it easy to underestimate how big this payoff is.
Because all of these speak “file”, every existing tool works on them.
You can grep your kernel configuration, monitor processes with cat, control hardware from a shell script with echo, and back up a raw disk with cp.
Scripting languages, editors and backup tools gained access to kernel internals and remote servers without being modified.
This is why “everything is a file” really means “everything is a client of the VFS”. The slogan describes the interface. The VFS is the machinery that lets wildly different things hide behind it.
The dentry cache, or why the VFS is also about speed
A common objection to abstraction layers is performance. The VFS answers it by being not just a switchboard, but a cache.
Path resolution is one of the hottest operations in a kernel.
Building a large C project can trigger millions of open() and stat() calls, and each one must translate a path into an inode.
Asking the concrete filesystem to walk its on-disk directories every time would be a disaster, especially for network filesystems where each lookup is a round trip.
This is what dentries are for.
The dentry cache (dcache) keeps recently resolved path components in a hash table in RAM.
On a warm cache, resolving /home/user/notes.txt never touches the filesystem below: the VFS finds the three dentries in the hash table.
The fast path, called RCU-walk, is optimized to the point of resolving components without taking a single lock.
Together with the inode cache and the page cache, this means the VFS layer absorbs the vast majority of file operations before they ever reach filesystem-specific code. The abstraction layer is, at the same time, the performance layer. Far from slowing Linux down, the VFS is where a lot of its filesystem speed actually comes from.
The price of abstraction
To be fair, the VFS is not free, and it would be dishonest to skip its costs.
There is a lowest common denominator effect.
The VFS interface models a POSIX filesystem: inodes, byte streams, owner/group/mode permissions.
Filesystems with a different native model must contort themselves.
FAT has no inode numbers or permissions, so the driver fabricates them from mount options.
Conversely, exotic features of a filesystem (Btrfs snapshots, XFS realtime volumes) cannot be expressed through standard calls and need filesystem-specific ioctl() escape hatches.
There is also indirection overhead.
Every operation crosses at least one indirect function call, which modern CPUs mispredict occasionally, and which the mitigations for speculative execution attacks made more expensive.
When retpolines were introduced against Spectre in 2018, Google measured that each indirect branch then cost from 3 extra cycles on average to about 30, for an overall overhead of 0 to 1.5% on their workloads.
For ultra-low-latency I/O on NVMe drives, even the generic VFS bookkeeping counts: these devices can answer in under 10 microseconds, and Jens Axboe benchmarked io_uring at 1.7 million 4 KiB reads per second with polling, against 608,000 for the older aio interface.
This is part of why interfaces like io_uring work so hard to shorten the path between the application and the driver.
Finally, the VFS is a serialization point. Because every filesystem shares the dcache and the inode locking rules, subtle VFS-level locking has historically been a scalability battlefield, and changing it requires understanding dozens of filesystems at once.
These costs are real but modest, and forty years of UNIX history have delivered a clear verdict: nobody seriously proposes removing the layer. The alternative, per-filesystem interfaces leaking into user space, was tried before 1985 and lost.
Conclusion
So, why does Linux need a VFS?
Because Linux promises user space a single, uniform world: one tree, one set of system calls, one meaning for “file”, while supporting dozens of filesystems that agree on almost nothing internally. Something has to reconcile the two, and that something is the VFS.
Thanks to it, cat works identically on ext4, FAT and NFS.
A new filesystem is a plugin that fills a few operation tables, not a rewrite of the kernel.
Path walking, the dentry cache and the page cache are implemented once and benefit everyone.
And processes, devices and remote servers can all hide behind ordinary file descriptors, which is where the generalized “everything is a file” philosophy actually comes from.
To me, the VFS is a textbook case of what a good abstraction does. It did not just solve the 1985 problem of making NFS and a local disk coexist. It created a stable interface behind which forty years of innovation (journaling, copy-on-write, FUSE, overlay filesystems for containers) could happen without user space noticing anything, except that things kept getting better.
Next time you type cat /proc/cpuinfo, spare a thought for the layer that makes a CPU table look like a text file.
Sources and further reading
- S. R. Kleiman, Vnodes: An Architecture for Multiple File System Types in Sun UNIX, USENIX Summer 1986.
- Overview of the Linux Virtual File System, Linux kernel documentation.
- Daniel P. Bovet and Marco Cesati, Understanding the Linux Kernel, 3rd edition, O’Reilly, 2005, chapter 12.
- Robert Love, Linux Kernel Development, 3rd edition, Addison-Wesley, 2010, chapter 13.
- Jonathan Corbet, Creating Linux virtual filesystems, LWN.net, 2002.
- Jonathan Corbet, Dcache scalability and RCU-walk, LWN.net, 2010.
- File Allocation Table, Wikipedia.
- Rémy Card, Theodore Ts’o and Stephen Tweedie, Design and Implementation of the Second Extended Filesystem, First Dutch International Symposium on Linux.
- Paul Turner, Retpoline: Binary mitigation for branch-target-injection, LKML, 2018.
- Jens Axboe, Efficient IO with io_uring, 2019 (archived copy).
- UNIX V6 kernel source code, The Unix Heritage Society archive, 1975.
- Angelina Kuntz, How to implement our own file system, GISTRE blog, 2024.