Home Server HDD Won't Stop! Accelerating LVM Cache Resync from Hell by 5x with Kernel Tuning (2.5MB/s → 13.1MB/s)
Introduction: HDD Stuck at 100% and Making a Horrible Noise After Reboot…
I have been running a server (Raspberry Pi 5) at home for 24/7 operation. One day, after a restart triggered by some minor incident, I encountered an issue where the external HDD access light was flashing violently, and the clicking/seeking noise continued non-stop for hours.
avg-cpu: %user %nice %system %iowait %steal %idle
2.10 0.00 0.64 6.37 0.00 90.89
Device r/s rkB/s w/s wkB/s w_await %util
sdb 1.19 74.89 29.74 2605.01 106.72 99.08%
sdc 1.62 58.79 29.86 2605.02 114.19 93.90%
Checking iostat revealed that the HDD usage (%util) for both drives (sdb and sdc) was stuck at 100%.
However, the write speed was a mere 2.5 MB/s per second.
“Did one of my Docker containers go rogue?” “Is the HDD failing and issuing read/write errors continuously?”
I was panicked, but further investigation revealed that the culprit was not an application, but rather a fail-safe feature built into Linux LVM cache (dm-cache). And I successfully optimized this “synchronization hell that would take a full day (over 20 hours)” by attacking Linux I/O schedulers and LVM parameters, achieving a 5x speedup (up to 13.1 MB/s).
I hope this serves as a reference for anyone experiencing “SSD-cached HDD arrays becoming extremely heavy after a reboot.”
1. Server Storage Configuration (Why did this happen?)
My home server uses the following tiered hybrid storage setup to balance performance and reliability:
graph TD
subgraph Physical ["Physical Drives (USB3.0 Connected)"]
SSD["/dev/sda (240GB SSD)"]
subgraph Cradle ["2-Bay External USB Dock"]
HDD1["/dev/sdb (2TB HDD)"]
HDD2["/dev/sdc (4TB HDD)"]
end
end
subgraph Logical ["LVM (vg_system)"]
C_POOL["SSD Cache Layer (dm-cache writeback)<br>40GB (/) + 160GB (/data)"]
RAID1["HDD RAID1 Mirroring Layer<br>sdb + sdc1"]
DB_SSD["/data/db_ssd (6GB, Pure SSD)<br>Dedicated area for MariaDB"]
end
subgraph Mounts ["