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?

15
  • 1
    Without knowing the specific SSD model it is impossible to tell you what will happen. Your question is exactly why there are consumer versus enterprise drives. techcommunity.microsoft.com/t5/storage-at-microsoft/…
    – MonkeyZeus
    Feb 16, 2022 at 14:16
  • It's an Inland SATA SSD. I am not even sure if it has DRAM as the only info I can find online are conflicting. When transferring 1 huge file, I see it run at a higher throughput until it settles in at a much slower one (don't know if this is DRAM caching or some caching macOS is doing). I assume in the case it doesn't have DRAM, it can only write to stable storage.
    – agz
    Feb 16, 2022 at 18:09
  • [Drive Listing] (microcenter.com/product/623042/…)
    – agz
    Feb 16, 2022 at 18:15
  • @agz: How huge and how fast? Many SSDs use some of their cells as a fast SLC write buffer (1 bit per cell), later compacting that to TLC or QLC or whatever. If you write more than a few (dozen) GiB (depending on how much free space the drive has, given trim etc.) at once, that will fill up. phisonblog.com/the-benefits-of-using-slc-buffers-with-ssds / anandtech.com/show/16087/the-samsung-980-pro-pcie-4-ssd-review/… for example. Feb 17, 2022 at 1:07
  • 1
    Sounds like you're suffering from an SLC cache scenario as explained in phisonblog.com/the-benefits-of-using-slc-buffers-with-ssds. The SSD you linked doesn't look very special so as long as your OS tells you it's safe to unplug the drive then it should be safe. I assume that trying to unmount it during a transfer results in the system telling you "NO", correct?
    – MonkeyZeus
    Feb 17, 2022 at 18:53

2 Answers 2

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.

16
  • 3
    The point in this answer is that the OS can use the barrier function in the disk I/O protocol to make sure all the writes are done before it tells the user that it is safe to remove... That barrier function will be called as part of the unmount.
    – user10489
    Feb 16, 2022 at 12:36
  • 5
    @MiG: The OS can only report what the SSD tells it to. There have been drives in the past which reported to the OS that they have committed the write to permanent storage when, in fact, they were still in the process of writing it. There is nothing the OS can do about that. So, the answer to "I think the asker wants to know if, after the OS reports that the volume is successfully unmounted, there might still be DRAM writes possible." is "Yes, especially if the drive lies to the OS". Feb 16, 2022 at 15:09
  • 1
    If the hardware is lying to you, it is defective and all bets are well and truly off. Feb 16, 2022 at 15:40
  • 4
    @GordanBobić or badly designed. If what it does doesn't correspond to what it tells, I'd call that a bug.
    – MiG
    Feb 16, 2022 at 15:44
  • 1
    @user21820: I wouldn't assume that at all. Lying to boost benchmark results is quite intentional.
    – Ben Voigt
    Feb 17, 2022 at 23:04
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .