Linux offers multiple block-level caching solutions that sit between fast storage (NVMe SSDs) and slow storage (HDDs) to accelerate I/O without requiring expensive all-flash arrays. These kernel-level caching technologies intercept block I/O at the device-mapper layer, transparently caching frequently accessed data on faster media.
In this guide, we compare three Linux storage caching technologies: dm-writecache for SSD write acceleration, bcache for full read/write caching, and FlashCache for enterprise-grade write-back caching. We cover installation, configuration, performance characteristics, and when each technology is the right choice.
What Is Block-Level Storage Caching?
Block-level caching operates below the filesystem layer, caching raw disk blocks rather than file-level data. This means:
- Filesystem agnostic: Works with ext4, XFS, Btrfs, ZFS, or any other filesystem.
- Transparent to applications: No application changes required.
- Hardware independent: Works with any block device (NVMe, SATA SSD, HDD, iSCSI, LVM volumes).
- Kernel integrated: Zero-copy data paths through the Linux kernel’s I/O stack.
Block caching differs from filesystem-level caching (ZFS ARC, Btrfs page cache) and application-level caching (Redis, Memcached). It sits at the lowest level of the storage stack, providing universal acceleration.
dm-writecache: SSD Write Acceleration
dm-writecache is a device-mapper target introduced in Linux kernel 4.12 that uses a fast device (SSD/NVMe) as a write cache for a slow device (HDD). It is designed specifically for write-intensive workloads where sequential writes to HDDs are the bottleneck.
Architecture
dm-writecache operates in write-back mode only — it does not cache reads. Write operations land on the fast SSD first, then are flushed to the HDD in the background by a dedicated kernel thread. This design provides:
- Write coalescing: Multiple small writes are combined into larger sequential writes on the HDD.
- Reduced write amplification: The HDD receives fewer, larger I/O operations.
- Predictable latency: Writes complete at SSD speed, decoupling application latency from HDD performance.
Installation
dm-writecache is built into the Linux kernel (since 4.12). No compilation is needed:
| |
Configuration
| |
Docker Compose for Testing
| |
| |
Performance Tuning
| |
When to Use dm-writecache
dm-writecache excels for write-heavy workloads where the HDD is the bottleneck:
- Database write-ahead logs (WAL) on HDD with SSD cache
- Log aggregation systems writing to HDD
- Video surveillance recording to HDD with SSD buffer
- CI/CD build artifact storage
It is NOT suitable for read-heavy workloads since it does not cache reads. For those scenarios, consider bcache instead.
bcache: Full Read/Write Block Caching
bcache is a Linux kernel block cache layer (merged in kernel 3.10) that uses a fast SSD to cache both reads and writes for a slow backing device. It supports write-through, write-back, and write-around modes.
Architecture
bcache registers a caching device (SSD) and attaches one or more backing devices (HDDs) to it. The SSD can cache multiple backing devices simultaneously, making it cost-effective for multi-disk servers.
| |
Installation
bcache is built into the Linux kernel (since 3.10). Install userspace tools:
| |
Configuration
| |
Docker Compose Setup
| |
| |
Cache Mode Comparison
| Mode | Description | Use Case |
|---|---|---|
writethrough | Writes go to both cache and backing device | Safety-first; no data loss on SSD failure |
writeback | Writes go to cache first, flushed later | Maximum write performance |
writearound | Writes bypass cache, go directly to backing device | Write-once workloads |
none | Caching disabled | Maintenance mode |
Monitoring
| |
FlashCache: Enterprise Write-Back Caching
FlashCache was developed by Facebook (now Meta) as a general-purpose write-back block cache for Linux. With 1,602 GitHub stars, it was widely used in production at Facebook for database acceleration. However, the project has seen minimal updates since 2021 and is considered legacy.
Architecture
FlashCache operates as a device-mapper target, similar to dm-writecache but with more features:
- Write-back caching with configurable dirty block limits
- SSD wear leveling and bad block management
- Cache persistence across reboots
- Configurable block sizes (512B to 64KB)
Installation
| |
Configuration
| |
Configuration Options
| |
Comparison Table
| Feature | dm-writecache | bcache | FlashCache |
|---|---|---|---|
| Kernel Integration | Built-in (4.12+) | Built-in (3.10+) | External module |
| Read Caching | No | Yes | Yes |
| Write Caching | Yes (write-back) | Yes (4 modes) | Yes (write-back) |
| Multiple Backing Devices | No (1:1) | Yes (1:N) | No (1:1) |
| Active Development | Yes (kernel mainline) | Yes (kernel mainline) | No (last update 2021) |
| SSD Wear Leveling | No | No | Yes |
| Cache Persistence | Yes | Yes | Yes |
| Production Stability | High (mainline) | High (mainline) | Moderate (legacy) |
| Best For | Write-heavy workloads | General caching | Legacy enterprise deployments |
Choosing the Right Caching Technology
| Workload | Recommended Technology |
|---|---|
| Database write-heavy (WAL, transaction logs) | dm-writecache |
| General server with mixed read/write | bcache (writethrough) |
| High-performance read caching | bcache (writeback) |
| Legacy enterprise FlashCache deployment | FlashCache (migration recommended) |
| Multi-HDD server with single SSD | bcache (1:N caching) |
Why Self-Host Storage Caching?
Deploying block-level caching on self-hosted infrastructure provides significant performance benefits without the cost premium of all-flash storage arrays. Cloud providers charge premium rates for high-IOPS storage tiers — implementing dm-writecache or bcache on self-hosted hardware can deliver 10-50x IOPS improvement for a fraction of the cost.
Cost efficiency: A 256GB NVMe SSD ($30) caching 4TB of HDD storage ($80) provides near-SSD performance for frequently accessed data at 25% of the all-flash cost. For multi-disk servers, bcache’s 1:N ratio (one SSD caching multiple HDDs) further improves the cost-per-GB ratio.
Performance predictability: Block-level caching operates below the filesystem layer, meaning it works with any filesystem and any application. Database performance, file server throughput, and backup speeds all benefit transparently without application-level changes.
Data control: Unlike cloud storage acceleration features (AWS EBS Provisioned IOPS, Azure Premium SSDs), self-hosted caching keeps data entirely on your hardware. For compliance-sensitive workloads, this eliminates data residency concerns associated with cloud-managed storage tiers.
For comprehensive storage management, see our storage replication guide covering DRBD, ZFS, and GlusterFS. If you’re managing XFS filesystems on cached devices, our XFS administration guide covers optimization and maintenance.
FAQ
Can dm-writecache improve read performance?
No. dm-writecache is a write-only cache. It accelerates write operations by landing them on the fast SSD first, but read operations always go directly to the backing HDD. If you need read acceleration, use bcache instead, which caches both reads and writes.
What happens if the SSD fails in a write-back configuration?
In write-back mode (dm-writecache, bcache writeback), unflushed data in the cache is lost if the SSD fails. For critical data, use writethrough mode (bcache only) which writes to both cache and backing device simultaneously. dm-writecache has no writethrough mode — if data safety is paramount, consider bcache or application-level replication.
Can I use bcache with NVMe drives?
Yes. bcache works with any block device, including NVMe. Use an NVMe drive as the cache device and SATA HDDs (or slower NVMe) as backing devices. The kernel automatically detects the device type and configures appropriate I/O scheduler parameters.
How large should the cache device be?
A general rule of thumb: the cache should be 10-25% of the backing device size for mixed workloads. For write-heavy workloads, 5-10% is sufficient since dm-writecache only caches writes. For read-heavy workloads with bcache, 20-30% improves hit rates. Monitor the cache hit ratio and adjust accordingly.
Is FlashCache still viable for new deployments?
FlashCache is considered legacy — its last significant update was in 2021. For new deployments, prefer dm-writecache (for write acceleration) or bcache (for read/write caching), both of which are actively maintained in the Linux kernel mainline. Existing FlashCache deployments should plan migration to bcache or dm-writecache.
How do I monitor cache hit rates?
For bcache: cat /sys/block/bcache0/bcache/stats_total/* shows hits, misses, and bypasses. For dm-writecache: dmsetup status mycache shows total blocks, blocks written, and write counts. For FlashCache: flashcache_stat /dev/mapper/cached_ssd provides detailed hit/miss statistics.
Can I resize a bcache cache device online?
Yes. bcache supports online cache device replacement. To resize, register a new larger SSD as a cache device, attach it to the backing device, and bcache will migrate cached data automatically. The old cache device can then be removed. This process is transparent to mounted filesystems.
Does block caching work with LVM?
Yes. You can place bcache or dm-writecache on top of LVM logical volumes. The typical stack is: physical disks → LVM → bcache/dm-writecache → filesystem. Alternatively, you can use bcache on physical devices and then create LVM volumes on top of the cached bcache device. Both configurations are supported.