ext4 vs XFS vs Btrfs on a VPS: Benchmarking Filesystems for Database and Web Workloads

Filesystem choice on a VPS is usually decided by folklore — “XFS for databases, ext4 for everything else, Btrfs if you want snapshots” — and the folklore was formed on bare metal with battery-backed RAID controllers. A KVM VPS presents a virtio block device backed by shared NVMe, so the latency distribution, the queue depth you can actually reach and the cost of metadata operations look nothing like a physical disk. The numbers below come from a repeatable test matrix you can run on your own instance in about twenty minutes, and what they show is that the winner depends on whether your workload is fsync-bound, metadata-bound or write-concurrency-bound.

Use the same block size and queue depth across filesystems or the comparison is meaningless. All tests here use fio with a 4 KiB random mix and a 16 KiB sequential stream, each run three times with the first discarded. If you have not yet confirmed the raw device performance of your instance, start with the fio and iostat baseline described in benchmarking VPS disk I/O, then apply this comparison on top of it.

Build the test plan before you format anything

Three workloads cover the realistic cases for a web or database VPS: 4 KiB random reads at queue depth 32 (database index access), 4 KiB random writes with fsync (commit-heavy OLTP), and 16 KiB sequential writes (logs, backups, uploads). Add one metadata test because it separates the three far more sharply than throughput tests do.

# mount-point agnostic: point $mnt at each test filesystem in turn
mnt=/mnt/test
sudo fio --name=rr4k --directory=$mnt --rw=randread --bs=4k --iodepth=32 \
  --numjobs=4 --size=1G --runtime=60 --time_based --group_reporting
sudo fio --name=rw4k-fsync --directory=$mnt --rw=randwrite --bs=4k \
  --fdatasync=1 --iodepth=1 --size=512M --runtime=60 --time_based
sudo fio --name=sw16k --directory=$mnt --rw=write --bs=16k \
  --iodepth=16 --size=2G --runtime=60 --time_based
# metadata: 20k small files in a nested tree
sudo time tar -xf /tmp/linux-6.6.tar.xz -C $mnt
sudo time find $mnt/linux-6.6 -type f -delete

Format and mount options that change the result

Defaults are not neutral. ext4 defaults to 4096-byte blocks and reserves 5% of the device for root; XFS picks a stripe geometry based on the device; Btrfs defaults to single-profile metadata on a single device, which is fine for a VPS but worth stating explicitly so the result is not accidentally a RAID-profile difference.

# ext4: drop root reserve to 1% on a data-only volume, keep 5% on /
sudo mkfs.ext4 -m 1 -E lazy_itable_init=0 /dev/vdb
# XFS: 4k block size, single-device, no stripe assumptions
sudo mkfs.xfs -f -b size=4096 -d agcount=4 /dev/vdb
# Btrfs: mixed single profile, no compression for a fair raw test
sudo mkfs.btrfs -f -d single -m single /dev/vdb

# mount options used for each run
# ext4:  defaults,noatime,nodiratime
# xfs:   defaults,noatime,nodiratime,logbsize=256k
# btrfs: defaults,noatime,space_cache=v2,compress=zstd:1  (second pass)

Results: three filesystems, three different winners

Representative figures from a 4 vCPU / 8 GB KVM instance with NVMe-backed virtio and a 300 MB/s sustained write cap. Treat the ratios as the useful signal, not the absolute numbers — your provider’s overcommit will move all three in the same direction.

Test              ext4              XFS               Btrfs (zstd:1)
----------------  ----------------  ----------------  ----------------
4k randread QD32  ~48k IOPS         ~52k IOPS         ~44k IOPS
4k randwrite+fsync ~2.9k IOPS       ~3.4k IOPS        ~1.9k IOPS
16k seq write     ~330 MB/s         ~345 MB/s         ~250 MB/s raw
untar 20k files   ~38 s             ~27 s             ~52 s
delete 20k files  ~4.1 s            ~1.3 s            ~6.8 s
snapshot create   n/a               n/a               ~0.2 s
noatime gain      +3-6%             +3-6%             +8-12%

XFS wins fsync-bound and metadata-heavy work, and the margin is not marginal: 3.4k versus 2.9k fsync IOPS is the difference between MariaDB committing comfortably at 200 TPS and hitting innodb_log_waits. Its advantage in the delete test comes from delayed logging and the B-tree structure handling range frees cheaply. ext4 remains the best default for a general web host because it is predictable, well-understood by every tool you will install, and has the lowest worst case on small disks.

Btrfs on a single virtual disk is the interesting case. compress=zstd:1 costs 20–30% sequential throughput but buys 1.6× effective capacity on text-heavy data and, more importantly for a VPS, cuts the bytes written to the device — which matters if your provider bills on write amplification or throttles on it. Snapshots are near-instant, which makes it the pragmatic choice for a container host or a web server where you want a rollback point before every deploy.

Where the differences actually come from

Two mechanisms explain most of the table. First, journaling style: XFS commits metadata to a log with delayed writes and lets data land out-of-order, while ext4’s default data=ordered forces data blocks out before their metadata commit — safer in a crash, slower under fsync pressure. Second, copy-on-write: Btrfs never overwrites in place, so a random 4 KiB write becomes a new extent plus new metadata plus, eventually, a free-space-tree update. On a disk that charges you per 4 KiB I/O, that is a real multiplier.

You can see the second effect directly in the write amplification counters: grep -w write_bytes /sys/block/vdb/stat before and after a fixed workload. On our Btrfs run the block layer saw roughly 1.8× the bytes the application wrote, against 1.05× for ext4 and 1.1× for XFS. If your provider meters writes, that ratio belongs in the cost calculation, not just the performance table.

A decision table, not a religion

Map your workload to the row that fits and stop optimising filesystem choice — the remaining gains are in mount options and I/O scheduling.

Workload                          Pick      Why
--------------------------------  --------  --------------------------------
WordPress / nginx, 1 disk         ext4      predictable, tooling-friendly
MariaDB / PostgreSQL, fsync-heavy XFS       +15-20% fsync IOPS, cheap deletes
Container host, deploys to roll   Btrfs     snapshots, zstd cuts write bytes
Bulk uploads, media               XFS       sequential + large extents
< 20 GB disk, lots of small files ext4      lowest overhead at small scale

Re-run this on your own instance

The published numbers on any blog — including these — are a starting hypothesis. Providers differ by an order of magnitude in write caps and in how aggressively they throttle burst credits, and a filesystem choice that wins by 18% on an unthrottled host can lose once you hit the ceiling. Run the four fio jobs above, keep the raw JSON output, and compare against the same tests after a month. If your instance is throttling during the sequential test, that is a provisioning signal rather than a filesystem one, and it is worth reviewing the VPS storage and performance options before you spend more time tuning mounts.

Leave a Reply