©2015 - 2022 Chad’s Technoworks. Disclaimer and Terms of Use

Chad’s TechnoWorks My Journal On Technology


Windows

NOTE: Windows 7 and Windows 2008 R2 supports TRIM only on SATA SSD. Windows 8 and higher, expands TRIM support on PCIe only for NVMe flash Drives.



To check TRIM:


Open the Start Menu, type CMD

Right click the icon and Run as Administrator


Type: fsutil behavior query disabledeletenotify


DisableDeleteNotify = 1 (Windows TRIM commands are disabled)

DisableDeleteNotify = 0 (Windows TRIM commands are enabled)


To enable TRIM:


Open the Start Menu, type CMD

Right click the icon and Run as Administrator


Type: fsutil behavior set disabledeletenotify 0

 


Reference: Sean’s Windows 7 Optimization For SSDs



RedHat / Fedora


TRIM is supported starting at v6.5+


Reference:

RedHat 6 Solid State Disk Guideline


Edit /etc/fstab and add ,discard in addition to the defaults option.


Example:


[chad@lxnode5 ~]$ cat /etc/fstab


#

# /etc/fstab

# Created by anaconda on Sun Jul 19 02:29:21 2015

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

UUID=9895ecef-3973-46cf-848b-e9ae88698a14 /                       ext4    defaults,discard        1 1

UUID=bdb8463d-f2db-45c0-aa10-5c83e3eb81b7 /boot                   ext4    defaults,discard        1 2

UUID=5bca9cf4-a97c-4331-b777-cdff827e7522 swap                    swap    defaults,discard        0 0

tmpfs                   /dev/shm                tmpfs   defaults        0 0

devpts                  /dev/pts                devpts  gid=5,mode=620  0 0

sysfs                   /sys                    sysfs   defaults        0 0

proc                    /proc                   proc    defaults        0 0

[chad@lxnode5 ~]$



Blog

SSD AND FLASHDRIVE TRIM

Chad’s Blog November 2015


Recently, I have been involved on projects related to Big Data covering Hadoop and NoSQL implementations. It has come to my attention when one of the NoSQL vendors - Couchbase - suggested to turn on the TRIM function in Linux for the internal SSDs as they claim it benefits the write speed of Couchbase server. Although the comment is just in passing and majority of our System Engineers had ignored this statement since we are using Flash Arrays, the Engineer in me has made me to investigate the TRIM function.

So, here we go...

 

Basic SSD Write operation

An SSD (Solid State Drive) is comprised of Flash Memory based on a NAND component. Data are stored on individual NAND cells. Before data is written, it needs to perform an erase procedure on the cell. Thus, a cell is "available" to store data if it is only in an erased state.

So, if we take this thought further - a brand new SSD has all its cells in erased state. As the system adds files to the SSD, it reads the status of the NAND cells if it already has a data or it is already in an erased state. If the cell already has a data (this means that this is an overwrite operation), the "Controller" (which is more of an SSD OS/Management System) will read the contents of the cell onto a cache, applies the new data change in the cache, then locate another available NAND cell that is already in an erased state and performs a write operation to save the changed data. The unused original NAND cell will later on be erased by a "Garbage Collection" process that usually runs during idle time. If ever there is no available NAND cell to store the changed data, it will use the original NAND cell; but it would perform an erase procedure first before it stores the changed data.

All of this type of operational procedures occurs regardless of the type of i/o (create, overwrite, or even delete). Compare this to a hard disk to where such write operation is as simple as overwriting a sector. However, since SSDs are basically flash memory, it's write operation is still fast despite the number of procedures that is being executed.  



The LBA (Logical Block Address) and the Life Of A NAND Cell

The SSD Controller manages the flow of data between the Flash Memory (NAND cells) and the Interface (i.e. IDE/PATA, SATA) using a logical-to-physical mapping system known as Logical Block Addressing. The LBA maintains a list of Blocks that maps to several Pages. In the world of SSD, a Page is compromised of several cells to accommodate the manufacturer's defined size of a Page. A block is sized typically at 256KB. A cell can only store 1-bit of data, and depending on the SSD manufacturer, the Pages are sized between 4KB to 16KB which comprises of that many cells.

When a changed data needs to be written no matter how small it is (i.e. 1KB), the Controller reads an entire Page onto its cache to make its modifications before dumping it. And so, a write operation affects a lot cells despite the fact only a few of them requires changes.

However, for some strange Controller related reasons, delete operations are handled in blocks. So, if a delete transaction only affects a few pages of a block, that entire block is loaded into the cache for modification and dump it back to a new set of cells.



There are limits as to the number of times a cell can be written (cycles). And depending on the NAND design, the following are the known life cycles based on the cell type:


SLC (Single Level Cell)  rated for 50,000 to 100,000 cycles

MLC (Multi Level Cell, also known as DLC "Dual Level Cell") rated for 3,000 to 5,000 cycles

TLC (Triple Level Cell)   rated for ~1,000 cycles

Ref: SSD Endurance Test


V-NAND (32-stack MLC) 6,000 cycles (Ref: Samsung 850 Pro Endurance Test)

V-NAND (32-stack TLC) 2,000 cycles (Ref: Samsung 850 Evo Review)


To attain the target warranty of an SSD device, the Manufacturer tries to avoid rewriting onto the same cell during an overwrite operation and chooses to write to another available cell to prolong the life of all cells. Thus as an example, an SSD having 1TB capacity has to curve out some space for cycling to attain a target lifespan of an SSD and thus making available only 960gb to the host system. This logical 64gb "reserved" cells (also called over-provisioning) are constantly moving around the entire Flash Memory as data changes occur against the SSD.



TRIM Operation and Garbage Collection

Now that we understand the basic internal operation of an SSD and the role of a "Garbage Collection" process which basically makes the unused cells available again for writing by erasing the cells, TRIM comes in to speed-up that availability.

A TRIM is an operating system function that sends a message to the SSD device to immediately make the Block/Page/Cell available by making an erase operation for a cell to occur within a write transaction. This can be useful in a scenario where the SSD is always busy and there's not much idle time where the Garbage Collection process usually kicks-in.


A busy SSD makes the Garbage Collection ineffective since it could not run its process due to the absence of idle time, and thus making the unused cells unavailable for writing as they were not in an erased state yet. So in this scenario, generally the Controller is unaware of the unused cells which causes the on-going transactions to most likely perform an overwrite to the same cells if it couldn't find an available cell and thus lessening the life span of the affected cell. And so, enabling TRIM at the OS brings the benefit of prolonged life of the SSD and faster write operations.


A TRIM operation can only work on SSDs that support it and I think as of this writing, majority of the manufacturers' newer models support this.

If you have an older SSD, you may check the manufacturer website or its support group for an update of the firmware.



IMPLEMENTING TRIM


Mac OS X


TRIM support in Mac OS X is available starting in the Snow Leopard version (10.6.8). By default, this is enabled in all their products equip with Apple SSD and Flash Drive. However, the TRIM function is disabled when you attach a non-Apple SSD onto their system. In this case, you have to enable it via a 3rd party utility for Mac OS X versions below Yosemite. There's also an alternative way to do it manually as posted by MacTrast but you may need to edit the indented quotes to straight-up quotes in order for the commands to work. Another way to fix the quotes issue is to copy and paste the entire command onto a programming text editor and use that converted command onto the terminal.


Download the free version of TRIM enabler software for Mac OS X 10.6.8 (Snow Leopard) to 10.9.x (Mavericks) from cindori.org


To enable TRIM on version Yosemite (10.10.4) and higher, type the following command at your terminal-


sudo trimforce enable


To verify if TRIM is enabled,

Go to the top bar left corner and click on the Apple logo → About This Mac → [System Report] → SATA/SATA Express

Select your SSD device and a list of status and description will be displayed. TRIM Support should indicate “Yes”.