1

When using SWAP on an SSD, does the filesystem offer any write-cycle protection? i.e. randomizing or otherwise managing writes to avoid "flash wear-out" since modern SSDs are generally rated in the low thousand write-cycles before wear-out.

I had previously assumed that all filesystes (SWAP included) would, though when reading ArchWiki

A recommended tweak for SSDs using a swap partition is to reduce the swappiness of the system to some very low value (for example 1), and thus avoiding writes to swap.

I noticed that my laptop genearlly has 100MB-400MB of swap at any given time. Am I accelerating the wear on my SSD by allowing it to go to swap?

1

Swap is not a filesystem.

I don't think OSes take any particular care of how they arrange the swap space. Most filesystems either don't care or are optimized for rotating disk drives in that they try to privilege sequential reads and writes (i.e. avoid fragmenting files too much), which is not relevant on SSD.

Modern SSD drives (as opposed to cheap flash media) do their own wear leveling in firmware, so the OS shouldn't need to care about this. When the OS is writing to the same address, the firmware maps each access to different physical blocks, in order to avoid having many erase cycles to the same block. With an SSD drive in a PC or server, as opposed to a flash memory in an embedded device, flash wear-out is usually not something you need to care much about.

You may however want to reduce swappiness on SSD compared to HDD. Swappiness is a compromise: it's the parameter that controls whether the kernel prefers to keep file contents or process data in RAM. Higher swappiness means that the kernel is more likely to swap out process data in order to make room for file contents. With many workloads (but not always), a lot of file contents is only ever read, whereas application data is written relatively often, so increasing swappiness increases the proportion of I/O in the write direction. Since SSD are usually relatively slow to write, compared with reading, the optimal swappiness tends to be lower for SSD.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.