SSD 為什么順序寫比隨機寫性能更好?


SSD以Page為單位做讀寫,以Block為單位做垃圾回收,Page一般有16KB大小,Block一般有幾十MB大小,SSD寫數據的邏輯是:

1)將該塊數據所在的Page讀出

2)修改該Page中該塊數據的內容

3)找出一個新的空閑Block將2)中的Page寫入,並將1)中提到的Page所在的Block中的Page標志為臟

 

理解了寫原理,也就明白了為什么順序寫比隨機寫好了。四個字:垃圾回收!寫相同數據量的情況下,順序寫制造更少的垃圾Block,所以比隨機寫有更高的性能。

這篇文章有詳細的描述:

... the need for garbage collection affects an SSD’s performance, because any write operation to a “full” disk (one whose initial free space or capacity has been filled at least once) needs to await the availability of new free space created through the garbage collection process. Because garbage collection occurs at the block level, there is also a significant performance difference, depending on whether sequential or random data is involved. Sequential files fill entire blocks, which dramatically simplifies garbage collection. The situation is very different for random data.

As random data is written, often by multiple applications, the pages are written sequentially throughout the blocks of the flash memory.
The problem is: This new data is replacing old data distributed randomly in other blocks. This causes a potentially large number of small “holes” of invalid pages to become scattered among the pages still containing valid data. During garbage collection of these blocks, all valid data must be moved (i.e. read and re-written) to a different block.
By contrast, when sequential files are replaced, entire blocks are often invalid, so no data needs to be moved. Sometimes a portion of a sequential file might share a block with another file, but on average only about half of such blocks will need to be moved, making it much faster than garbage collection for randomly-written blocks. ...

 原文來源:http://serverfault.com/questions/843628/why-does-sequential-writes-have-better-performance-than-random-writes-in-ssds

 

當然,如果每次讀寫都以Block為單位讀寫,那么順序寫和隨機寫的性能相當。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM