Swap partition on a flash drive, is it really that bad?
There are comments all over the web giving negative advice to people who would like to try running a linux box with swap partition on a flash drive.
Write cycles are limited in flash drives. A memory cell can usually be written to about 100,000 times but nearly all flash memory devices have specialized circuitry to write to different locations each time the memory is access to even out the wear on all cells. So in theory you can write 200 TB of data on a 2 GB sd card before it fails. This may not be so in practice, but let’s halve it to 100 TB. How much time do you think your computer is gonna take to wear out your card completely? Well that depends on your computers swappiness, but I seriously think it is going to take about a year.
Another protest against the flash swap is the speed of flash devices. While flash devices are much slower than hard drives, think about this scenario: Your computer is playing back a high definition video file and using all its ram, and your hard drive just can keep up with reading the media from the drive. What happens when a cron job executes and needs some memory? Some pages need to be swapped to your hard drive which is on the same device but on a different partition. Your drive head will jump there to write the page, and jump back immediately to reading the media potentially skipping frames on decoding. Using another harddrive to hold the swap file would fix this problem but what if you can’t? What if you are a cheapskates like me? Using a flash memory device for swap would free your hard drive, and even though it is slower, the fact that it uses another media to read from and another bus to move the data makes for shorter I/O queues on devices and faster access times.
So while it may not be as good as upgrading your RAM, putting in a second hard drive for swap or buying a faster hard drive; it still makes a difference in systems where hard drive I/O is the bottleneck. If this applies to you, go on and make a swap partition on that old flash drive (just make sure it is not USB 1.1). It is a very cheap performance upgrade you can use for a year. And who knows what you will be using one year from now anyway?
Popularity: 27% [?]