# to DISCARD or not to DISCARD on modern NVMe drives

## tnt

Hello.

I have run into quite a lot of places where real-time discard/trim (used as ext4 mount option) is not recommended, even by ext4's own Theodore Ts'o:

https://forums.freebsd.org/threads/ssd-trim-maintenance.56951/#post-328912

Nevertheless, all of those articles were focusing on buggy SATA implementation of queueable TRIM command, forcing linux to revert to non-queueable version and leading to performance impact. NVMe drives were usually not mentioned.

Is there any info how successfully queueable TRIM command is implemented in modern NVMe drives like WD Black 3D, Samsung 970 EVO/PRO and similar?

Thx.

----------

## hhfeuer

There's no new definitive info, just the old Intel NVMe docs from 2016 where it was also advised not to turn on discard but use the periodic fstrim. Same reasons that Ts'o mentioned, especially small discards being ignored thus ineffective.

----------

## NeddySeagoon

tnt,

The guts of the drive have not changed, only the interface to the outside world, so the guidance for SATA devices still applies.

----------

## Jaglover

F2FS has discard turned on by default. https://www.kernel.org/doc/Documentation/filesystems/f2fs.txt

----------

## tnt

After so many years, I would really expect those SSD controller developers to implement some kind of list/map of blocks eligible for TRIMing and to TRIM them later/when idle.  :Sad: 

I guess that this is exactly what queueable TRIM should do, when implemented correctly.

----------

## P.Kosunen

 *NeddySeagoon wrote:*   

> The guts of the drive have not changed, only the interface to the outside world, so the guidance for SATA devices still applies.

 

https://nvmexpress.org/about/nvm-express-overview/

There are changes in the guts also, parallelism and queues are more important.

https://github.com/torvalds/linux/blob/master/drivers/nvme/host/pci.c

There are some Samsung/WD quirks, but those doesn't seem to be deallocate/trim related. I have used discard with ext4 on my Samsung SM961 without problems.

----------

## tnt

But, if online TRIM/DISCARD is not recommended, it's quite strange that Windows is still enabling it by default.   :Rolling Eyes: 

Windows 8/10 have scheduled TRIM via Disk Defragmenter (Optimize Drive), but real-time TRIM is still on if you do not kill it on your own.

----------

## tholin

 *tnt wrote:*   

> But, if online TRIM/DISCARD is not recommended, it's quite strange that Windows is still enabling it by default.   

 

I guess Windows IO subsystem isn't as bad as Linux's. In Linux if there are a lot of discards queued up and the disk is slow at processing discards and some program calls sync() everything freeze until the queue has been processed. The same thing happens when offline trim (fstrim) is used but at least you can decide when to run it.

A patch was merged in 4.18 that will hopefully improve the situation if wtb is used.

https://github.com/torvalds/linux/commit/782f569774d7000e54ae9d680b0e4cd29b1c7ca3

----------

