6

I am using a SSD connected to a Mac over a sata to usb bridge to archive relatively big files. After I transfer it to the SSD, I unmount it and and unplug it.

This SSD has a DRAM cache. From my understanding, this cache is both used to cache writes and store a copy of the file mapping. If I unplug it without unmounting or when its currently writing, I would assume that it would be very possible to lose data that is cached in DRAM and maybe even lose files due to pointers to any data that changed in the mapping being lost as well.

My question is: If I unmount the drive and immediately unplug after it successfully unmounts, is there a chance that I remove power from the SSD prior to it finishing writing whatever is in the DRAM to disk?

Does the OS / APFS manage the DRAM and ensures that its flushed prior to it being unmounted or does the firmware in the SSD do this?

agz
  • 8,438

2 Answers2

26

The DRAM on the SSD is managed by the firmware, but the OS can tell the firmware to flush all pending data to stable storage using the "barrier" function calls. The OS can also tell the SSD whether write caching should be enabled at all.

If you cleanly unmount the drive, the OS will issue the required function calls to make sure all data is fully written.

If you unplug it mid-write without cleanly unmounting, all bets are off, and the outcome will depend on the SSD firmware, file system and various other factors.

5

There is DRAM involved both in the host controlled by the operating system and DRAM inside the SSD controlled by the SSD's firmware.

As stated in the other answer, if you eject properly, all of that should be taken care of by well defined mechanisms that are part of the SATA and USB protocols to synchronize actions between the host and the SSD.

If you yank it out mid write, it is likely that data in both the DRAM of the host and the SSD will remain unwritten, and it is kind of moot if the unwritten data was in the DRAM in the host or the DRAM in the SSD, as it will be lost either way. In that situation, there's probably even data on the bus that has been sent by the host but not yet received by the SSD.

user10489
  • 2,081