[Bglug] [kwlug-disc] Installing onto an SSD

Remi Gauvin remi at georgianit.com
Thu Mar 11 11:34:43 EST 2021

On 2021-03-11 10:56 a.m., Anthony Morassutti wrote:
> What is a "trim" command??

Unlike magnetic disks, Flash memory cells can not be overwritten on the
spot.  When a 4KB data block on an SSD is changed, the drive actually
copies the entire 512KB (I'm not sure if this is the real value, but
will use it here for illustration) block to a new cell.  The old Cell is
erased entirely for it to be re-used.

On traditional computer magnetic media, when a file is deleted, the data
blocks are not actually erased.  Eventually, the filesystem will simply
re-use that space if it needs it.

This causes 2 problems for SSD's.  In time, all the blocks on the SSD
will have Data in them, even if the filesystem considers it all empty
space.  In terms of performance, the more free blocks available, the
faster the SSD will be able to write data.  SSD write speed will
decrease dramatically once the drive is more than 50% full.  The 2nd
problem, since the drive is constantly moving that data to fresh cells
as part of it's wear leveling, copying stale data around will increase
wear unnecessarily.

The traditional method of really erasing data on a HDD (by replacing it
with 0's) will not alleviate these issues.  As far as the SSD is
concerned, all 0's is still data.

Very early in the transition to Flash media for computer storage, (ie,
SSD drives), the TRIM (or Discard) command  was added to the ATA
specification.  This is a special command that the Operatring system
sends to the SSD to tell it 'this data block is empty.'  From that point
forward, the SSD is no longer to preserve that data.

Linux has 3 ways to leverage this ability.

1. You can mount your filesystem with the 'discard' option in fstab.
This will instruct your filesystem to issue a TRIM command on the data
blocks whenever a file is deleted.  It was found, however, this can hurt
performance when the workload includes lots of file deletions.

2. There is an fstrim command.  Fstrim will instruct your filesystem to
TRIM all the unused space in one bulk request.  Most distros put this in
a cron.daily or cron.weekly job.

3.  *DANGEROUS*.  Linux has a blkdiscard command that will TRIM an
entire partition or disk.  This is a great command to use to blank a
drive for re-use, but note: it is not considered sufficient in the case
where a secure erase is required.

More information about the Group mailing list