Hacker News new | ask | show | jobs
by joshspankit 1985 days ago
> The only reason anyone ever wants to disable disk caching is because they think it takes memory away from their applications, which it doesn't!

Wildly disagree!

I regularly want to disable disk caching when I want to be able to drop power or disconnect a drive without drive corruption.

With smaller “microcontrollers” running linux, their power could drop at any moment. With external drives, I might want to pull the drive the second it’s done transferring a file. Caches get in the way in both cases.

2 comments

There are different types, which I think is buffers vs cache in top. The read caches would be fine but the delayed writes in ram are quite another thing.

The one that eats your ram (the reason for the site to exist) would mostly be the read caches.

enabling or disabling disk cache doesn't prevent the write hole when experiencing sudden power loss. in transit writes are still lost and have to be atomically accounted for. disk caches only increase the amount of data that is or isn't synced with disk.
With sudden power loss, the difference is that any single write may be in the cache for longer than the time it would have taken to write it. In the case of no cache with a power loss there is only a single possible failure: power loss during write. With cache that expands to two possible failures: Power loss during write from cache, and power loss with unwritten data in the cache.
You can disable 'write cache' on your linux system.

to see wether or not write cache is active

cat /sys/block/[your block device]/queue/write_cache

write back means the write operation is completed as soon as it hits the linux write cache you can set it to write through to make it wait untill the controller responds, this has obvious performance implications depending on the workload. note that alot of hdd's and all ssd's have their own caches and you'll need to disable those as well.

that would at least give alot of performance back from the read cache.

check nvme controller write cache [1]

sudo nvme id-ctrl /dev/nvme0|grep vwc

disable nvme write cache

sudo nvme set-feature /dev/nvme0 -f 0x6 -v 0

I have not tested anything and I do not recommend this in the slightest, dont expect to be protected against sudden power failure data loss. it will also destroy your ssd and amplify writes considerably.

[1] https://wiki.archlinux.org/index.php/Solid_state_drive/NVMe#...