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: 24% [?]

    • Keith
    • January 14th, 2012

    From my experience, where I use a flash drive as swap with Ubuntu, it has worked out much better than hard-disk swap although not as good as RAM.
    Also, the gain seem to depend on how the swap is going to be used. I mean if you are adding in small processes (like firefox, gimp etc) slowly one by one, flash swap works great. You don’t feel the usual hang. But if you try loading heavy ones like starting a virtualbox os etc, there is a hang although comparatively smaller than that with hard disk swap.
    Here is how to change the swap partition to pen drive –

  1. umm,, well, I’m using netbook, and i was reading ’bout make a flash drive as swap memori in some website, then, when I look this post, I decide to use it with surely.

    sorry 4 my bad engish, hahaha

  1. No trackbacks yet.