Swap: Difference between revisions

From OLPC
Jump to navigation Jump to search
No edit summary
(Add recipe for swapping to SD card)
Line 1: Line 1:
Swap on SD is currently is broken. The XO currently force-unmounts the SD card at suspend, which loses the swap file and breaks all applications that touched the swap, most notoriously X11.
Swap on SD cards is broken in many XO software releases. When the bug is present, the XO forcibly unmounts the SD card at suspend, which loses the swap file, and breaks all applications that touched the swap, most notoriously X11. It also often overwrites the first blocks of your SD card with zeros or gibberish, which makes them no longer work until you reformat them entirely. NOT FUN!

The SD suspend bug(s) are fixed in Joyride releases 2263 and later (maybe others) and in Build 710 or later of the preceding
releases. Having the bug fixed allows an SD card to be used as swap space (for demand paging), making your small RAM seem larger and your XO more responsive.

The recipe below WILL NOT WORK if you have the XO's original software release, or the "Update.1" release. Use at your own risk!

== How To Swap (Page) To An SD Card ==

Use a recent joyride software release (this requires getting your XO a [[Activation and developer keys|developer key]], which is a good idea anyway since it unlocks your machine and puts you in control of it). Get a throwaway 1GB SD card. Available for
$3-$20 depending where you go. I say throwaway because swapping to it
will tend to burn it up faster than its "usual" lifetime for photos
and such. You will still be able to use half a gig on the card for
file storage; the other half will be for swap space. Plug it into the
SD card slot on the XO. You'll have to keep it plugged in the whole
time while you're swapping to it; you can't remove it the way you
remove a USB stick or a non-swap SD card. If/when it starts to fail
after a few years, you can copy any still-interesting user files off
it, throw it away, and put in a new $1 1GB SD card (or something
larger).

Go to a terminal (either the Terminal activity, or Ctrl-Alt-F1). Become root.
Type "<tt>mount</tt>", make sure the SD card is mounted at <tt>/dev/mmcblk0p1</tt>,
in a "vfat" filesystem.

Go into the Journal, find the SD card hiding behind the Frame at the
bottom, hover over it, pick Unmount. Go back to the terminal.

Type "<tt>mount</tt>", make sure <tt>/dev/mmcblk0p1</tt> is not mounted any more. Type
"<tt>yum install parted</tt>" since the partition editor is not in the distro
any more (you'll need to be on the Internet to do this). Run "<tt>/sbin/parted /dev/mmcblk0</tt>". Type "<tt>print</tt>" to see the
current configuration. On mine it looked like this:

Number Start End Size Type File system Flags
1 127kB 1018MB 1018MB primary fat16

Type "<tt>resize 1 0 512</tt>" to shrink this filesystem down to 512MB. If it
asks you whether to use FAT32, just say no. Then type "<tt>mkpartfs
primary linux-swap 512 1018</tt>". That'll make a second partition for
swapping to, and format it as a Linux swap partition. (If your SD card is a different
size, adjust these numbers to give you larger or smaller partitions that fit.) Type "<tt>print</tt>"
and it should look roughly like this:

Number Start End Size Type File system Flags
1 32.3kB 512MB 512MB primary fat16
2 512MB 1018MB 506MB primary linux-swap

Type "<tt>quit</tt>". Now you're back to the shell. Type "<tt>/sbin/swapon /dev/mmcblk0p2</tt>". You're done.

The Hal daemon is smart enough to mount filesystems when it sees an SD
card appear, but it's not smart enough to start using freshly
available swap space. For the moment, you'll have to do "<tt>/sbin/swapon
/dev/mmcblk0p2</tt>" each time after you reboot the XO. Similarly, it
won't automatically do a "<tt>/sbin/swapoff</tt>" if you try to eject it. I'm sure
somebody will eventually come up with a Hal script or something to
automate those parts.


== Earlier commentary about swapping ==


[[User:Andrew|Andrew]] 14:22, 9 January 2008 (EST)
:Swapping to a partition would overcome this???
:Swapping to a partition would overcome this???



Revision as of 10:18, 11 August 2008

Swap on SD cards is broken in many XO software releases. When the bug is present, the XO forcibly unmounts the SD card at suspend, which loses the swap file, and breaks all applications that touched the swap, most notoriously X11. It also often overwrites the first blocks of your SD card with zeros or gibberish, which makes them no longer work until you reformat them entirely. NOT FUN!

The SD suspend bug(s) are fixed in Joyride releases 2263 and later (maybe others) and in Build 710 or later of the preceding releases. Having the bug fixed allows an SD card to be used as swap space (for demand paging), making your small RAM seem larger and your XO more responsive.

The recipe below WILL NOT WORK if you have the XO's original software release, or the "Update.1" release. Use at your own risk!

How To Swap (Page) To An SD Card

Use a recent joyride software release (this requires getting your XO a developer key, which is a good idea anyway since it unlocks your machine and puts you in control of it). Get a throwaway 1GB SD card. Available for $3-$20 depending where you go. I say throwaway because swapping to it will tend to burn it up faster than its "usual" lifetime for photos and such. You will still be able to use half a gig on the card for file storage; the other half will be for swap space. Plug it into the SD card slot on the XO. You'll have to keep it plugged in the whole time while you're swapping to it; you can't remove it the way you remove a USB stick or a non-swap SD card. If/when it starts to fail after a few years, you can copy any still-interesting user files off it, throw it away, and put in a new $1 1GB SD card (or something larger).

Go to a terminal (either the Terminal activity, or Ctrl-Alt-F1). Become root. Type "mount", make sure the SD card is mounted at /dev/mmcblk0p1, in a "vfat" filesystem.

Go into the Journal, find the SD card hiding behind the Frame at the bottom, hover over it, pick Unmount. Go back to the terminal.

Type "mount", make sure /dev/mmcblk0p1 is not mounted any more. Type "yum install parted" since the partition editor is not in the distro any more (you'll need to be on the Internet to do this). Run "/sbin/parted /dev/mmcblk0". Type "print" to see the current configuration. On mine it looked like this:

Number  Start  End    Size    Type     File system  Flags
 1      127kB  1018MB 1018MB  primary  fat16

Type "resize 1 0 512" to shrink this filesystem down to 512MB. If it asks you whether to use FAT32, just say no. Then type "mkpartfs primary linux-swap 512 1018". That'll make a second partition for swapping to, and format it as a Linux swap partition. (If your SD card is a different size, adjust these numbers to give you larger or smaller partitions that fit.) Type "print" and it should look roughly like this:

Number  Start  End     Size   Type     File system  Flags
 1      32.3kB 512MB   512MB  primary  fat16
 2      512MB  1018MB  506MB  primary  linux-swap

Type "quit". Now you're back to the shell. Type "/sbin/swapon /dev/mmcblk0p2". You're done.

The Hal daemon is smart enough to mount filesystems when it sees an SD card appear, but it's not smart enough to start using freshly available swap space. For the moment, you'll have to do "/sbin/swapon /dev/mmcblk0p2" each time after you reboot the XO. Similarly, it won't automatically do a "/sbin/swapoff" if you try to eject it. I'm sure somebody will eventually come up with a Hal script or something to automate those parts.


Earlier commentary about swapping

Swapping to a partition would overcome this???

Swap on the internal memory doesn't work either, it causes system freezes. Swap doesn't even like attaching to a jffs2 file, but can be forced by using a loopback device. The internal flash chip is only rated for 3000 writes/cell (Remember when flash could take 100,000 writes? Now we're giving that up for density). JFFS2 will try to spread that across the whole chip, even then swap write patterns are likely bad for it. Try the following at your own risk.

su
dd if=/dev/zero of=/var/swap count=128000
/sbin/mkswap /var/swap
#!/bin/sh
if [ `cat /proc/swaps | wc -l` == 1 ] ;then
    loopdev=`su -c "/sbin/losetup -f"`
    su -c "/sbin/losetup $loopdev /var/swap"
    su -c "/sbin/swapon $loopdev"
fi

user:mike41430

The document that the "Hardware specification" page calls the "Definitive Laptop Specification", which is dated 9/13/07, says "The endurance of the NAND device is one hundred thousand erase cycles". The Swap article, with edit dates 12/23-28/07, says the "internal flash chip is only rated for 3000 writes/cell". I do not know which of these statements to believe. Did the "definitive laptop specification" become less "definitive" between 9/13 and 12/23? In particular, I would like to know the endurance rating of the flash memory in my G1G1 XO-1, ordered 11/12/07 and shipped 12/17/07. I also hope that a future release will be fixed so that it will be possible to swap on the built-in SD card slot, or use it as an extension of memory, which seems to be what was intended.