I have a new samsung ssd in my new notebook. I tuned up everything to avoid writings in the disk (firefox profiles and /var/log
in memory), I'm using a ext4
fs with relatime
and I use fstrim
once a day to TRIM my ssd.
I monitor disk load with iostat -dhm
. Before running fstrim
the command iostat
shown
Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sda
4.97 0.05 0.59 1856 20924
after trimming /home
# fstrim -v /home
/home: 100.2 GiB (107555401728 bytes) trimmed
ìostat
shows
Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sda
5.91 0.05 3.51 1859 123498
MB_wrtn
increased 102574 MB
.
Does that mean fstrim
is writing 102574 MB = 100.2 GB
to my disk ?
Trim is supposed to "mark" the pages that do not contain valid data, not writing them.
I guess iostat
saw the operation made by fstrim
as writing (even if it is not a writing). What do you think? Is there a better way to monitor my disk?
Note: Using iotop
is not an answer, because it doesn't show the amount of data of processes that were killed. Thus, iotop
measurement
is inexact.
Best Answer
Yes, it means exactly that.
fstrim
essentially looks at every single block of your block device and decides if the block is being used by the filesystem (that is, contains important data):When it's done, the amount of trimmed blocks should always be equivalent to the free space on the filesystem.
fstrim
TRIMs each free block every time you run it, regardless if it already has been TRIMmed in the past, so it won't become faster if you run it more often.The kernel probably considers the TRIM command like a write command, so every executed TRIM command counts as a 4k write command.
"Marking" blocks as trimmed is equivalent to "writing" them, because their contents change. If you'd accidentally TRIM the wrong block, you would lose data - just as writing zeros to the wrong block causes you to lose data.