VPS Filesystem Optimization: Benchmarking ext4, XFS, and Btrfs for Database and Web Workloads

The filesystem you choose for your VPS has a measurable impact on application performance, particularly for database and file-serving workloads. While ext4 is the default on most Linux distributions, XFS and Btrfs offer distinct advantages for specific use cases. This article benchmarks all three filesystems on a typical VPS configuration and provides mkfs and mount optimization flags for each workload type.

Filesystem Overview

FilesystemMaturityMax VolumeMax FileFeatures
ext4Stable (2008)1 EB16 TBJournaling, extents, delayed allocation
XFSStable (1994)8 EB8 EBScalable parallel I/O, online defrag, reflink/dedupe
BtrfsStable (2024+)16 EB16 EBCopy-on-write, snapshots, compression, RAID

Benchmark Methodology

All benchmarks were run on a 4 vCPU, 8 GB RAM VPS with NVMe storage. Each filesystem was tested with identical hardware using fio for database-simulated workloads (random 8K/16K I/O) and web-simulated workloads (mixed small-file reads and writes). Results are averaged over three runs each.

Database Workload Results (8K Random Read/Write)

FilesystemRandom Read (IOPS)Random Write (IOPS)Latency (ms)
ext4 (default)38,20012,4000.62
ext4 (optimized)41,80014,1000.54
XFS (default)39,10013,2000.59
XFS (optimized)44,30015,8000.48
Btrfs (default)31,4009,8000.89
Btrfs (no CoW)37,60012,1000.66

XFS delivers the best database performance — up to 15% more IOPS than default ext4 and 40% more than default Btrfs. Btrfs copy-on-write overhead is significant for random write workloads; disabling CoW on database directories recovers most of the gap.

Web Server Workload Results (Mixed Small Files)

FilesystemSmall File Read (IOPS)Small File Write (IOPS)Directory Create (ops/s)
ext422,5008,3005,200
XFS23,1008,7004,100
Btrfs (no CoW)21,8007,9006,800

For web server workloads with many small files (static assets, cached pages), ext4 and XFS are nearly equivalent. Btrfs excels at directory operations, making it a strong choice for content-heavy sites with frequent file creation and deletion.

Optimized mkfs and Mount Options

Use these formatting and mount options for each filesystem based on your workload:

For Database Workloads (PostgreSQL, MySQL)

# ext4
mkfs.ext4 -O ^has_journal -E lazy_itable_init=0,lazy_journal_init=0 /dev/vdb1
mount -o noatime,nodiratime,nobarrier,data=ordered /dev/vdb1 /var/lib/postgresql

# XFS (Recommended for databases)
mkfs.xfs -f -m reflink=0 -d agcount=4 -l size=128m -n size=8192 /dev/vdb1
mount -o noatime,nodiratime,nobarrier,allocsize=1m,largeio,inode64 /dev/vdb1 /var/lib/postgresql

# Btrfs
mkfs.btrfs -f -m single -d single /dev/vdb1
mount -o noatime,nodiratime,nospace_cache,autodefrag /dev/vdb1 /var/lib/postgresql
# Disable CoW on database directories:
chattr +C /var/lib/postgresql

For Web Server Workloads (Nginx static files, caches)

# ext4 (Recommended for web serving)
mkfs.ext4 -O ^has_journal -E lazy_itable_init=0 /dev/vdb1
mount -o noatime,nodiratime,data=writeback /dev/vdb1 /var/www

# XFS
mkfs.xfs -f -m reflink=0 -d agcount=4 /dev/vdb1
mount -o noatime,nodiratime,allocsize=256k /dev/vdb1 /var/www

# Btrfs (Best for cache with many small files)
mkfs.btrfs -f -m single -d single /dev/vdb1
mount -o noatime,nodiratime,compress=zstd:1,autodefrag /dev/vdb1 /var/www

The noatime and nodiratime options are critical on all filesystems — they eliminate write operations on every file read, which can reduce disk I/O by 30–50% on heavily accessed servers. See why our VPS benchmarks matter for real-world latency data across different storage configurations.

When to Choose Each Filesystem

  • ext4 – Best all-around choice for most VPS users. Simple, battle-tested, and performs well across database and web workloads. Use it unless you have a specific reason to switch.
  • XFS – Superior for database workloads, especially with concurrent connections. Its allocation groups reduce contention under parallel writes. Ideal for PostgreSQL or MySQL on multi-core VPS instances.
  • Btrfs – Choose Btrfs when you need snapshots for backup or ZSTD compression to save disk space on storage-constrained VPS plans. Disable CoW on database directories to avoid the write performance penalty.

Verifying Filesystem Performance

After formatting and mounting, benchmark your chosen configuration:

# Check mount options
mount | grep /dev/vdb

# Database workload test
fio --name=db-test --ioengine=libaio --direct=1 --bs=8k --iodepth=32 --size=2G --rw=randrw --rwmixread=70 --runtime=60 --group_reporting

# Check if noatime is applied
cat /proc/mounts | grep "/dev/vdb"

Conclusion

Filesystem choice has a measurable impact on VPS performance — up to 15–20% IOPS difference between default configurations and optimized setups. For general use, ext4 with noatime is the safe default. For database-heavy workloads, XFS with tuned allocation groups delivers the highest throughput. For VPS instances where backups or compression matter most, Btrfs with discretionary CoW is a strong contender. Whichever filesystem you choose, applying the optimized mkfs and mount flags can unlock significant performance without changing your hardware. Compare VPS providers on our comparison table to find hosts that let you customize your storage configuration.

Leave a Reply