I recently experienced a btrfs corruption event on my backup drive due to an untimely reboot from unattended upgrades. I then ran of btrfsck that caused the filesystem to be unrecoverable. I was able to mount the filesystem read only and copy all the data off but then I had to reformat the filesystem and start over. I found copying data to the drive was really slow. Its was a used SMR drive and basically without a refresh or trim the drive couldn’t know what sectors were free and was re-writing stale data.

(Drive could not even handle the 100 Mb/s the Pi 2 was capable of without stalling)
The same stalling pattern was observed when swapping out the Pi 2 for a Pi 4.

(Drive could sustain about 400 Mb/s or 50 MB/s)
I wrote a script to measure the read / write bandwidth of the drive every minute. Here’s what before and after looked like using the same hardware (drive attached to Raspberry Pi 4.

#!/bin/bash
# Script that tracks drive throughput of /dev/sda every minute
read rd1 wr1 <<< $(cat /proc/diskstats | grep "sda " | awk '{ print $6 " " $10 }')
#printf "1: Read $rd1 Wrote $wr1\n"
while sleep 1m
do
read rd2 wr2 <<< $(cat /proc/diskstats | grep "sda " | awk '{ print $6 " " $10 }')
#printf "2: Read $rd2 Wrote $wr2\n"
WrMBs=$(echo "scale=2; ($wr2 - $wr1) * 512 / 1048576 / 60" | bc)
RdMBs=$(echo "scale=2; ($rd2 - $rd1) * 512 / 1048576 / 60" | bc)
printf "Read MB/s: $RdMBs Write MB/s: $WrMBs\n"
rd1=$rd2
wr1=$wr2
done
Leave a Reply
You must be logged in to post a comment.