This guide focuses on optimizing mdadm
software RAID performance during resync, rebuild, or reshape operations on AlmaLinux / CloudLinux 9, or any recent systemd-based Linux OS.
๐ง 1. Boost Resync Speeds via sysctl
Applies to: RAID 1, 5, 6, 10
Raise the minimum sync speed (default: 1000 KB/s):
echo 50000 > /proc/sys/dev/raid/speed_limit_min
echo 200000 > /proc/sys/dev/raid/speed_limit_max
To persist across reboots:
cat <<EOF > /etc/sysctl.d/99-raid-speed.conf
dev.raid.speed_limit_min = 50000
dev.raid.speed_limit_max = 200000
EOF
sysctl --system
๐ฆ 2. Increase Disk Readahead
Applies to: RAID 1, 5, 6, 10
Improves sequential disk I/O during rebuild.
for dev in /dev/md*; do
blockdev --setra 65536 "$dev"
done
Repeat for physical disks (e.g., /dev/sd[a-z]
).
To persist:
- Add to
/etc/rc.d/rc.local
or a custom systemd service.
๐ 3. Tune stripe_cache_size
(RAID 5/6 only)
Applies to: RAID 5, 6
(Not used by RAID 1 or 10)
echo 16384 > /sys/block/md0/md/stripe_cache_size
- Acceptable range: 17โ32768
- Each unit = 1 page (~4 KB)
- Larger values = faster rebuilds but more RAM
Check current value:
cat /sys/block/md0/md/stripe_cache_size
Persist with a systemd override or /etc/rc.local
.
๐ง 4. Enable Bitmap Indexing
Applies to: RAID 1, 5, 6, 10
Bitmaps accelerate resync after unclean shutdowns by tracking changed blocks.
mdadm --grow --bitmap=internal /dev/md0
To disable:
mdadm --grow --bitmap=none /dev/md0
๐งต 5. Tune Resync Threads (Optional)
Applies to: RAID 5, 6, 10 (not RAID 1)
You can increase the number of active threads used during resync:
echo 8 > /sys/block/md0/md/group_thread_cnt
Default is typically 1
. Use 4โ16
depending on CPU cores and load.
โ 6. Disable NCQ on Disks (May Help with SATA Drives)
Applies to: All RAID types
for d in /sys/block/sd*/device/queue_depth; do
echo 1 > "$d"
done
Do not apply on SSDs or enterprise NVMe drives unless advised by the vendor.
๐ 7. Monitor Rebuild or Resync Progress
cat /proc/mdstat
Example output:
md0 : active raid5 sdc1[2] sdb1[1] sda1[0]
976630464 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]
[>....................] resync = 4.0% (39208960/976630464) finish=90.5min speed=172999K/sec
๐งฐ 8. Per-RAID-Level Summary
RAID Level | Relevant Tweaks |
---|---|
RAID 1 | speed_limit_* , bitmap, readahead, optional NCQ disable |
RAID 5 | All of above + stripe_cache_size , optional thread tuning |
RAID 6 | Same as RAID 5; may benefit more from thread tuning due to dual parity overhead |
RAID 10 | speed_limit_* , bitmap, readahead, optional thread tuning (depends on layout), rarely needs stripe cache |
๐ก 9. Optional: Auto-apply with Systemd (e.g. md-raid-boost.service
)
Create /etc/systemd/system/md-raid-boost.service
:
[Unit]
Description=RAID Speedup Tweaks
After=local-fs.target
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/md-raid-boost.sh
RemainAfterExit=true
[Install]
WantedBy=multi-user.target
Then create /usr/local/sbin/md-raid-boost.sh
:
#!/bin/bash
sysctl -w dev.raid.speed_limit_min=50000
sysctl -w dev.raid.speed_limit_max=200000
for dev in /dev/md*; do
blockdev --setra 65536 "$dev"
[ -f /sys/block/$(basename $dev)/md/stripe_cache_size ] && echo 16384 > /sys/block/$(basename $dev)/md/stripe_cache_size
done
for d in /sys/block/sd*/device/queue_depth; do
echo 1 > "$d"
done
Make executable:
chmod +x /usr/local/sbin/md-raid-boost.sh
systemctl enable --now md-raid-boost