4

Most SSD have a cache to provide fast write speed. But what happens when I shutdown the computer with full cache? Is that cache volatile? How fast ist the cache processed and persisted? Do I need to wait some seconds before I shutdown my computer after transferring a lot of data? Do I need power loss protection to avoid data loss?

kfaria
  • 143
  • 4

2 Answers2

4

During a controlled shutdown, the OS/filesystem flushes all pending writes to stable storage, issuing a final write barrier (ie: ATA FLUSH) to be sure no data remains in the volatile write cache. This can need some time, but you don't have to do anything: just wait for the operation to complete (and the system to power-off).

But what does happen during an unexpected shutdown, for example just after a power loss? On consumer SSDs, lacking a powerloss protected write cache, you will lose any unsynched cache content. To avoid losing cached data, the user/OS needs to explicitly sync and flush important but pending data (eg: a database write or a filesystem journal update) via a sync+barrier primitive (ie: sync and fsync() on Linux).

On enterprise SSDs that provide capacitor-based powerloss protected write back cache, a sudden power failure will not cause any data loss. Depending on the drive type/firmware, this protected cache can be exported as writeback or writethrough:

  • in the first case (writeback), the OS will continue sending write barriers and cache flushes, but the drive will simply ignore them unless the on-board controller detects some issues with the powerloss protection circuitry. This mode of operation commands a somewhat higher overhead (due to barrier being generated by the OS), but permits the drive to dynamically switch between actual writeback/writeback+flushes/writethrough modes based on internal health counters;

  • in the second case (writethrough), the OS avoid sending any write barriers. This leads to greater performance (due to less OS overhead), but if the drive electronic detects any issues it can only switch to "full" writethrough, were any write is considered important and immediately flushed to the physical media.

shodanshok
  • 50,565
  • 2
    My question is regarding if there are any things a user has to respect when using an SSD. Does the driver prohibit or delay a shutdown (intentionally shutdown)? Is the clearing of the cache unnoticable fast? – kfaria May 19 '20 at 18:32
  • 1
    No, the driver does not delay the shutdown. Rather, the user/OS need to explicitly sync and flush all pending data via a sync+barrier primitive (ie: sync and fsync() on Linux). – shodanshok May 19 '20 at 19:37
2

Yes, file system will delay shutdown up to a point it’s own “lazy writer” will flush all the writes to persistent storage. However if you’ll hit “power off” all the data in cache will be lost. Obviously.