7

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?

4
  • 1
    Then why does Windows tout Readyboost for SD cards, if it would wear them out?
    – user412191
    May 21, 2015 at 1:02
  • 3
    Possible duplicate of Can you use an SD card for swap in Ubuntu 12.04?
    – mlt
    Oct 8, 2015 at 19:48
  • @user412191 Readyboost isn't swap. It's a type of disk cache specifically tuned for high reads and infrequent writes. Readyboost would be suited to an SD card. May 1, 2016 at 23:56
  • none of the answers here comment on the swapiness of the system being used. I think this is something quite important to consider. If I'm primarily using my sd card to enable hybrid suspend/hibernate (which I am) and limit the swapiness to 0, then swap will not be used as often (thus avoiding the multiple writes issue degrading the SD card). Also, for systems with only an SSD (which I have) I'd recommend everyone to set swapiness to 0 and use an SD card as the swap drive (it's obviously better to degrade an SD card as compared to an SSD).
    – kapad
    Sep 21, 2018 at 7:36

4 Answers 4

7

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.

13
  • I really don't care if it gets damaged, I have a supply of like 10, also, the reader is internal, I don't know if that makes a difference?
    – sbergeron
    Jun 25, 2014 at 14:50
  • 2
    In that case it depends on the Hard Drive and SD card. All other things being equal, it's still pretty unlikely that your SD cards have a higher read/write speed than a conventional Hard Drive. Is there an "I" character or an "II" character in the bottom right corner of the cards? If so then it's likely that they're on-par with the hard drive. If not then it's very unlikely that the read/write speed is going to be acceptable for swap. I've noted that you've refereed to them in the post that they're "normal speed". It is going to be a massive bottleneck on your system whenever swap starts. Jun 25, 2014 at 14:57
  • they're just a normal class 4
    – sbergeron
    Jun 25, 2014 at 15:05
  • Being generous the read/write speed is going to be about 25% that of your Hard Drive. Jun 25, 2014 at 15:07
  • so better to just use a file on the hard drive?
    – sbergeron
    Jun 25, 2014 at 15:09
3

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.

0
2

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.

2
  • 1
    Is there any detriment, especially during file transfers, of having swap on the same disk? I just thought it would congest the bandwidth of the hard drive, but I guess not?
    – sbergeron
    Jun 25, 2014 at 13:35
  • There is a small potential detriment to having it on the same drive - if there is a disk-heavy workload occurring at the same time as your system needs to swap - but this detriment will be far exceeded by the penalty of having it on a slow SD card (or any other slower drive). Unless you can afford two somewhat equally fast hard drives, just putting swap into a partition near the start of the drive - even on the same drive as the OS - should get you pretty good performance. Jun 25, 2014 at 13:40
0

Based on my comment here

The first thing to consider is the use case for the swap drive. Is this swap drive going to be used often because the system has less memory and is used for running many different applications simultaneously?

If yes, then it's definitely better to go with a swap on the main drive, since many writes to the SD will degrade performance, and in cases where the system wrote a swap page to a corrupted SD, the system will crash and need to be restarted with a new SD.

If no, then you need to consider the speed of the SD card controller (and also the speed the SD card itself supports i.e. the class of the SD card). For this case, @thomasrutter's answer is what you should follow.

The second case to consider (I'm adding this, which is not a part of the OPs question but is relevant with today's laptops) is whether the main drive is a SSD drive or a rotational drive.

For SSD drives, I'd always recommend using an SD card for swap (or no swap at all) because the SSDs are still very expensive, and it's financially sound advice (to degrade the SD which is cheap instead of the SSD, which is many times more expensive).

Finally, let's consider the case for a machine with a large enough RAM and an SSD drive. For these machines (laptops/desktops) the main memory would be sufficient for almost all work loads. Therefore, I'd recommend tuning the swapiness to 0. (the swap would only be used for cases where to main memory is fully used up, or for enabling hybrid suspend/hibernate). For these systems, I'd definitely recommend a swapiness of 0 with a SD card as the swap drive. The reason is that each time you suspend, a number of writes are made to the swap, and degrading an SD card is way cheaper than degrading an SSD drive.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .