Urgent.News

What's breaking now, across thousands of outlets.

Tech

Flush a bcache writeback cache in seconds, not days

Before a reboot, a kernel upgrade or pulling an SSD out of a bcache setup, you want the dirty data on the backing disk. Switching to writethrough looks like the way to get it there, and on a busy disk it can leave the backlog draining at 4 KiB per second. Setting writeback_percent to 0 makes it drain at full speed: 950 MiB across three devices drained within 20 seconds for us. I'm Väinämöinen,…

To prepare a bcache disk for a reboot, upgrade, or maintenance, you should flush the writeback cache. Setting writethrough mode instead of writeback allows writes to go directly to the backing disk without staying in the cache. However, writethrough does not automatically flush dirty data already in the cache. The kernel's should_writeback() function determines if a write remains dirty or not.

In writethrough mode, no new writes become dirty. The dirty data that existed before the switch remains in the SSD, leaving via the background writeback thread. This thread is limited to a 4 KiB/s copy rate by the writeback_rate controller. By default, writeback_percent is set to 10, causing the controller to aim for a target of 10% of the cache size.

The controller's rate is clamped between a minimum of 8 and a maximum based on the target. When the cache is less than the target, the proportional term becomes negative, dropping the rate to the floor of 4 KiB/s. This behavior means that a large amount of dirty data can take a long time to drain, potentially hours or even days.

To speed up the drain, set writeback_percent to 0. This change stops the rate update and allows the writeback thread to copy dirty data as fast as the backing disk can handle it. In practice, a 950 MiB backlog of dirty data on three bcache devices drained to zero in just 20 seconds after setting writeback_percent to 0. To monitor the drain, check the writeback_rate_debug value in sysfs for current rate, dirty data amount, target, and calculation terms.

After the maintenance, restore the original cache_mode and writeback_percent values. If the SSD is being removed from the bcache stack, detach the device first, as detachment also drains the cache without the rate limit.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

The Purdue Model in Practice Versus on Paper

The Purdue model is a layered way to describe an industrial network, from the process at Level 0 up to the enterprise at Level 5. Real plants blur it.

  • Purdue model categorizes industrial networks into five levels, from process to enterprise.
  • Implementing the Purdue model and IEC 62443 guidelines secures industrial networks against attacks.

More from Friday 13 November →