High-volume creation and rapid deletion of temporary files—often spawned by compilers, background batch workers, or container runtimes—can severely degrade Virtual File System (VFS) performance and exhaust inode tables. Because standard audit logging tools such as auditd impose heavy CPU overhead, tracing files that exist for only milliseconds requires kernel-level instrumentation. The eBPF-powered filelife utility tracks file creation through deletion events, calculating exact lifespans with negligible system impact.
How filelife Leverages eBPF for File Tracking
Rather than continuously monitoring every filesystem I/O event, filelife targets the kernel VFS lifecycle hooks:
- VFS Creation Probes: Attaches kprobes to
vfs_create()to record the timestamp, process ID, and filename into an eBPF BPF_HASH map. - VFS Unlink Probes: Attaches kprobes to
vfs_unlink()to match file deletion events against the hash map. - Lifespan Calculation: Subtracts the creation timestamp from the deletion timestamp to determine the file’s lifespan down to fractional seconds before emitting a telemetry record.
Installing the BCC Tracing Tools
Ensure the BPF Compiler Collection (BCC) and matching kernel headers are installed:
# Ubuntu / Debian
sudo apt update
sudo apt install -y bpfcc-tools linux-headers-$(uname -r)
# Fedora / RHEL / AlmaLinux
sudo dnf install -y bcc-tools kernel-devel-$(uname -r)
The executable is typically installed at /usr/sbin/filelife-bpfcc or /usr/share/bcc/tools/filelife.
Tracing Short-Lived Files in Real Time
Execute filelife as root to begin monitoring ephemeral file creation:
sudo filelife-bpfcc
When processes create and delete files, filelife streams real-time event logs:
TIME PID COMM AGE(s) FILE
11:22:04 28410 cc1 0.08 /tmp/ccX492A.s
11:22:05 28414 as 0.02 /tmp/ccZ881B.o
11:22:18 19440 python3 1.45 /var/run/app/worker_temp.lock
11:22:32 30105 git 0.12 .git/index.lock
The output columns identify:
- TIME: Time of file deletion.
- PID & COMM: The process responsible for removing the file.
- AGE(s): Total seconds the file existed between creation and deletion.
- FILE: Complete filesystem path of the temporary file.
Filtering by Lifespan Duration
To ignore files that survive for extended durations and focus strictly on rapid ephemeral churn:
# Trace files that live for 10 seconds or fewer
sudo filelife-bpfcc -d 10
This filters out long-lived configuration or state files, isolating high-frequency scratch disk operations.
Mitigating Ephemeral Disk Churn with tmpfs
If filelife reveals heavy short-lived writes to physical SSDs or HDDs:
- Redirect target application scratch directories to an in-memory
tmpfsmount:# Check active tmpfs mounts df -h -t tmpfs # Mount dedicated in-memory scratch space sudo mount -t tmpfs -o size=2G,noexec,nosuid tmpfs /mnt/fast-scratch - Configure the
TMPDIRenvironment variable for backend workers:export TMPDIR=/mnt/fast-scratch - Re-run
filelife-bpfccto verify that temporary file I/O operations are serviced entirely from RAM, eliminating storage wear and block latency.