Is having swap on hard drive or sd card better?

I have a bunch of 16gb normal speed sdhc cards, so if I use them I'm not worried about them getting damaged, but I was wondering: is swap on a 7200rpm 320 gb hard drive that is also the drive ubuntu is installed on better or worse than an sd card with the only use as swap?


Solution 1:

If you're unconcerned with damage to your SD cards then it really depends purely on speed. Your 7200rpm internally is likely slower than your SD card's internal read/write speed, but actually getting data to drive will likely be the biggest bottleneck. Unless your SD card reader is very new, the 7200rpm HDD connected with a SATA should be significantly faster.

Your SD card is unlikely to have a decent microcontroller to address spent/damaged memory very efficiently (how SSD's address increased memory failures), so you'll more than likely not notice any failure until you get a catastrophic failure for the SD card.

If you're using anything "mission critical" on this system, then you should definitely not be going with the SD cards.

Solution 2:

The SD cards will perform significantly worse for swap and it may reduce their lifetime.

  • Flash media is asynchronous in its access speed. Performing many separate read actions is very fast, faster than usual on a hard drive. However, performing many separate small write actions is very slow, often an order of magnitude slower than on a hard drive.

    When you swap to disk, your workload will consist of many small write operations - the worst performing workload for it.

    (In case you're wondering, modern SSDs get around this issue with very sophisticated firmware trickery, which simpler Flash drives like SD cards don't have).

  • Flash media has a limited number of write cycles. This limit is high enough that normal consumers don't need to worry about it - it'll usually be in the tens of thousands of writes. However, if you are swapping then it will increase the wear on the drive quite a lot. Probably not enough to observe any problems over a short timespan.

Solution 3:

While you can use an SD card for swap (Raspberry Pi does this, for example) it is not ideal. Use your hard drive, as it much faster than an SD card. Also, an SD card will eventually wear out from heavy usage due to the limited number of writes.