![]() |
VOOZH | about |
The SSD’s internal “garbage collecting” processes are responsible for erasing blocks and managing wear leveling. However, filesystems typically “delete” data by just marking it in their own records as space that is available again. They do not actually erase the data from the underlying storage, but may overwrite the area previously occupied by that data on subsequent writes.
This means that the SSD will typically not know that a page is no longer needed until it receives instructions from the filesystem to write to the same logical location at a later time. It cannot perform its garbage collection routines because it is never informed when data is deleted, just when the space previously reserved for it should now be used for other data.
The TRIM command propagates information about which data is no longer being used from the filesystem down to the SSD. This allows the device to perform its regular garbage collecting duties when idle, in order to ensure that there are zeroed pages ready to handle new writes. The SSD can shuffle data ahead of time, clean up stale pages, and generally keep the device in good working condition.
Performing TRIM on every deletion can be costly, however, and can have a negative impact on the performance of the drive. Configuring periodic TRIM gives the device bulk information about unneeded pages on a regular schedule instead of with each operation.
In this tutorial, you will learn how SSDs and TRIM work and then enable periodic TRIM on a variety of Linux distributions.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
DigitalOcean Block Storage allows you to attach additional storage volumes to your Droplets quickly and easily. Block Storage volumes function like regular block devices when attached to your servers, allowing you to use familiar tools to manage your storage needs. In this series, we will introduce basic Linux storage terminology, cover how to create and manage Block Storage volumes, and how to perform a variety of administrative tasks to keep your volumes running smoothly.
Browse Series: 2 tutorials
Former Senior Technical Writer at DigitalOcean, specializing in DevOps topics across multiple Linux distributions, including Ubuntu 18.04, 20.04, 22.04, as well as Debian 10 and 11.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Thanks for this tutorial! Never had a clue about this. Luckily I was running 16.04 so this was very easy to implement :)
Awesome Tutorial Thanks Mark
Well written :-) But can you elaborate on the discard feature of a device, which you can see using e.g. " lsblk -d -o name,DISC-GRAN,DISC-MAX,model"
What’s going on when a disk support discard?
And when you call the “fstrim -a” how does the disk know which block has been deleted, where is this information stored?
Great tutorial! Thank you.
One n00b question: Is there a way to test that this newer version of fstrim is actually working?
Super helpful. Statically compiling a newer fstrim is a great idea in certain edge cases where you can’t replace an antiquated OS.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.