Some Bits: Nelson's log

Proxmox disk wear

Does Proxmox 8.1 wear out my disks? Maybe. A fairly idle Proxmox server is writing 40GB a day and I think most of that is wasteful. My SSD will last 10+ years at that rate but maybe I can make it better. So I looked more closely and in the end concluded most of the write activity is related to the guest operating systems I’m running, not Proxmox itself. Proxmox alone is writing about 50KB/second of data.

Wear is a concern with consumer SSDs; even a high end Samsung 980 Pro is rated for only 600 TB of writes for a 1TB drive. (Enterprise SSDs are 3x that or more.) It should be enough for an ordinary home server not doing a whole lot but a misbehaving system could make things bad. There’s several kinds of misbehavior with different solutions.

The Proxmox subreddit is full of posts like this or this with people noting high wear on their SSDs. The discussions are muddled. Someone says “it’s a problem!” and several people immediately respond “not a problem for me”. Inevitably someone says “buy an expensive enterprise SSD you fool”. Out of that noise I’ve found some pattern: Proxmox can write a lot of data.

Measuring disk writes

How do you measure the problem? The easy way is to use the Proxmox GUI to look at “Disks” for the host; the last column is “Wearout”. That’s current state of use and comes from SMART data. (Or should; my cheap N100 server doesn’t have the info.) Take a look, you may be surprised! I haven’t run Proxmox long enough to really know, my old Ubuntu server was running for a year+ without Proxmox and is only at 1%.

You can also get more insight by setting up system metrics on Proxmox. That has it export data to an Influx database when you can then visualize with Grafana.

More hands-on, you can measure write load with various Linux IO tools. Good old iostat is one way, ZFS has its own version of that:

$ zpool iostat

capacity operations bandwidth
pool alloc free read write read write
---------- ----- ----- ----- ----- ----- -----
rpool 72.4G 1.74T 28 21 1.91M 727K

That tells me the ZFS pool on my SSD has averaged 727KB a second since the last reboot. Watching zpool iostat 60 for minute-by-minute reports it’s averaging about 500KB a second on both Proxmox hosts I have. That’s about 40GB a day or 16TB a year. That still gives me decades before the device wears out. But it seems pretty wasteful, what’s doing all that writing?

Another tool is iotop or pidstat -d which show per-process IO stats. fatrace is also interesting, it gives you a log of file access.

Guest system write load

A simple explanation for the writes is the VMs or Containers running as guests on Proxmox may be writing to (virtual) disk, doing real work or writing logs. That’s got nothing much to do with Proxmox.

Proxmox has a nice tool for understanding disk I/O in guests; a graph right there in the GUI.

On my BTRFS machine the graph above tells me the Ubuntu VM guest is writing about 200KB/s. Another graph shows only one of the three containers has sustained writes, it says about 15KB/s. FWIW if I stop just the containers the iostat on the hypervisor goes from 500KB/s to 350KB/s, suggesting the three containers are writing 150KB/s between them. If I then also shut down the VM it saves another 300KB/s. The numbers don’t quite add up but I’m willing to believe that most of the disk writes are things the guest systems are doing. The Proxmox host itself is only writing 50–100KB/s, a small enough number I can ignore it.

On the ZFS machine where I measured 500KB/s writes, the VM itself says it was writing about 100KB/s. That still leaves 80% of the write load coming from the Proxmox hypervisor and maybe a mystery. Or maybe not, like I said the numbers don’t always add up.

Write amplification

A systems problem, write amplification is when writing (say) 1GB of application data results in a lot more than 1GB of write operations on the disk. Pathological systems can have 100x write amplification, a real problem. There’s various possible causes for this, I don’t really understand it.

On a simple test using iostat and dd I verified that writing 100MB of data from /dev/urandom in a VM resulted in about 100MB actually being written to the ZFS pool. Careful how you test; if something’s compressing the actual write might be less than the application data.

I think write amplification is a particular concern with ZFS depending on what RAID configuration you choose. Particularly if you run ZFS in a guest on a virtual disk backed by a physical ZFS pool. The VM itself can also be relevant, see zoned-storage for instance in QEMU. One drawback of virtualization is you’re so far removed from the hardware that things can get out of hand quickly.

Proxmox itself

On to the real question, does Proxmox itself write too much to disk? I’ve got a measurement that it’s only 50–100KB/s. Still, why that much? The Internet is full of advice on how to make Proxmox write less; this guide is particularly good.

The suggestion I was hoping would work is stopping services related to clusters if you only have a single node. The usual suggestion is to stop four: pve-ha-crm, pve-ha-lrm, pvesr.timer, and corosync. Of those only the two pve-ha services were even running. Stopping them didn’t really change the write load.

Another suggestion is to install log2ram and use that for /var/log instead of the real disk. Which could be a nice solution but you lose your logs in case of a hard system crash. Along those lines I’ve used tmpfs before for temporary directories. It helps as long as no one is expecting /tmp to be big.

Another recommendation is to change the vm.swappiness property; apparently Proxmox preemptively starts swapping things to disk when RAM is just 60% full. I don’t have any swap configured so that’s not going to change anything. Memory thrashing to swap could very quickly overwhelm an SSD.

File access details on Proxmox

I tried using iotop, pidstat -d, and fatrace to better understand what was going on. iotop is hard to read or possibly useless because ZFS or BTRFS themselves dominate the reports. pidstat -d is similar to iotop but different packaging. fatrace is a neat tool, and new to me. It shows which files are being written over the whole system. Sadly not how much are being written. Also it can’t show writes to a ZFS volume like my VM is stored on, since those aren’t files.

Shutting down all guests I’m left with proxmox itself. I’m still at 50KB/s or so, it’s hard to be sure exactly. fatrace tells me disk writes go to the following places:

  • pmxcfs: /var/lib/pve-cluster/config.db-wal. This is the PVE High Availability stuff I talked about turning off earlier. Even with those two services turned off there’s still some writes there.
  • pvescheduler: /var/lib/pve-manager/pve-replication-state.lck. Something related to a replication feature I’m not using. There are instructions on how to turn this off but they don’t seem to apply to modern versions.
  • pvestatd: /var/log/pve/tasks/.active.lock. Presumably an important part of PVE’s task scheduler.
  • pvestatd: /var/lib/rrdcached/journal/rrd.journal... Guessing this is the database for the nice graphs in the UI.
  • tailscaled: /var/lib/tailscale/tailscaled.log?.txt. Tailscale writes data briefly to its own log before pushing it to journalctl and removing it. This discussion has some notes about moving or disabling it. It seems to be about 30 writes a minute, 100 bytes at a time.

So that’s that. Most of my writes are coming from guests. Proxmox could be a little more efficienct, so could tailscaled, but what it’s doing now is not awful. And the amount of writes isn’t significant enough to worry about my disk lifespan.