3

I want to know if a particular block device claims to requires cache flushes.

From the xfs faq (emphasis mine):

Q. Should barriers be enabled with storage which has a persistent write cache?

Many hardware RAIDs have a persistent write cache which is preserved across power failure, interface resets, system crashes, etc. The same may be true of some SSD devices. This sort of hardware should report to the operating system that no flushes are required, and in that case barriers will not be issued, even without the "nobarrier" option. Quoting Christoph Hellwig on the xfs list,

If the device does not need cache flushes it should not report requiring flushes, in which case nobarrier will be a noop. Or to phrase it differently: If nobarrier makes a difference skipping it is not safe.

On modern kernels with hardware which properly reports write cache behavior, there is no need to change barrier options at mount time.

I know that my device does not need cache flushes, but I want to check that it is properly reporting that to the kernel.

How can I find out whether a particular block device reports that it needs cache flushes? I found this in /sys:

root@diamond:/# cat /sys/block/sdb/device/scsi_disk/0\:0\:1\:0/cache_type
write through

But I don't know what that means in this context.

Versions:

  • Linux 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-2 (2016-04-08) x86_64 GNU/Linux

1 Answers1

4

Yes, the contents of the file /sys/block/xxx/queue/cache_type file is how you can tell whether a device needs cache flushes or not. From Documentation/block/queue-sysfs.txt in the Linux kernel source:

write_cache (RW)
----------------
When read, this file will display whether the device has write back
caching enabled or not. It will return "write back" for
the former case, and "write through" for the latter. Writing to this
file can change the kernels view of the device, but it doesn't alter
the device state. This means that it might not be safe to toggle the
setting from "write back" to "write through", since that will also
eliminate cache flushes issued by the kernel.
  • If the contents of this file is "write through", then the device claims that it does not require cache flushes.

  • If the contents of this file is "write back", then the device claims that it does require cache flushes.