FSTrim Trimming the Same Amount Multiple Times in a Row

I was running fstrim on a couple of old drives in anticipation of installing them in an even older RAID controller that doesn't support the trim command.[0] To do this, I formatted the entire drive as ext4, mounted it, then ran fstrim -v /mnt/temp to discard all of the unused blocks. I did this using a USB-SATA adapter, and what I noticed was that after running fstrim the adapter activity light was still blinking like crazy. I was curious if fstrim was still running, even though the command had completed already.

Short answer: Yes, it was. Long answer: While investigating this, I discovered that running fstrim twice in a row on the drive claimed to discard the exact same number of blocks. That's not what I expected[1], so I looked deeper. I found some discussions about this, but nowhere did I see anything that explained what I was seeing. Hence this post.

In short, I needed to leave the drive connected and mounted for a while after running fstrim. In a few minutes the activity light quit blinking and when I ran fstrim again it reported 0 blocks discarded, which is what I expected. It seems that there was still some trim activity going on in the background, even after the command was complete. I suppose in most cases you wouldn't care about this because you'd be trimming a permanently installed drive, but in my situation it was important to know that the full trim process would take a few minutes. Note that I was able to unmount the drive, even though the trim was still in progress. Trim doesn't seem to block unmounting.

I don't know how many people will be doing something like this, but I know there are other people with home labs made of older hardware so it's plausible that someone would. If you are, keep this in mind and make sure that fstrim is reporting 0 blocks discarded before you disconnect the drive.

0: To avoid performance degradation in this situation, under-allocate the drives in the RAID controller. Leaving 10-20% of the SSD unused will allow the built-in controller to manage the blocks reasonably well.
1: Apparently XFS always discards all empty blocks, so if you're using XFS this might be normal behavior. It's not for ext4.