Using An Sd Card As Swap Space


sinoth

Member
Joined
Sep 9, 2008
Messages
163
Website
Visit site
I was compiling on the Pandora and g++ kept crashing on one file... I finally figured out it was because I was running out of RAM! To remedy this, I found an old 256 meg SD card lying around and formatted it to be used as Linux swap space. This means it is an extension of the Pandora's physical RAM -- like a page file for Windows.

First, I used the fdisk tool (careful with this!) to wipe out the partitions on my card and created just one of type 82 -- Linux Swap. I then ran the following commands (with the extra card in the 2nd slot):

Code:
sudo mkswap /dev/mmcblk1p1
sudo swapon /dev/mmcblk1p1

To confirm the swap is working you can type `free` and take note of the Swap: total column. The swap will not be used automatically using this method. Every time you reboot you'll have to 'swapon' again.

Normally you won't need to do this. The Pandora has plenty of RAM for multitasking and running pretty heavy applications... I only ran into trouble because compiling can eat up memory.

Can any gurus comment on what kind of cons are there to permanently leaving a 256MB partition on an SD card and putting it in /etc/fstab to be automatically used? Will this degrade performance in any way even before swap is required?
 
As a Linux guru only, and not a Pandora guru, I can give you a few pointers to make as little use as possible (but still use it if need be) of the pandora swap SD, and make it load and use it automagically on boot.

Putting it in fstab will make it load when you enter swapon -a, but there's one more step you should add. I would edit /etc/sysctrl.conf and add this line:

vm.swappiness=0

If you read up on swappiness, you'll find that the default is 60, and 0 means that it will use swap as the dead last resort, and 100 means it will use swap as much as possible. For the sake of your SD card I recommend putting it to 0 =)

Now to make it load on boot, I would edit your sudoers with visudo and add sudo swapon -a for your username and put it as a startup script on login.
 
mawler said:
Putting it in fstab will make it load when you enter swapon -a, but there's one more step you should add. I would edit /etc/sysctrl.conf and add this line:

vm.swappiness=0

It should be sysctl.conf, I think. Also I would chose a much higher value. SD cards are cheap anyway and don't break _that_ easily.
 
Last edited by a moderator:
mali said:
mawler said:
Putting it in fstab will make it load when you enter swapon -a, but there's one more step you should add. I would edit /etc/sysctrl.conf and add this line:

vm.swappiness=0

It should be sysctl.conf, I think. Also I would chose a much higher value. SD cards are cheap anyway and don't break _that_ easily.
I always make that typo... yeah you're right.
 
Last edited by a moderator:
Another way you could do it, is to dd a file on your SD card, then do mkswap /path/to/swap.file
That way you don't need to do scary fdisking ( though I recommend cfdisk as it's slightly nicer to work with. )

Thought I posted a tutorial on this in my AUFS hackery thread, but looks like I haven't updated it yet! clever me.. hehe

[edit]
Reading your post again, I see you're sacrificing the entire card, rather than just repartitioning it.. the above way would only really be useful if you're wanting to keep the swap file on your normal card, or you don't want to sacrifice an entire card/repartition it.
[/edit]
 
Back
Top