Trimming can trigger internal garbage collection on some firmware and causing some performance impact when one leasts expects it, so enabling TRIM via the discard mount flag may be suboptimal. It is therefore better to batch up discards and run fstrim periodically when a machine is idle in terms of minimising performance impact (this is also more power efficient too).
For the curious, how much is being discarded when one runs fstrim? Fortunately the kernel has a tracepoint added to ext4_trim_extent and this enables one to observe the block device, allocation group, starting block of the free extent in the allocation group and number of blocks to TRIM.
With debugfs mounted one can easily observe this using:
echo 1 | sudo tee /sys/kernel/debug/tracing/events/ext4/ext4_trim_extent/enable
sudo cat /sys/kernel/debug/tracing/trace_pipe | grep ext4_trim_extent
then invoke fstrim from another terminal and one will observe:
fstrim-4909 [003] .... 6585.463841: ext4_trim_extent: dev 8,3 group 1378, start 2633, len 829
fstrim-4909 [003] .... 6585.474926: ext4_trim_extent: dev 8,3 group 1378, start 3463, len 187
fstrim-4909 [003] .... 6585.484014: ext4_trim_extent: dev 8,3 group 1378, start 3652, len 474
...
The deeper question is therefore how frequently should run fstrim? It is hard to say exactly, since it is use-case dependant. However, anecdotal evidence seems to suggest running fstrim either daily or weekly.
No comments:
Post a Comment