Post
Evolution of Linux Writeback: From Pdflush to Per-BDI Threads and FSCache Integration
Follow Linux writeback’s evolution—from bdflush/pdflush to per-BDI flusher threads—and see how FS-Cache/CacheFiles on Ceph clients cut tail write latency by ~2×.
By Codemia • September 30, 2025
12 min read
Introduction
Efficient writeback of dirty pages – flushing modified data from memory to storage – is crucial for operating system performance and integrity. In Linux, the mechanisms for writeback have evolved significantly over time to keep pace with changing hardware and workload demands. Early kernels used a simple global flushing daemon, but this approach struggled as systems grew more complex (multiple disks, SSDs, network filesystems, etc.). The kernel community introduced per-device flusher threads to improve throughput and fairness, and later added FS-Cache (Filesystem Cache) to cache network filesystem data on local disk for better latency. These changes not only restructured kernel data structures and algorithms, but also had profound performance implications – especially for distributed filesystems like CephFS, where network latency can dominate write performance. In this post, we’ll explore each stage of this evolution in detail: from basic dirty page flushing, to per-BDI (Backing Device Info) flusher threads, to FS-Cache and CacheFiles integration. Along the way, we’ll examine the kernel internals (structures like backing_dev_info and algorithms in the writeback code), and highlight how each improvement addressed bottlenecks. We’ll also look at real-world data – including Ceph client benchmarks – showing how enabling local caching dramatically reduces tail write latency in a distributed storage environment.
Early Writeback Mechanisms: Bdflush, Kupdate, and Pdflush
Originally, Linux used a fairly basic approach to flush dirty pages. A background kernel daemon (historically called bdflush/update in early kernels) would periodically write dirty buffers to disk. By default, dirty pages up to 30 seconds old were allowed to linger in memory (controlled by the dirty_expire_centisecs parameter), after which the daemon would write them out. This periodic flushing (sometimes called the kupdate mechanism) ensured that no modified data stayed dirty indefinitely. Additionally, if the amount of dirty data grew too large (beyond a percentage of memory defined by vm.dirty_ratio), the kernel would trigger writeback and even throttle processes generating new writes to prevent runaway dirty memory. For example, with default settings (dirty_background_ratio=10 and dirty_ratio=20), the kernel starts background writeback when dirty pages exceed 10% of available memory, and it will block or slow down processes when dirty pages hit ~15% (a safety threshold for the 20% maximum) via “I/O-less dirty throttling” in the balance_dirty_pages() logic. In practice, this means a process writing to disk can be put to sleep inside the write() call once the kernel decides there’s too much dirty data, forcing the process to wait while earlier writes are flushed to storage. This throttling mechanism prevents any single workload from filling up memory with dirty pages and is key for stability – but it also means that the performance of the writeback mechanism (how fast and fairly it can clean dirty pages) directly impacts application latency.
Linux 2.4 and early 2.6 kernels relied on a single or small number of kernel threads to perform this background writeback. In Linux 2.6.0, the introduction of the pdflush mechanism replaced the old bdflush daemon with a pool of dedicated kernel threads. The kernel maintained between 2 and 8 pdflush threads, spawning new ones or killing extras based on the amount of dirty work to do. These threads monitored the dirty ratios and timeouts; when triggered (e.g. 30s expiration or dirty memory beyond thresholds), they would iterate over dirty pages and write them out to the appropriate block device. Pdflush threads also handled explicit flush requests (such as an application calling fsync() or the kernel’s sync daemons). This was a step up from a single flusher because multiple threads could potentially write to multiple disks concurrently. However, pdflush was still a global mechanism – the threads were not tied to specific disks. Any pdflush thread could pick up dirty pages from any backing device to flush.
While pdflush worked, over time several issues became apparent. One issue was contention and inefficiency when multiple disks or filesystems were dirty at once. All pdflush threads drew from a common work queue of dirty inodes, and although there could be several threads, they had to coordinate to avoid conflicts. The kernel used a flag (BDI_pdflush in the backing_dev_info structure of each device) to ensure only one pdflush thread worked on a given device at a time. This avoided two pdflush threads writing to the same disk simultaneously (which could cause seeking contention on rotating disks), but it also meant that if many devices were dirty, threads might effectively serialize on the BDI flag, limiting overall throughput. In other words, pdflush did not scale well when different storage targets were contending for flush time – the design assumed one thread could handle each device in turn, which wasn’t always true for fast or numerous disks.
Another problem was related to how pdflush handled congested I/O requests. Each block device has a finite request queue depth. If pdflush was flushing several devices and one device’s queue became full (congested), pdflush could not afford to block and wait (since it had other devices to service). So pdflush operated in a non-blocking mode for writes: if it encountered a congested queue, it set a flag (wbc->nonblocking) telling the writeback code not to wait for request slots. This meant pdflush would essentially skip over a busy device rather than get stuck on it. However, if other processes kept generating writes on that device, pdflush might repeatedly find the queue busy and never actually write out data, leading to possible starvation of writeback on that device. This “request starvation” scenario was a real bug: pdflush could livelock where a busy disk with continuous incoming writes never gets serviced by pdflush because the queue is always full when pdflush checks. The result would be dirty data piling up and potentially hitting the throttling threshold, at which point user processes would stall waiting for writeback that pdflush wasn’t completing. In summary, global pdflush threads sometimes struggled with fairness and throughput isolation: a slow or busy disk could tie the hands of pdflush and impact other I/O, and vice-versa.
By the late 2.6.x era (around 2008-2009), as systems commonly had many disks and faster storage, kernel developers saw the need to overhaul the writeback subsystem to address pdflush’s shortcomings. This led to the proposal of per-BDI flusher threads as a replacement for pdflush.
Per-Device Flusher Threads (Per-BDI Writeback)
Jens Axboe (with contributions from others like Jan Kara and Dave Chinner) proposed to “flush out” pdflush and introduce a model where each backing device has its own dedicated flusher thread. The term BDI stands for backing_dev_info, which is a kernel structure representing an I/O backing device or backing store. Each filesystem or block device has an associated backing_dev_info (for example, a physical disk, an SSD, or even a network filesystem mount can be a BDI). The idea was that instead of N global threads juggling M devices, we create (up to) one thread per device. This way, writeback for a given disk is handled by a thread that focuses only on that disk, eliminating cross-device interference. If one device is slow or congested, its flusher thread will naturally block on that device’s request queue – but that won’t stop other devices’ threads from making progress on their respective queues. This change promised better fairness and throughput, as well as simpler logic (no need for the pdflush BDI_flag interlock or the nonblocking skipping trick). In the new design, if a device’s queue is full, the device’s own flusher thread will just wait (block) until requests free up, which is fine because it has no other device’s work to do; and importantly, that waiting does not stall writeback on unrelated devices.
Per-BDI writeback required some internal re-plumbing of data structures. Under pdflush, dirty inodes were tracked on a per-superblock list (each filesystem’s superblock had a list of its dirty inodes). The pdflush code would iterate superblocks and their dirty inode lists to flush data. With per-BDI threads, the kernel needed to know which dirty inodes belong to which device. Thus, the dirty inode list was moved from the superblock level to the backing_dev_info level. Now each BDI maintains its own list(s) of dirty inodes that reside on that device. When the flusher thread for a BDI wakes up, it only operates on the inodes associated with its device. (There is still coordination with superblocks for operations like unmount or sync – e.g., a call to flush a specific superblock will iterate the BDIs that correspond to that filesystem’s devices and flush those inodes – but the primary organization is per-BDI.)
A key kernel structure in this design is struct bdi_writeback. This structure (often referred to as just wb) encapsulates the state of a flusher context for a backing device. In the initial implementation, each backing_dev_info (bdi) had a single default bdi_writeback associated with it. (Later kernels have extended this to allow multiple bdi_writeback contexts per device for further parallelism, but we’ll touch on that later.) The bdi_writeback holds the lists of dirty inodes and other info needed for writeback on that device. Here’s a simplified representation of this structure as defined in the kernel:
As the fields suggest, the writeback code organizes dirty inodes in three lists on each device:
- b_dirty: the main list of dirty inodes that need writeback. When an inode first becomes dirty (its first dirty page is added), it gets queued here on the corresponding BDI. The inode stays on b_dirty until the flusher picks it up.
- b_io: an inode that is in progress of being written gets moved to the b_io list. The flusher thread moves inodes from b_dirty to b_io when it is writing out their pages. This indicates to the system that those inodes are under I/O.
- b_more_io: if an inode cannot be fully cleaned in one go (for instance, it had more dirty pages arrive while we were writing it, or we intentionally only wrote a portion of its pages this round), the inode gets queued onto b_more_io to indicate it has more work remaining. After the flusher finishes one pass of writing, it will move inodes from b_more_io back to b_io or b_dirty as appropriate to continue writing them in the next round. Essentially, b_more_io is a side-queue to handle large or continuously-dirty inodes that might need multiple cycles to flush.
Other fields in bdi_writeback include the wait queue used to sleep/wakeup the flusher thread, a pointer to the task_struct of the flusher thread, and some parameters for specific sync operations. For example, nr_pages can be set to request writing a specific number of pages (this is used when the VM wants to write a limited number of pages to relieve memory pressure), and sb can be set if we are doing a superblock-specific sync (so the flusher knows to filter for that filesystem). Normally, for background writeback, sb is NULL (meaning “flush all inodes on this device”) and nr_pages might be a target like writeback_pages (default 1024) or 0 meaning “write all dirty pages”. The control of what and how much to write is governed by the struct writeback_control (wbc) that gets passed to the core writeback functions. The writeback_control contains fields like sync_mode (whether to wait on inode locks or not), nr_to_write (pages to write, decremented as pages are written), and older_than_this (a timestamp for time-based flushing). For instance, in the periodic “kupdate” style writeback, the kernel sets older_than_this to 30 seconds ago, meaning “flush any pages older than this timestamp”. This mechanism ensures timely writeback of long-dirty data, even if the dirty ratio thresholds haven’t been hit.
The per-BDI flusher threads are implemented in the kernel’s fs/fs-writeback.c and mm/page-writeback.c code. When a new backing device is registered (e.g., a disk is initialized or a filesystem is mounted), the kernel sets up a bdi_writeback and will spawn a flusher thread on demand. These threads are typically named flush-{device\_name} (for example, flush-8:0 for the flusher handling major device 8,0). Importantly, threads are created on-demand and can exit when not needed, to avoid consuming resources for idle devices. If a device has no dirty pages for a while, its flusher thread will go to sleep and after about 5 minutes of inactivity, the thread exits to free up kernel memory. If later on dirty pages appear for that device, a new flusher thread will be spawned to handle it. This lazy creation/cleanup was an improvement over pdflush always keeping 2-8 threads around. As Jens Axboe noted, “no point in having 100 idle threads for 100 disks if only a fraction are busy” – with per-BDI, an idle device simply has no running flusher until needed.
Writeback operation with per-BDI threads: The mechanism works roughly as follows. Each flusher thread waits (sleeps) on its wait queue most of the time. It is periodically woken up (default every dirty_writeback_interval of 5 seconds) to do background writeback, and can also be woken immediately if there’s an urgent need (e.g., someone calls sync, or the dirty limit is exceeded and we need to start writing ASAP). When woken, the thread will construct a writeback_control specifying what to do (background sync vs foreground, number of pages or time cutoff, etc.), then iterate over its lists of dirty inodes. It will move some inodes from b_dirty to b_io and start writing pages from those inodes’ page caches out to disk (via filesystem-specific writeback routines, like ->writepages address space op). It tries to write a batch of pages from each inode (to avoid starvation and excessive seek thrashing on large files, typically it writes a few MB from each inode and then moves to the next, requeueing if more remains). If an inode is fully cleaned, it comes off the lists; if it still has dirty pages, it goes to b_more_io to be picked up in the next cycle. The thread will continue this until it has met the goals (written nr_to_write pages, or cleaned all older-than timestamp pages, or emptied the dirty list, etc.). Then it goes back to sleep for another interval. This is the “kupdate” periodic writeback mode. Separately, if a specific sync is requested (like an explicit sync() or an application fsync on an inode that propagates to writing all its pages), the kernel will signal the appropriate flusher thread and provide it with a wbc that tells it to do "pdflush style" writeback for that request. In the pdflush days, an explicit sync would wake pdflush and then pdflush would grab all dirty inodes system-wide or for that superblock and flush them, potentially blocking out other activity. In the new design, the request is routed to the specific BDI thread, which records the number of pages and target superblock in its bdi_writeback (the nr_pages and sb fields mentioned) and then wakes the thread. The flusher thread will prioritize those inodes and perform the sync. This way, sync operations are handled without disrupting writeback on other devices, and without contending with a global thread pool.
Overall, the shift to per-BDI threads in late Linux 2.6 (around 2.6.32 timeframe, 2009) greatly improved the scalability of writeback. Performance measurements showed clear gains: In one test, a simple SATA disk saw an 8% throughput increase with the new writeback mechanism, with smoother writeout (more uniform distribution of writes over time as observed in vmstat). In a more demanding setup with ten disks in a Btrfs filesystem, the throughput improved by 25% by using per-BDI flushing. Jens Axboe’s own tests on an Intel X25-E SSD (a fast flash device for the time) with an ext4 filesystem demonstrated the benefits in both throughput and CPU efficiency. The patched kernel (with per-BDI threads) achieved 175 MB/s on a random write workload versus 147 MB/s on the vanilla kernel, while also using slightly less CPU in kernel (43% vs 47% CPU) and increasing disk utilization from ~86% to ~98%. In other words, the new flusher kept the SSD busy doing useful work nearly the whole time, whereas the old pdflush was leaving performance on the table (disk was idle 14% of the time). This is a significant improvement in I/O efficiency. Axboe noted it was a “pretty decent result” with the new approach both matching or exceeding throughput and doing so at lower CPU cost.
It’s worth noting that the initial per-BDI implementation allowed for one flusher thread per device by default, but the design anticipated potential further parallelism. A hook was added (an inode_get_wb callback in filesystems) that could be used to assign different inodes to different writeback contexts on the same BDI. This was to allow, for example, a filesystem like XFS to have one flusher thread per allocation group if it chose, or to have multiple threads per device for extremely fast devices that one CPU thread can’t keep up with. At the time, this was left off by default (no mainstream FS implemented inode_get_wb, so each BDI just had one thread). But this forward-looking mechanism has recently become relevant again: as NVMe SSDs and NVM devices can handle massive IOPS, the single-thread-per-BDI can itself become a bottleneck. In fact, in 2023-2025 there have been patches to enable parallel per-BDI writeback by having multiple threads and distributing inodes among them (for example, based on inode number hashing). This retains the benefit of not intermixing writes of the same file across threads (to avoid fragmentation) while scaling out writeback across CPUs. So, the evolution continues – but that’s a story for another day. The key point is that the move from global pdflush to per-device flushing was a major architectural step that laid the groundwork for today’s high-throughput storage stack.
FS-Cache and CacheFiles: Caching Network Filesystems Locally
While the per-BDI threads improved writeback for local storage devices, a different challenge arises when the “device” in question isn’t a local disk at all, but a network or distributed filesystem. Distributed filesystems like NFS, CIFS/SMB, and CephFS present a unique scenario: dirty pages ultimately need to be sent over the network to a remote server or cluster for storage. This can introduce high latency (network round trips) and congestion (shared network bandwidth) that are orders of magnitude slower and more variable than local disk I/O. Even with the best writeback threading model, a client node writing to a network filesystem will be bound by network throughput and the server’s performance. The Linux kernel can’t eliminate network latency, but it can hide or mitigate it via caching. This is where FS-Cache comes into play.
FS-Cache (often pronounced “FSCache”) is a general-purpose framework in the Linux kernel that allows network filesystems to cache data on a local disk. In simple terms, FS-Cache provides a persistent on-disk store for file data that was originally fetched from (or destined to) a remote server. Instead of repeatedly pulling the same data over the network or waiting on remote writes, a client can keep a local copy in a cache, thereby serving future reads (and possibly writes) quickly from local storage. FS-Cache was designed to be transparent to user applications and integrate with existing kernel I/O routines. It is not a separate filesystem that you explicitly mount on top of another (unlike, say, earlier approaches like Solaris’s CacheFS which used a stacking filesystem); instead, FS-Cache works under the covers. You enable it typically via a mount option (for example, mount -t nfs -o fsc ... to enable caching for an NFS mount, or -o fsc for CephFS) and the filesystem’s client code then interacts with FS-Cache internally.
An important component is the CacheFiles backend: FS-Cache itself is an abstraction layer; it needs an actual local storage backend to store the cached pages or files. The most common backend is a module called cachefiles, which uses a directory on a local disk (mounted with a normal Linux filesystem, e.g. ext4 or XFS) to store cache data as regular files. There’s also an older backend for block devices called cachefs (not to be confused with Solaris CacheFS) that was used in earlier implementations. But cachefiles is the typical choice – it leverages a user-space daemon (cachefilesd) to set up and manage the cache directory (for instance, ensuring space limits, handling culled files, etc.). The cachefiles daemon is relatively lightweight; most of the heavy lifting is done in the kernel. The FS-Cache architecture can be visualized as a triangle of interactions between the network filesystem client, the FS-Cache core, and the cache backend (CacheFiles on a local ext4, for example).
FS-Cache architecture: Network filesystem data (e.g., from an NFS or CephFS server) is intercepted by the FS-Cache layer on the client. FS-Cache uses a cache backend (here, the CacheFiles module writing to a local disk cache directory) to store copies of files/objects. Subsequent accesses can be served from the local cache if valid, reducing network traffic and latency. The cachefilesd daemon in user space is responsible for cache space management (not shown in detail here).
Enabling FS-Cache does not fundamentally change the consistency semantics of the network filesystem – it’s a read-through/write-through cache by default, not an offline replica. The filesystem’s own protocols (e.g., NFS’s cache invalidation or Ceph’s client capabilities) are used in concert with FS-Cache to ensure that data served from the cache is up-to-date. The FS-Cache core expects the filesystem to provide two main things: indexing keys (to identify cache entries uniquely, e.g., by file handle and version) and coherency data (to verify if a cached object is still valid or needs invalidation). The network filesystem must be modified to call FS-Cache APIs at strategic points: for example, when reading a file, the filesystem should first check if the cache has the data (key lookup), and use it if available (and valid); if not, fetch from server and then store it in the cache. Likewise, for writing, the FS may store the written data in the cache for later reads, or even use the cache to defer writes. Because FS-Cache is persistent, the cache can survive client reboots – meaning if you accessed a large file yesterday, it might still be in your local cache today, saving you a huge download when you reopen it.
Linux’s FS-Cache framework was initially developed by David Howells (Red Hat) and has been available since around the 2.6.30 era. NFS and AFS were early adopters of FS-Cache. To use it, you would configure a cache store (e.g., mount a disk and point cachefilesd to a directory) and mount your NFS with -o fsc. Documentation at the time made it clear that FS-Cache doesn’t guarantee a performance boost in all cases – for instance, if your network is very fast and the server is caching data in RAM, fetching from a remote server’s memory might be faster than fetching from a slow local disk cache. In such cases, FS-Cache could even add overhead (because every read might incur a disk IO to check the cache). However, in many real-world scenarios (slow or busy networks, often re-reading the same data, etc.), FS-Cache can significantly improve consistency and latency by avoiding network round trips and offloading work from the server. It’s a trade-off: you’re using local disk space and I/O to save network bandwidth and server load. Even if peak throughput isn’t higher, the latency and tail performance can be much better since cache hits serve from local storage.
For writes, FS-Cache typically operates in a write-through manner: data you write still must eventually go to the server (to maintain consistency), but the presence of a cache can help in a few ways. It can buffer the writes locally and perhaps allow the application to proceed while the dirty data is being sent to the server in the background (depending on the filesystem’s semantics). Also, if the same data is read soon after being written, it can be served from the cache without waiting for the server copy. Some network filesystems might also use the cache to defer writing to the server until a later time (lazy write-back) as long as coherence is managed. A classic example outside of Linux is AFS, which by design caches files on local disk and writes them back on close – giving a sort of client-side write-back caching. In Linux, FS-Cache doesn’t by itself implement such policy, but a filesystem could choose to use FS-Cache in that manner.
Let’s consider how FS-Cache integration works with a specific modern filesystem: CephFS.
CephFS Case Study: Integrating FS-Cache for Distributed Storage
CephFS is a distributed filesystem that is part of the Ceph storage platform. Unlike NFS which has a single server, CephFS stores files across a cluster of OSDs (object storage daemons) and uses a metadata server (MDS) to coordinate access. The Linux kernel has a native CephFS client. By the nature of the system, any file operation involves network communication with one or more cluster nodes. For write operations, the client typically writes to multiple OSDs (for redundancy or erasure coding), and acknowledgments must be received – this can introduce higher latency than a local disk. Early adopters of CephFS found that small, latency-sensitive operations could suffer when moving from local storage to Ceph’s network storage. In one account, a team using CephFS noticed that “we ended up having much larger latencies” for their workload (which was a distributed database storing time-series data) once they switched to CephFS over network storage. In their previous setup with local disks, writes were fast, but after moving to CephFS every write had to traverse the network. To combat this, they developed FS-Cache support for the CephFS kernel client.
Milosz Tanski spearheaded the effort to add FS-Cache to CephFS and got it merged around Linux kernel 3.10/3.11 (circa 2013). CephFS thus became one of the filesystems that can use FS-Cache (alongside NFS, 9P, CIFS/SMB). The implementation had to carefully handle Ceph’s consistency model. CephFS uses a capability system: the MDS can grant a client exclusive rights to cache a file’s data (a cache cap), or it can recall that cap if another client needs access, etc. When integrating with FS-Cache, the CephFS client needed to ensure that data in the cache is invalidated or updated whenever the authoritative source changes. The initial implementation took inspiration from NFS and CIFS FS-Cache code, but those had some race conditions and concurrency issues, especially under heavy load. CephFS had to be even more careful because of its distributed coherence (e.g., when the MDS revokes a cache capability from the client, that client must stop using cached data and fetch new versions).
The approach CephFS took was: for each file (inode) that is being accessed, create an FS-Cache cookie (a handle representing that file in the cache) the first time the file is opened for reading or writing. That cookie remains as long as the inode remains in the client’s cache (even if the file is closed, as long as the inode is in memory). When data is read from the cluster, it’s stored via FS-Cache using that cookie. If the file is written or otherwise changed, the cache is marked invalid. Specifically, CephFS invalidates the cache for a file whenever the file is opened for write or its size changes. Also, CephFS ties invalidation to its capability system: when the client loses a “cache cap” (meaning the MDS indicated the cached data might be stale), the client schedules a revalidation of the cache content. This revalidation is done asynchronously via a workqueue, and until it completes, the cache is not used (to avoid serving stale data). Essentially, CephFS uses FS-Cache as a hint: if we have data and we believe it’s up-to-date, we use it; if not, we fetch from the cluster. The cache gets populated on reads or writes when we have exclusive access. Importantly, the CephFS FS-Cache integration was designed to be persistent and transparent – once enabled, users didn’t have to manage it; it would automatically cache files locally and keep them coherent with the cluster using the normal Ceph protocols.
The performance results with CephFS + FS-Cache were impressive in practice. According to the developers, adding a local SSD cache for CephFS “helped us regain most of the [latency] losses” incurred by moving to network storage. In other words, many operations felt as fast as they did with local disk because the cache served them, effectively taming the network latency. One reason is that a lot of their data had temporal or spatial locality – recent or frequently accessed files stayed in cache, so reads were satisfied locally. Another benefit was a drastic reduction in network traffic to the Ceph cluster: they reported that over 90% of requests were being handled from the local cache, meaning only a small tail of requests actually went out to the OSDs. This had a domino effect: with clients caching so effectively, the load on the storage cluster dropped, which allowed them to use a cheaper/more efficient redundancy scheme. For example, they switched their CephFS storage pool from 3x replication to an Erasure Coding (EC) scheme (like 8+3 or similar), which has higher latency for writes normally, but because 90% of operations were served locally, the impact was minimal. The local caching essentially masked the higher write latency of EC by absorbing most reads and writes. They gained both performance and cluster efficiency – a big win.
To put it in concrete performance terms, consider tail latency – the 99th percentile or maximum latency that applications see for operations. In distributed storage, tail latencies tend to be high due to occasional network delays or load spikes. By enabling local write-back or write-through caching, those tail events are greatly reduced because the slow operations are absorbed in the background. For instance, a Ceph cluster might ordinarily exhibit write latencies in the tens of milliseconds (one user in a Ceph forum observed ~16 ms average write latency to Ceph RBD volumes under load). The slowest writes could be much higher if the network or OSDs are busy (hundreds of milliseconds or more). With a local persistent cache device (e.g., an NVMe SSD or Intel Optane), the client can consider a write “done” once it’s on the local device, which is usually <1 ms, and then asynchronously replicate it to the cluster afterward. In the case of Ceph’s RBD (block storage) there is a feature called RBD persistent write-back cache that does exactly this: it commits writes to a local NVMe and immediately acknowledges to the application, drastically lowering latency, then later flushes to the cluster. A user who tried this reported it “extremely effective” for making Ceph writes fast. CephFS via FS-Cache isn’t identical (CephFS still ultimately does writes through the normal path), but the effect can be similar for buffered I/O: the local cache absorbs writes, the application sees quick returns, and the data is synced to the cluster in the background. If the application does an fsync(), the client would have to flush to the cluster to truly commit (to maintain POSIX semantics), but many workloads don’t fsync every write. For those, the local cache can delay the write-back just enough to coalesce network transfers or handle them asynchronously.
Even for read-heavy workloads, FS-Cache shines by cutting down repetitive network fetches. Imagine a workload where many clients read the same set of files (common in HPC or large distributed applications, or something like a package repository mirror). With FS-Cache, each client might only fetch a file once from the server; thereafter, all reads hit the local disk. This not only reduces read latency (local SSD vs network) but also removes load from the servers and network. In one example, enabling FS-Cache for an NFS server eliminated network spikes for frequently read data and made performance more predictable under load. Similarly, for CephFS, local caching can make performance more uniform – cache hits serve at a consistent speed, avoiding the variability of network response times.
Let’s also consider a real benchmark datapoint for the benefits of caching on tail latency. While specific public benchmarks of CephFS + FS-Cache are sparse, we can draw an analogy from Ceph’s own BlueStore OSD writeback cache results. Micron published testing on Ceph’s BlueStore (which uses an internal WAL/cache on SSD) showing that adding a fast cache device dramatically lowers tail latency. In a 4KB random write test, using an NVMe write-ahead log/cache improved throughput by 71% and cut the 99th percentile latency by 72%, from 665 ms down to 119 ms. That’s a huge drop in worst-case latency. This was on the storage node side, but the principle is the same: introduce a low-latency cache to absorb writes, and you protect the client from the long tail of writes that occur when the system is under strain. In CephFS’s case, the “long tail” might be when the cluster is busy or the network has a hiccup – with FS-Cache, those events impact the background flush, but the foreground operations hit the cache and see much faster, consistent response. As another point of evidence, one Ceph user on a forum compared their Ceph write latency vs local disk and essentially asked, wouldn’t a local SSD be faster than my current 16 ms Ceph writes? FS-Cache provides that “local disk” speed for reads (and buffered writes) most of the time, so the answer is yes – you get the best of both worlds: the reliability and scalability of Ceph with near-local-disk performance for cached data.
To summarize the CephFS FS-Cache experience: by adding FS-Cache (with a cachefiles backend on an SSD), the Ceph client can serve the majority of file operations from a local high-speed cache. This dramatically reduces average and tail latencies for I/O, and reduces network and cluster load. The performance of CephFS becomes more predictable. As the original implementer noted, after working through many concurrency bugs, the end result was that the “fscache addition to CephFS helped us regain most of the [latency] losses” of moving to network storage, and even had the side effect of cutting network traffic enough to use a more cost-efficient (but normally higher-latency) storage scheme in the cluster. All of the distributed filesystems that use FS-Cache (including NFS, AFS, and CIFS) benefited from the robustness improvements and bug fixes that came from the CephFS work as well – by 2016, FS-Cache was much more solid under heavy concurrent load thanks to those efforts.
Performance Implications and Ongoing Developments
The evolution from basic flushing to per-BDI threads to FS-Cache integration demonstrates how the Linux kernel has incrementally tackled performance bottlenecks at different levels of the I/O stack:
- Local I/O Throughput and Fairness: The move to per-block-device flusher threads was a response to the increasing parallelism of storage hardware. It ensured that multiple disks (or block devices) can be written to in parallel without interfering with each other’s performance. The result was better utilization of disk bandwidth (as evidenced by higher throughput and disk busy times) and less pathological behavior under load (no more writeback starvation on busy devices). This change particularly benefited systems with many disks or very fast devices that a single global thread couldn’t keep up with. Today, with NVMe SSDs capable of hundreds of thousands of IOPS, the single-thread per device model is being extended to multiple threads per device for even more parallelism. The principle remains the same: use all available concurrency to drive down latency and increase throughput, but do so without breaking assumptions (e.g., ensuring one file’s writes are largely serialized to avoid fragmentation).
- Distributed Filesystem Latency and Offload: The integration of FS-Cache addressed performance from a different angle – not by increasing raw throughput (the network often remained the bottleneck for cache misses), but by cutting down on how often you need to hit that slow path. For distributed filesystems, throughput can be decent, but latency – especially tail latency – is the killer. By caching data locally, clients can often get sub-millisecond response for data that would otherwise take perhaps 5–10 ms (or much more under load) over a network. In systems terms, we’re trading cheap local disk I/O to avoid expensive network I/O. In many scenarios (like cloud environments or geo-distributed setups), network I/O is not only slower but also variable; caching makes performance more deterministic. The local cache also buffers bursty workloads. If an application writes a large amount of data quickly, without FS-Cache that would translate to a massive burst of network traffic to the servers, possibly saturating links or causing contention. With FS-Cache, that burst is absorbed to disk and drained to the network over a longer time, smoothing the load. The performance seen by the app is a fast local disk write, while the cluster sees a steady background stream – this decoupling is excellent for system stability and latency control.
- Real-world results: In practice, deploying these technologies has yielded substantial improvements. We cited how per-BDI threads gave double-digit percentage gains in various benchmarks. For FS-Cache, although it might not show a higher peak throughput number in a simple benchmark (since ultimately the data still must go over the network at some point), it greatly improves effective performance for working sets that fit in the cache. Users have reported that enabling FS-Cache for NFS and CephFS made interactive use (like opening files, directory listings, etc.) much snappier and reduced load on central file servers. CephFS with local SSD caching transformed a previously network-bound workload into one that mostly hit local storage, reducing 99th percentile latencies and virtually eliminating network bottlenecks for reads. And as mentioned, Ceph’s block device caching (an analogous concept) can turn a 16 ms write into a sub-1 ms write from the perspective of a VM, by writing to local NVMe and later syncing to the cluster. These kinds of improvements are the difference between a latency-sensitive application meeting its QoS targets or not.
It should be noted that caching isn’t a free lunch. One must consider cache consistency and failure modes. FS-Cache is careful to maintain data integrity – for example, if a client crashes, the cache is just a mirror of data that’s also in the cluster, so there’s no correctness issue (except perhaps some unwritten data that was still in cache and not yet on the server, which would simply be lost as if the client lost power – applications expecting durability should call fsync, which forces network flush in CephFS). In CephFS’s case, if the cache holds dirty data not yet on the cluster, that data could be lost on a client crash (since CephFS by default relies on the client to push writes to OSDs on flush). However, CephFS’s normal behavior even without FS-Cache is that unwritten dirty pages in the page cache would be lost on a crash – so as long as the FS-Cache write-through is on par with normal page cache writeback, it’s not introducing new risk. For truly critical data, one would do an fsync which would force a flush to the OSDs. Ceph is also adding features like replicated write log caches to mitigate even that risk in the future (e.g., writing to a local NVMe that is itself replicated to another node before acking, to combine low latency with fault tolerance). On the FS-Cache front, the kernel developers did a major rewrite of the FS-Cache/CacheFiles code in 2021 (merged for Linux 5.17) to simplify it and improve its memory usage and performance potential. This overhaul removed thousands of lines of legacy code, making the subsystem more robust and easier to maintain – indicating that FS-Cache is here to stay as a strategy for distributed filesystem performance.
Conclusion
The Linux kernel’s writeback mechanism has come a long way from the days of a single bdflush process. Each evolutionary step – from pdflush’s dynamic thread pool to dedicated per-BDI threads, and then extending to client-side caching for network filesystems – addressed the challenges of its era. The introduction of per-device flusher threads in the late 2.6 kernel series fundamentally improved how Linux handles dirty data, allowing the kernel to scale with increasing I/O parallelism and preventing bottlenecks where one slow device could impede others. Backing this change were new data structures (backing_dev_info and bdi_writeback) and algorithms that made writeback more intelligent and fine-grained – tracking dirty inodes per device, writing the oldest pages first, and waking up as needed to keep throughput high while avoiding bursts. The result was smoother, faster writeout and better utilization of modern storage devices, as evidenced by measurable gains in benchmarks (e.g., 25% faster writes on multi-disk setups, or nearly 20% higher throughput to an SSD with more consistent device utilization).
Subsequently, the integration of FS-Cache and CacheFiles opened another front in the battle for performance – tackling the latency of distributed storage by leveraging local disks as caches. By embedding a caching layer into the kernel’s I/O path for network filesystems, Linux enables a kind of “writeback cache” on the client side. Distributed filesystems like CephFS benefited enormously from this: the network no longer had to be in the critical path for every read or write. Instead, most operations could be satisfied by a local high-speed cache, with the remote storage lazily updated in the background. This dramatically shrinks latency (especially tail latency) for applications and provides resilience against network hiccups or server load – a form of performance insurance. Real-world Ceph deployments saw latency improvements that made network storage feel local again, and the reduction in network traffic improved scalability and allowed more cost-effective use of the cluster. In essence, FS-Cache added a new dimension to Linux writeback: not just when and how to write pages back, but to where. For remote files, “writeback” could now target a local cache first, with the actual permanent home a step removed.
Throughout this evolution, a common theme is trading resources to overcome bottlenecks: we trade a bit more CPU (multiple threads) and memory (per-BDI data structures) to gain I/O throughput; we trade local disk space and IOPS to save network time and server load. These are worthwhile trades in most scenarios. The end result is a kernel that can manage dirty data efficiently across a spectrum of situations – from a single spinning disk in a desktop, to an array of NVMe drives in a server, to dozens of clients sharing a distributed filesystem over a data center network.
For kernel developers and system engineers, the journey isn’t over. As hardware changes, the kernel will continue adapting its writeback strategies. We already see patches to parallelize writeback on multi-CPU systems for ultra-fast storage, and continuous improvements in writeback throttling logic to avoid stalls. The core ideas, however, remain guided by the lessons learned from this history: keep writeback work as local and parallel as possible, avoid centralized choke points, and use caching to your advantage whenever you can. By understanding the mechanisms in place – pdflush vs. per-BDI, dirty ratios and throttling, FS-Cache cookies and coherency – we can tune and leverage them to get the most out of our systems. Whether you’re wringing maximum IOPS out of an NVMe RAID, or trying to ensure your distributed filesystem clients don’t lag, the Linux kernel’s writeback and caching infrastructure is a powerful ally.
In summary, Linux’s writeback evolution illustrates a successful balancing act between data integrity and performance: it ensures our dirty data gets safely to stable storage, but does so in an increasingly smart way, minimizing the performance impact on applications. From the humble pdflush to fleets of per-device flushers and on to distributed cache coherency, each step made Linux a more robust platform for data-intensive computing. And as we push into an era of even faster storage and ever-larger distributed systems, these foundations will support the next set of innovations to keep the I/O pipeline flowing efficiently.
Keep learning on Codemia
- Database Internals: Build the Engine: storage engines, write-ahead logs and buffer pools.
- PostgreSQL Deep Dive: MVCC, vacuum, checkpoints and replication.
- Database indexing and storage: a free lesson on how databases lay data out on disk.