How to Trace VFS Directory Operations and Call Frequency in Linux Using vfscount

The Virtual File System (VFS) layer in Linux provides a unified abstraction over diverse storage systems, including ext4, XFS, Btrfs, and network file shares. Whenever applications read files, traverse directory trees, create inodes, or write logs, execution flows through kernel VFS functions. Measuring the operational frequency and throughput of these VFS calls is essential for diagnosing disk bottlenecks and software slowdowns. The vfscount utility, part of the BPF Compiler Collection (BCC), dynamically traces VFS operations system-wide with near-zero performance overhead.

Why Trace VFS Calls in Linux?

Traditional monitoring tools such as iostat or vmstat report block-level physical disk throughput, but they are blind to calls satisfied directly by the Linux page cache or dentry directory cache. An intensive indexing script or rogue search process might generate millions of directory traversal operations per second, consuming severe CPU cycles while showing almost zero physical disk I/O.

The vfscount tool hooks into high-level VFS functions (such as vfs_read, vfs_write, vfs_fsync, and vfs_create) using extended Berkeley Packet Filters (eBPF). This reveals exact file system demand patterns directly at the kernel boundary.

Installing the BCC Tools Suite

The vfscount utility requires the BCC package and kernel development headers.

On Debian, Ubuntu, and Linux Mint systems:

sudo apt update
sudo apt install bpfcc-tools linux-headers-$(uname -r)

On RHEL, Rocky Linux, AlmaLinux, or Fedora:

sudo dnf install bcc-tools kernel-devel-$(uname -r)

The binary is typically located at /usr/sbin/vfscount-bpfcc or /usr/share/bcc/tools/vfscount.

Running vfscount to Measure File System Activity

Running vfscount with no arguments begins system-wide kernel function counting. Press Ctrl + C after a sampling duration to display aggregated counts:

sudo vfscount-bpfcc

Sample output from an active production server:

Tracing VFS calls... Hit Ctrl-C to end.
^C
ADDR             FUNC                          COUNT
ffffffffb432a100 vfs_fsync                         24
ffffffffb432b400 vfs_create                       142
ffffffffb4329200 vfs_open                        4820
ffffffffb4328b00 vfs_write                      18293
ffffffffb4328500 vfs_read                       94201

This breakdown clearly illustrates whether workloads are predominantly read-heavy, write-intensive, or bound by metadata creation operations.

Interval-Based VFS Monitoring

Rather than accumulating totals over an indefinite span, specify an interval (in seconds) and optional count to stream periodic snapshots:

sudo vfscount-bpfcc 5

This command prints updated VFS function call tallies every 5 seconds, allowing administrators to correlate workload spikes with scheduled batch jobs, web requests, or database checkpoints.

Diagnosing High Metadata and Directory Traversal Workloads

When investigating systems suffering from elevated system CPU usage without corresponding storage transfer volume, examine functions responsible for directory resolution and file attributes:

  • High vfs_open counts: Indicates processes frequently re-opening files without connection pooling or persistent file handles.
  • Elevated vfs_create / vfs_unlink counts: Suggests heavy temporary file churn, common in build systems, compilers, or improperly configured application caches.
  • Frequent vfs_fsync invocations: Highlights excessive synchronous disk flushing, which severely limits transaction throughput on storage volumes.

Complementing vfscount with Latency Tracing

While vfscount provides high-level event frequency, pairing it with vfsstat or fileslower provides latency and filename context:

# Stream per-second VFS call rates
sudo vfsstat-bpfcc 1

# Trace file operations taking longer than 10 milliseconds
sudo fileslower-bpfcc 10

By leveraging vfscount during routine diagnostics, Linux systems engineers can quickly distinguish between physical drive latency and upstream application-level file system churn.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.