Swap on iLiad

From MobileRead
Jump to: navigation, search

Swapping is a method consisting of swapping pages from the main working memory of a device (RAM) onto an auxiliary device like an harddrive or, in case of the iLiad, a disc-on-chip or a flashcard. It is a linux implementation of virtual memory used when main memory is running low.


[edit] Prerequisites

italic commands need to be run in the shell.

  • Shell-Access to the iLiad is needed Shell-Access
  • An up-to-date version of Busybox is needed [[1]]

[edit] Creating a swapfile

  • Create a file of the right size on the DOC, SD/MMC or CF:
dd if=/dev/zero of=/media/CF/swpfile bs=1M count=64

This actually creates a file swpfile of size 64 MB in /media/CF/ - thus on a CompactFlash-Card - filled with zeros. We need this file to reserve a given amount of space, though the file itself is not usable as swapfile at this stage. For SD/MMC or if using the intern Disc-on-Chip-Memory you would have to replace /media/CF with the appropriate pathes - the same applies for the following commands. Of course the size of this file can be changed as well, just replace count=64 with the needed size in MB, e.g. count=128 for a swapfile of 128 MB.

  • Create a swapfile out of the file above
mkswap /media/CF/swpfile 

Now the file can be used as swapfile.

[edit] How large should the swapfile be?

On normal Linuxsystem a rule of thumb is 2x the memory size. As the iLiad has 64MB of RAM, this would mean a swapfile or partition with 128MB. Normally 64MB should be sufficient.

[edit] Swap on CF vs MMC/SD vs DOC

Using an extern card thus has the advantage o Using the intern DOC-device has several advantages:

  • Accessing an extern card consumes energy, thus reduces the battery time
  • You need to have the right card inserted whenever you want to use swap

But it has a severe disadvantage as well:

  • There is only a limited number of write cycles to a flash device. As swapping can mean a high number of write accesses to the swapfile in relatively short time, this could tear down the DOC-device much faster then normal usage. As the DOC cannot be replaced, failure of it would result in a defect iLiad.

An external card on the other hand is cheap and replaceable. Modern Flashcards should give a reasonable lifetime even being used as swapdevice - but even when failling, replacing them is easily done. Higher quality cards, often called ultra cards or 'professional series card', can be expected to achieve a longer lifetime than standard or low-quality cards.

[edit] Activating Swap

swapon /media/cf/swpfile

Again, replace /media/cf/swpfile with the appropriate path, see above.

[edit] Deactivating Swap

swapoff -a

deactivates all swapfiles. If the swapfile resides on an extern card, swapping needs to be disables before the card can be (safely) removed.

[edit] Swap on Startup / shellscript to ease usage

Activating swap on startup would be easy. Copy the following into a file activateSwap.sh and set its executable bit by running chmod 700 activateSwap.sh. Running this script activates swap:

#! /bin/bash
swpFilePath='/media/cf/swpfile' #change to whatever path is used
swapActivated = 0
if ( -e $mmcFolder/swpfile ) ; then
   swapon $mmcFolder/swpfile && swapActivated = 1
if ( $swapActivated -gt 0 ) ; then
   echo "Swap successfully activated"
   echo "Error activating swap"

Running it from a startscript thus would activate swap on bootup, running it on the comandline activates swap when needed. In both cases swapoff -a would deactivate swapping and should be run when powering down the system.

(this script doesnot work with the default shell, but a test -e /your/swap/file && swapon /your/swap/file do the job)

To set the swap at boot time, copy the script to /home/root :

cp activateSwap.sh /home/root/

then link the script into the init system

ln -s /home/root/activeSwap.sh /etc/rc5.d/S99swp

Warn : use the name S99swp, or this will not work ! (the swap script must be launched after S99start)

Use the following script if bash is not available:

#! /bin/sh
swpFilePath='/media/card/swpfile' #change to whatever path is used
if ( test -e $swpFilePath ) ; then
   swapon $swpFilePath && echo "Swap successfully activated"
   echo "Error activating swap"

Further information and some examples can be found in the corresponding discussion thread: [[2]]

Personal tools

MobileRead Networks