Le disque dur de son serveur domestique ne s'arrête plus ! Comment optimiser le noyau pour accélérer la resynchronisation du cache LVM (dm-cache) par un facteur de 5 (de 2,5 Mo/s à 13,1 Mo/s)
Introduction: HDD stuck at 100% and making a terrible 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 sound 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 only 2.5 MB/s per second.
“Did one of my Docker containers go rogue?” “Is the HDD failing with read/write errors?”
I 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). By attacking the Linux I/O scheduler and LVM parameters, I successfully accelerated this “synchronization hell” that would otherwise take a full day (over 20 hours) to complete, achieving a 5x speedup (up to 13.1 MB/s).
I hope this serves as a reference for anyone experiencing similar issues where an “HDD array with SSD cache becomes 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