1

I know hdparm -W0 /dev/sata-ssd can disable disk cache for SATA SSD, but this does not work on my NVMe SSD (i.e., Samsung 980 pro). Maybe some option of nvme can do it, but I failed to find it.

How can I make this?

Thanks.

Tim He
  • 291

1 Answers1

6

You can do this via the nvme commands, but I'm curious to know why you would want to do this. Disabling the cache will save a bit of RAM if that's the goal, bit it will cut your throughput in half at the very least.

Either way, this is how you do it:

# nvme get-feature -f 6 /dev/nvme0n1 
get-feature:0x6 (Volatile Write Cache), Current value:0x000001
# nvme set-feature -f 6 -v 0 /dev/nvme0n1 
set-feature:06 (Volatile Write Cache), value:00000000
# nvme get-feature -f 6 /dev/nvme0n1 
get-feature:0x6 (Volatile Write Cache), Current value:00000000

If for some reason you elect to make this persistent across reboots, you will need to write a udev rule:

ACTION=="add", KERNEL=="nvme*", RUN+="nvme set-feature -f 6 -v 0 %N"

These commands work with my Samsung 970 Pro, so should work with your device as well.

  • 1
    Thanks for the answer! Because I found that my Samsung 980 pro is slower than my Samsung 860 evo (i.e., fsync() latency). I suspect the disk cache may lead to this. So I want to disable them to make a comparision. – Tim He Jan 22 '21 at 02:20
  • Thanks for posting the answer instead of just saying "why would you want to know that, haha regards". – Nande Jun 03 '22 at 22:22
  • When I try this, I just get "feature not namespace specific". Any Idea why? – Philipp Ludwig Jun 28 '22 at 10:23
  • Disk caches could slow cluster storage down: https://yourcmc.ru/wiki/Ceph_performance#Drive_cache_is_slowing_you_down – dpat Nov 16 '22 at 14:42
  • If you get the "feature not namespace specific" error, try using set-feature against "nvme0" instead of "nvme0n1" (adjusting of course for whatever the identifier of your disk is). – Truisms Hounds May 10 '23 at 20:25