As we know, SSD can only write full 4k page or erase it. Not to add bytes to existing dirty page.
Lets take database write ahead log.
We call fsync() with flushing all buffers to ssd every log update with new 1k of data.
- write first 1k of log and allocate 4k ssd page. call fsync()
- write another 1k of wal data. call fsync().
ssd can’t add to existing 4k page, read 1k from previous page and write 2k to new 4k page.
mark prev page as dirty for garbage collector. - the same as 2 step – write 3k to new allocated 4k page
- write last 1k. call fsync()
ssd driver allocate new 4k page, move prev 3k of data and add last 1k to the end.
after all we have 4 dirty pages – last one with full 4k of data, and 3 previous pages marked as dirty on order to reclame garbage.
This cause fast degradation of ssd cause we need write 4 times more pages than we should write to simple hard drive.