Swap on microSD

=Swap=

Swap is a virtual memory which runs off storage devices (HDD, SSD, eMMC, microSD...). It is in a form of a file on a drive (currently this method does not work on Maemo 5) or as a seperate partition (this is actually a better method). Its advantages are that it expands available memory, but it is of course very slow compared to thousand times faster RAM and is therefore used by the system to drop off data which is currently not needed. That means that you can run many programs at once, but they will be running slowly. Virtually every desktop OS does that (for example Windows has page file).

Enabling additional swap is not needed on N900 for expanding available memory, because it has already 256 MB of RAM and 768 MB of swap space on internal 32 GB eMMC module, resulting in 1 GB of total available memory, which is enough for a device like that. It does however help to offload the work from internal eMMC if there is additional swap space enabled on microSD, because kernel uses both swap partitions and is therefore swapping bandwidth increased which results in higher performance.

=Swappiness=

Swappiness is kernel parameter which tells it how aggresive should the swapping be. The more aggressive it is, more RAM is freed, but there is a performance impact, because more data needs to be swapped (written to the slower drive). Swappiness value is between 0 and 100 with 100 being the least aggressive. Maemo 4 had swappiness set to 1 by default while Maemo 5 sets it to 100. The best value is somewhere in between. 256 MB of N900's RAM is enough for a few open programs and there is also enhanced battery life because eMMC doesn't need to write so much swap data. So swappiness should be set somewhere between 30 and 50. It is set with the following command which has to be run as root.

echo 30 > /proc/sys/vm/swappiness

You can set swappiness at each boot automatically by using startup script.

=Configure microSD card for swapping=

The microSD card must be split into at least 2 partitions. The first one should be fat32 (vfat) formatted and the second one must be formatted for linux swap (type 82) and about 384 MB in size. You can change the size of it, but this value should be suitable for most people.

You can repartition and reformat the card with standard Linux tools from the N900 terminal, but the easiest way is to connect the device in mass storage mode to a Linux machine (which can also be a virtual machine if you use other OS as your primary one) and you can do the partitioning with GUI tools.

=Using microSD partition as swap=

Reboot after the repartitioning and after the boot, this is seen in /dev.


 * /dev/mmcblk0 (internal eMMC itself)
 * /dev/mmcblk0p1 (27 GB partition mounted on /home/user/MyDocs)
 * /dev/mmcblk0p2 (2 GB partition mounted on /home)
 * /dev/mmcblk0p3 (768 MB swap partition on eMMC)
 * /dev/mmcblk1 (microSD itself)
 * /dev/mmcblk1p1 (fat32 partition on your microSD mounted on /media/mmc1)
 * /dev/mmcblk1p2 (swap partition on your microSD)


 * 1) mmc part defines type of storage device
 * 2) blkX defines number of storage device (0 is internal eMMC, 1 is microSD)
 * 3) pY defines partition number

The swap partitions are not mounted, but you can enable swapping on microSD partition with:

swapon /dev/mmcblk1p2

If you have repartitioned microSD differently you have to change the partition number accordingly. The last part is setting the swapon command to run at every boot and you can do that with a startup script.

There is an additional warning and that is that while the device is running and swap is turned on on microSD partition, you shouldn't take the card out. It would be the same as taking out a RAM stick while running.