TRIM

TRIM 是 file system 告訴 SSD / flash-based NVM:「這些 logical blocks 已經不用,可以回收」。NVMe 類似 command 常稱為 unallocate / deallocate。


Why SSD Needs It

HDD 可 in-place overwrite,刪除後等下次覆寫即可。Flash 不能直接 overwrite page;通常要先 erase 整個 erase block。

若 SSD 不知道哪些 pages 已被 file system 刪除,就會把它們當有效資料搬來搬去,造成 garbage collection 與 write cliff。


Flow

file deleted
  → FS marks blocks free
  → FS sends TRIM ranges
  → SSD marks pages invalid
  → background GC can erase earlier

Tradeoff

TRIM 是 hint,不保證立刻 erase。立即 TRIM 太頻繁會增加 command overhead;batch / periodic TRIM 較省,但 device 會晚一點得知 freed pages。

TRIM 也不是 secure erase;需要資料不可恢復時,要用 encryption erase 或 device secure erase。