Skip to main content
RunBook Academy

CephLXXI · Client PerformanceClient Performance

Choosing a cache mode

Advanced⏱ ~17 minrbdqemu

What you'll learn

  • Describe what each cache mode guarantees
  • Match cache mode to workload durability needs
  • Understand the interaction with guest flushes
  • Configure the mode correctly

Prerequisites

None — start here.

Verified against Ceph Tentacle 20.2.x · Ceph Squid 19.2.x (supported previous) · cephadm matches the verified Ceph release · podman 4.x · csi-rbd and csi-cephfs current · RBD / CephFS / RGW current (matches Ceph release) · Linux kernel 5.15+ (5.10 minimum) · Ubuntu 24.04 LTS (Ceph host baseline) · Debian 12 (Bookworm) (Ceph host baseline) · Rocky Linux / RHEL / AlmaLinux 9.x (Ceph host baseline) · Proxmox VE 9.x (cross-course integration) · Kubernetes 1.31+ (cross-course integration) · 2026-08-18

Not yet marked complete on this device.

Why this matters in production

Cache mode determines what survives a client crash. Choosing writeback for a workload that assumes writethrough is a data loss configuration that performs well until it does not.

The modes

ModeWrite acknowledged whenSurvives client crash
nonethe cluster has committedeverything acknowledged
writethroughthe cluster has committedeverything acknowledged
writebackthe client cache holds itonly what was flushed
rbd config image set rbd-vms/vm-disk-1 rbd_cache true
rbd config image set rbd-vms/vm-disk-1 rbd_cache_max_dirty 0    # writethrough
rbd config image set rbd-vms/vm-disk-1 rbd_cache_max_dirty 25165824  # writeback

Setting rbd_cache_max_dirty to 0 makes the cache writethrough: reads are cached, writes go straight through.

In QEMU

-drive file=rbd:rbd-vms/vm-disk-1,cache=writeback
-drive file=rbd:rbd-vms/vm-disk-1,cache=writethrough
-drive file=rbd:rbd-vms/vm-disk-1,cache=none
QEMU settinglibrbd behaviour
cache=noneRBD cache disabled
cache=writethroughRBD cache enabled, no dirty data
cache=writebackRBD cache enabled with dirty data
cache=unsafewriteback and flushes ignored — never in production

cache=unsafe discards flush requests, which means even a guest doing everything correctly loses data on a crash. It exists for throwaway builds and has no production use.

Guest flushes and why they matter

guest filesystem journal commit
  → issues fsync
  → QEMU issues flush to librbd
  → librbd writes dirty cache to the cluster
  → acknowledges
  → guest journal is durable

Writeback caching is safe provided this chain works end to end. It breaks when:

BreakConsequence
cache=unsafeflushes discarded
The guest driver does not issue flushesdirty data accumulates unflushed
A barrier is disabled in the guestfilesystem ordering guarantees lost
# in the guest, verify flushes are reaching the device
mount | grep -o 'nobarrier'      # should return nothing

Choosing

WorkloadMode
VM root disk, ordinary OSwriteback
Database with its own WALnone or writethrough
Build or scratch volumewriteback
Anything with strict durability requirementsnone
Guest whose flush behaviour is unknownwritethrough until flush

Quiz

Knowledge check · 4 questions

  1. Q1. Why can `cache=unsafe` lose data even for a guest that issues fsync correctly?

  2. Q2. Setting `rbd_cache_max_dirty` to 0 makes the cache behave as writethrough.

  3. Q3. Choose cache modes for a mixed VM fleet.

    A fleet includes modern Linux VMs, several legacy VMs with old paravirtual drivers, and database VMs. All currently use cache=writeback.

  4. Q4. What chain must work for writeback caching to be safe?

Passing score: 75%. Answers are checked in this browser.

Production discipline

Match cache mode to the workload’s own durability mechanism: writeback for guests with verified flush discipline, writethrough or none for databases that manage their own WAL. Never use cache=unsafe on anything whose data matters — it defeats a correctly-behaving guest’s fsync.

Cross-course references

  • Kubernetes: volume mount options affecting durability need the same per-workload choice
  • Linux: write barriers and disk write cache present exactly this trade