HIRO GEAR
自作インフラ Linux Raspberry Pi ストレージ

¿El disco duro de tu servidor en casa no para? Cómo aceleré la resincronización del caché LVM (dm-cache) en un factor de 5 mediante ajustes del kernel (de 2.5 MB/s a 13.1 MB/s)

¿El disco duro de tu servidor en casa no para? Cómo aceleré la resincronización del caché LVM (dm-cache) en un factor de 5 mediante ajustes del kernel (de 2.5 MB/s a 13.1 MB/s)

Introduction: HDD Stuck at 100% and Making a Horrible Noise After Reboot…

I have been running a server (Raspberry Pi 5) at home 24/7. 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 for hours without stopping.

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 disks (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 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 takes over a full day (more than 20 hours)” by attacking Linux I/O schedulers and LVM parameters, achieving a 5x speedup (up to 13.1 MB/s).

I hope this helps anyone else experiencing the same issue 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 ["