User avatar
Posts: 1014
Joined: Mon Feb 13, 2012 8:06 pm
Location: Romiley, UK
Contact: Website

Re: Linux Swap and SD Cards

Mon Mar 05, 2012 3:52 pm

Haven't easily found anything on this subject but I'd be grateful if someone could answer this one.

First off - I assume that any Linux Build used on the Raspi will be holding Linux swap on the SD card.

Now I've had a play with 'low power' 'solid state' 'no moving parts' Linux Cigarette Packet Servers in the past with the wonderful Linksys NSLU2 NAS - this was a 266Mhz Arm5 Compatible Core device with 32Mb (ouch) of RAM that had 2 USB ports which you could hang Memory Sticks and whatnot on - there was a big 'health warning' on them though that they would not run forever because the Linux Swap was on the SD Card/USB Stick and these devices were certified for quite a low number of device writes before failing - and of course Linux Swap gets good and hammered on low memory devices - and indeed that's what happened to mine.

So - is this issue likely to afflict the Raspi?  I assume the more expensive the SD Card, the greater the number of guaranteed write cycles on the card, so maybe we can buy our way out of the issue (if it actually exists)
Steve N – binatone mk4->intellivision->zx81->spectrum->cbm64->cpc6128->520stfm->pc->raspi ?

Posts: 5
Joined: Mon Mar 05, 2012 5:13 pm
Contact: Website

Re: Linux Swap and SD Cards

Tue Mar 06, 2012 8:51 am

There is always a chance that even good SD card will die due to amount read/writes. RPi having 256MB of RAM may perform better comparing to your previous boxes, SD card with its 200MB of SWAP may survive longer. Everything depends on type of use. I would suspect that combination of these two (RAM/SWAP) will give overall good performance and life span - we're going to know for sure when we finally get the units so we can start testing...

Posts: 6
Joined: Wed Feb 08, 2012 12:51 pm
Contact: Website

Re: Linux Swap and SD Cards

Tue Mar 06, 2012 9:28 am

Depending on the applications you plan to try, you might not even need any swap space at all. Its not a hard and fast requirement of the OS, just very commonplace on desktops and servers where there is lots of storage available and you might as well use swap, just in case.

256MB is a lot of memory for a device dedicated to a single purpose. The problems start when you do like Freddie Mercury and sing the "I want it all, and I want it NOW" song...

Memory and swap usage are easy enough to test using a virtual machine, use the "top" command in a separate console to see what the memory does as you run stuff, swap will only be touched if the system needs it, and the used amount is an indication of what you have to "slim" off your applications' memory footprint.


Posts: 28
Joined: Sun Oct 02, 2011 5:36 am
Location: Traverse City, MI USA
Contact: Website

Re: Linux Swap and SD Cards

Tue Mar 06, 2012 6:04 pm

It definitely depends on usage. I'm currently running Arch Linux ARM on a Pogoplug that only has 128MB of RAM. It doesn't have swap and runs off a USB flash drive. I'm able to serve up Django applications with Nginx as a reverse proxy without running out of memory. Try to find the lowest resource intensive application for whatever task you're trying to accomplish.
Ben Hanna
Ducky Pond

Posts: 4
Joined: Fri Feb 17, 2012 11:10 pm

Re: Linux Swap and SD Cards

Tue Mar 06, 2012 6:52 pm

I agree using swap on a flash drive can be an issue. A first sulution is to turn the swap off with something like:sudo swapoff /dev/sdaX
You can also se a pourcentage withcat /proc/sys/vm/swappiness
which indicates how much ram needs to be used befor the kernel starts using the cache. It can be changed by addingvm.swappiness = 20
in the /etc/sysctl.conf file and restarting the computer. These commands seems to work with ubuntu, so make sure it's also appropriate with your distribution when you try it

Posts: 10
Joined: Sun Mar 04, 2012 3:52 pm

Re: Linux Swap and SD Cards

Wed Mar 07, 2012 6:13 pm

I once built a Debian system that ran off a USB key (it was a prototype for something we ended up not doing).  Not a ramfs system that copied everything into a ramdisk; it just ran right off the USB drive.  It didn't have any swap but it did have an SNMP-based network management system that wrote regularly to the drive.  We ran it for a week once.  The system appeared to be working fine when I shut it down.  That USB key never booted again, though, and it wasn't readable when I tried to see what the trouble was.

I believe most consumer-grade flash memory devices are good for about 100,000 writes to any location, but they normally try to avoid writing to the same location over and over.

Return to “General discussion”