Tested on a ASUS WL-500g Premium with Kamikaze 7.07 (brcm-2.4).

1. Install kmod-loop, losetup and swap-utils packages

ipkg install kmod-loop losetup swap-utils

2. Create the UCI configuration file (/etc/config/swap)
config swap
        option path     '/tmp'
        option filename 'swapfile'
        option size     '2000'

3. Create the init script to initialize the swap space  on every boot


#!/bin/sh /etc/rc.common
# Copyright (C) 2007 OpenWrt.org
START=98
sleep 5

start_service () {
        local section="$1"
        config_get path     "$section" path
        config_get filename "$section" filename
        config_get size     "$section" size

        dd if=/dev/zero of=/$path/$filename count=$size
        losetup /dev/loop/0 /$path/$filename
        mkswap /dev/loop/0
        swapon /dev/loop/0
}

start() {
        config_load "swap"
        config_foreach start_service swap
}

stop() {
        swapoff /dev/loop/0
}

4. Make the init script executable
chmod +x /etc/init.d/swap

5. Enable the swap space, by default a swap space with  1MiB on /tmp in the ramdisk will be created.
/etc/init.d/swap enable
/etc/init.d/swap start

6. You can change a few parameters using UCI.
OPTION      DEFAULT VALUE    DESCRIPTION
path        /tmp             Location where swap file will be stored.
filename    swapfile         Name of the swap file.
size        2000             Size in blocks: 1000 blocks = 512 Kbytes | 1 Megabyte = 2000 blocks

E.g. to change to location of the swap file to your USB pen drive and  change the size of the swap space to 256MiB do:
uci set swap.cfg1.path=/mnt/usb
uci set swap.cfg1.size=512000
uci commit swap
/etc/init.d/swap restart

7. With the 'free' command you can check the swap space  usage...
              total         used         free       shared      buffers
  Mem:        30512        13856        16656            0         1316
 Swap:          992            0          992
Total:        31504        13856        17648

You've read the post. What's next?

If you like this post, I meant REALLY like it, then consider bookmarking or help us promote it. Many thanks.

Share and Enjoy:
  • Twitter
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Live
  • PDF
  • Reddit
  • Technorati
  • Yahoo! Bookmarks
  • Print
  • email
  • RSS
  • StumbleUpon

Related posts:

  1. Mini Ad Spot v1.4 Joomla Module