I believe it is enabled by default. You can check it:
cat /sys/block/nvme0n1/queue/write_cache
write back
Probably this is optimal setting
Write through caching:
When the controller receives a write request from the host, it stores the data in its cache module, writes the data to the disk drives, then notifies the host when the write operation is complete. This process is calles write-trough caching because the data actually passes through-and is stored in- the cache memory on its way to the disk drives.
Write back caching:
This caching technique improves the subsystem's response time to write requests by allowing the controller to declare the write operation 'complete' as soon as the data reaches its cache memory. The controller performs the slower operation of writing the data to the disk drives at a later time.
In most cases nvme ssds has built in ddr cache like 500MB or 1GB (probably managed by disk firmware if not let's someone correct me because maybe that's the problem)
You can check if trim is working as expected by manually executing sudo fstrim -av
and test write speed in real life by copying and pasting big file and measure time taken.
But there are still slow writes and it seems like these are handling in this way by kernel itself (maybe some reliability syncing):
SSD slow write speed on Ubuntu