After a few years with a lot of writing and deletion of data, I noticed my server starting to have problems even at light writing and reading at the same time, on the same disk.
Looking at the hard drive activity light on the case, I could see it being mostly just constantly on, and the disk sounding like it was pretty busy. Not having done a defrag in years, it was not the first thing I thought of, instead I tried to do some simple benchmarking, and started to investigate if it was actually a SMR drive I had, despite the model number claiming it would be a CMR. Writing data to the drive was pretty evenly slow, and same was reading, where an SMR would start out initially fast, then drop down in write operations.
After pulling more of my remaining hairs out, I finally thought of fragmented data, and I started looking into how that would work on Unraid. Sadly no plugins has been made, so it is all done manually… Luckily it is still pretty simple.
With the way the array in Unraid is made, defragmentation isn’t done on the entire array as one big drive, it is done on each disk instead.
To get the status of Disk 1 in the array, open the console and put in
xfs_db -r -c frag /dev/md1
It will then return a fragmentation factor
actual 422638, ideal 1630, fragmentation factor 99.61%
well… That number sounds a bit high…
To start the defragmentation I used the User Scripts plugin, and created a script in it called defrag.
Inside this script I got this
xfs_fsr -v /dev/md1
To be able to start the defrag and close the browser, I pressed the “Run in background” button.
All I had to do now, was to be patient and wait for it to finish… Almost 48 hours later with the activity led constantly on, it turned off again.
Let’s check the status!
actual 35069, ideal 34866, fragmentation factor 0.58%
That is quite a difference, but that is just a number, did it do anything?
And yes! It looks like it actually helped. I can now write to the drive, while also reading from it. Write speed’s has also gone up to almost be able to fully utilize the 1 gigabit network connection again.