Making Swap

This post has already been read 26718 times!

In my quest to speed up the 770 (I think that by loading my bookmarks and RSS feeds I’ve crushed it- it’s just so slow now that it’s mostly unusable) I ran across a link in the comments here to a post on the users list about enabling swap on the MMC, and how that could help processes in the poor 770.

So here is my output, enabling 32Megs of swap on my 1G MMC, starting from a terminal on my Mac.
Note: you have to do this every time you reboot of course.

blinky:~ dillera$ ssh user@192.168.251.53

BusyBox v1.00 (Debian 2:20041102-11) Built-in shell (ash)
Enter 'help' for a list of built-in commands.

processing andy mods
done
~ $ sudo gainroot
Root shell enabled

BusyBox v1.00 (Debian 2:20041102-11) Built-in shell (ash)
Enter 'help' for a list of built-in commands.

/home/user # dd if=/dev/zero of=/media/mmc1/extraswap bs=1024 count=32768
32768+0 records in
32768+0 records out
/home/user # mkswap /media/mmc1/extraswap 32768
Setting up swapspace version 1, size = 33550336 bytes
/home/user # swapon /media/mmc1/extraswap

The 5 min result: swap seems to be helping, as I am now able to run a browser, the bookmarks app and the RSS reader and they are not making me wish I had a pocketpc…..

9 thoughts on “Making Swap

  1. […] At the same time, I will likely create a swap file in this partition too, which people have reported makes their system run more stably and faster. The itT FAQ page on swap cites Andy Diller writing at The Synching Apple as the originator of this notion (the initial post there points to a comment in the Maemo Users list about enabling swap). A thread here at itT forums, “Swap space on RSMMC card?“, contains more material on this. […]

  2. […] I followed the instructions given in this blog, and added a swap file on my removable card to try to improve the perfomance of the system. […]

  3. rich

    Some info here on swap files/ partitions on the Zaurus

    http://www.pdaxrom.org/index.php?showid=43&menuid=8

  4. Geoff

    Well, most of the mmcmobile cards I find seem to be specced for more like 100,000 erasures, but whatever. It’s kind of worth it. The partition method is very clever! I’ll have to give it a shot once I get a card reader.

    Oh — and yeah, I crashed my 770 by USB-plugging the device while I had the swap running. Took me a minute to realize what had happened, but the card/device were okay.

  5. And- thanks Tommy for that vastly improved idea regarding swap partitions- I forgot what the USB does to the 770’s MMC (since I use ssh via wifi mostly these days).

    I’m going to use your method to keep my swap on its own partition.

  6. I’m not so sure that this is that much of an issue with the 770. If you had a regular desktop or workstation, perhaps you’d wear it out in a year or so (they are capable of millions of writes I think) , but on the 770– I don’t think there is that much activity. It’s not like you are using it as a workstation…..

    And with prices dropping, and capacity increasing, in 1 or 2 years you can just toss it and get the 16G RSMMC card for $20. :)

    Here is some info about the NAND memory you find on these cards:
    http://en.wikipedia.org/wiki/Flash_memory

  7. Geoff

    Agreed — using the swap file helps me tremendously. Why, oh why didn’t they put 128mb in the 770?

    The catch appears to be this: according to Karoliina, using flash memory as swap will wear out your flash pretty quickly, as flash memory has a limited number of write/erase cycles (I assume, for each bit) before it goes dead.

    So the question is this: can somebody who knows the mechanics of Linux virtual memory better than I do the math on exactly *how* quickly this will wear out your flash? I’d hate to get a 1GB mmcmobile card and kill it in a week just because I like having several windows open.

  8. Tommy Cheng

    Thanks for the info. Enabling some swap space really improve stability and performance a lot, now I can run opera, email, videoplayer, rss reader and FBReader all at once without any noticeable slowdown(thank god). So after playing a little with the swap file on mmc card, I dig into the system to make a more premanent hack.

    With the above mentioned swap file method, I see 2 issues that I want to avoid: 1) having to reapply the mod manually each time the 770 boots; 2) when the 770 is connected to a PC via the USB cable, the mmc card is automatically unmounted and that seems like a very dangerous thing to do when the swap file is still in use. So here’s what I did in case anyone is interested.

    1.) Prepare the MMC by re-partitioning it into 2 partitions, partition1 for normal data and partition2 for swap. In my case, 46MB for partition1 and 16MB for partation2 (I am still using the factory 64MB mmc). I’ve done this using fdisk on a Linux box

    2.) Format partition1 using FAT16 and leave the 2nd one alone.

    3.) Insert the MMC back into the 770 and log in using SSH, and do the following:

    ~ $ sudo gainroot
    Root shell enabled
    
    
    BusyBox v1.00 (Debian 2:20041102-11) Built-in shell (ash)
    Enter 'help' for a list of built-in commands.
    
    /home/user # ls /dev/mmc*
    /dev/mmcblk0    /dev/mmcblk0p1  /dev/mmcblk0p2
    /home/user # echo '#!/bin/sh' > /var/lib/install/etc/init.d/mmcswap.sh
    /home/user # echo '#' >> /var/lib/install/etc/init.d/mmcswap.sh
    /home/user # echo 'if [ -e /dev/mmcblk0p2 ] ; then' >> /var/lib/install/etc/init.d/mmcswap.sh
    /home/user # echo '  mkswap /dev/mmcblk0p2' >> /var/lib/install/etc/init.d/mmcswap.sh
    /home/user # echo '  swapon /dev/mmcblk0p2' >> /var/lib/install/etc/init.d/mmcswap.sh   
    /home/user # echo 'fi' >> /var/lib/install/etc/init.d/mmcswap.sh
    /home/user # more /var/lib/install/etc/init.d/mmcswap.sh
    #!/bin/sh
    #
    if [ -e /dev/mmcblk0p2 ] ; then
      mkswap /dev/mmcblk0p2
      swapon /dev/mmcblk0p2
    fi
    /home/user # chmod +x /var/lib/install/etc/init.d/mmcswap.sh
    /home/user # ln -s /var/lib/install/etc/init.d/mmcswap.sh /etc/rc2.d/S27mmcswap.sh
    /home/user #
    
    

    4.) Reboot and enjoy.

    Now you get a swap upon boot-up that won’t be affected when the USB cable is plug-in. Also, if you insert a normal MMC(only 1 partition), the 770 will boot as normal, the only adverse affect is that you don’t get the swap. There is one caveat thou, the 770 needs to be turn off if you want to change/eject the mmc card.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.