Author Topic: swap drive on SD-card ?  (Read 16324 times)

Muffe

  • Guest
swap drive on SD-card ?
« on: March 12, 2009, 05:56:36 AM »
Under normal conditions i know Linux only with any swap drive. But these LLL's with only 128MB of RAM (where only around 70MB are free) didnt have one - why (or better why not)?
The question is... is it possible to create an swap drive on an SD-card or the NAND-flash that can be used by the OS? Next Question; is it possible to create an ext3 partition on an SD-card, where the OS can be installed?

greetz... Lars

Mijzelf

  • Guest
Re: swap drive on SD-card ?
« Reply #1 on: March 12, 2009, 09:07:12 AM »
Yes, you can generate a swapfile on SD:
Code: [Select]
dd id=/dev/zero of=/SD/SD_1/swapfile bs=1024 count=131072
mkswap /SD/SD_1/swapfile
swapon /SD/SD_1/swapfile
dd and mkswap only need to be called once, swapon on each boot. It should be possible too to create a swap partition on the SD card, using fdisk or something like that, and activate it with swapon.
A problem is that the SD card is awfully slow compared to ram, or even the nandflash.

The reason for not having a ramdisk on this laptop is (I think) because flashmemory is slow on writing, and wears out, and the default distro just *runs* on 128MB.

It is possible to boot from nand2, and I suppose it should be possible to create a kernel which boots from sd.

« Last Edit: March 12, 2009, 09:12:00 AM by Mijzelf »

Mijzelf

  • Guest
Re: swap drive on SD-card ?
« Reply #2 on: March 12, 2009, 09:14:41 AM »
Yes, you can generate a swapfile on SD:
Code: [Select]
dd id=/dev/zero of=/SD/SD_1/swapfile bs=1024 count=131072
mkswap /SD/SD_1/swapfile
swapon /SD/SD_1/swapfile
dd and mkswap only need to be called once, swapon on each boot. It should be possible too to create a swap partition on the SD card, using fdisk or something like that, and activate it with swapon.
A problem is that the SD card is awfully slow compared to ram, or even the nandflash.

The reason for not having a ramdisk on this laptop is (I think) because flashmemory is slow on writing, and wears out, and the default distro just *runs* on 128MB.

It is possible to boot from nand2, and I suppose it should be possible to create a kernel which boots from sd.


utd_grant

  • Guest
Re: swap drive on SD-card ?
« Reply #3 on: March 12, 2009, 11:32:27 AM »
I've heard (anecodotal evidence only...) that using flash memory (SD card or SSD 'hard drive') for a swap space can lead to too many rewrite cycles and premature death. If the system RAM is never going to get max'ed out by the apps you're running on a day-to-day basis, it might be best just to avoid creating a swap drive at all; I certainly don't intend to edit a 30 Megapixel image in GIMP on my LLL.   :D

Muffe

  • Guest
Re: swap drive on SD-card ?
« Reply #4 on: March 12, 2009, 08:14:43 PM »
hmmm... on SD-cards that may be right, but for SSD like the NAND-flash it should not be a problem. I would try to create an swap drive with a size around 256MB on the NAND, but i cant see any drive in the fdisk partition tool. Any ideas for a tool, that supports the partitioning of the NAND?
And... has somebody any solution for installing the OS (or the biggest part of it) on a SD-card?

Mijzelf

  • Guest
Re: swap drive on SD-card ?
« Reply #5 on: March 12, 2009, 08:38:40 PM »
You can't repartition internal flash. The 'partitions' are dictated by uBoot, AFAIK. (have a look at 'cat /dev/mtd')
But you can create a swapfile:
Code: [Select]
dd if=/dev/zero of=/path/to/swapfile bs=1024 count=128*1024
mkswap /path/to/swapfile
swapon /path/to/swapfile

About booting from SD; This page is about booting from nand2, by a kernel patch.

wicknix

  • Guest
Re: swap drive on SD-card ?
« Reply #6 on: March 13, 2009, 04:05:37 AM »
There really is no point for swap. I have yet to use over 70 meg ram on this thing. Thats with firefox having 4 tabs open, xchat running, ip radio streaming and pidgin open. That still leaves 58 meg free should you happen to open even more applications.

I've run firefox on a hp jornada 720 which has a 206mhz strongarm cpu and 32 meg ram. I had created a small 32 meg swapfile for that, and still only touched 12 meg of swap.

As for that general 'theory' that running swap on a ssd is bad due to write cycles... i'm sure its somewhat true, but my jornada has been using the same CF card (which holds the OS and swapfile) for 5 years now. Not a single problem yet.

Cheers.

Muffe

  • Guest
Re: swap drive on SD-card ?
« Reply #7 on: March 13, 2009, 07:33:22 AM »
With 3 tabs in BonEcho, IP-Radio and one or two small programs open there is no RAM left and the system slows down.


but what's that - sometimes there is an Internal Flash to see in the system diagnostic tool (?) - is it an bug in the system tool or is there realy something

Mijzelf

  • Guest
Re: swap drive on SD-card ?
« Reply #8 on: March 13, 2009, 08:30:06 AM »
There are different ways of measuring used memory. The commandline program 'free' gives another number than 'htop'. I think it's because free also counts the filebuffers, while htop doesn't.
Filebuffers can be flushed or just freed when there's lack of memory. It makes no sense to swap them to a swapfile.

wicknix

  • Guest
Re: swap drive on SD-card ?
« Reply #9 on: March 13, 2009, 08:33:10 AM »
That system info applet is inaccurate, and it also causes the fn/shift keys to drop out. Its removed in the upcoming rc2.1. Try the same things again, but use htop (process monitor). I guess it depends on the website you're viewing also as pages with loads of images will eat more ram.

That 'flash' i'm guessing shows up after you use video online? I noticed video online creates a /tmp/minifs directory when i was hexing through the binary awhile back. IP Radio does the same thing. Cheap way of having a slight read ahead buffer. Otherwise no idea.

Cheers.
« Last Edit: March 13, 2009, 08:35:17 AM by wicknix »

Muffe

  • Guest
Re: swap drive on SD-card ?
« Reply #10 on: March 13, 2009, 08:49:26 AM »
No, i did'nt use Video Online bevore. But it seemed, that the system creates itself an temporary "swap"-file with a size of 5MB, if the memory gets to low...
but that feels not enough - after opening one more program, the system gets little lags.

and... i also know that this system info tool "kills" the Fn/Shift-keys ;)

edit...
oh yes, ip-radio may be also the reason - and yes, that can also be an cache or buffer - mem

edit:


...
But you can create a swapfile:
Code: [Select]
dd if=/dev/zero of=/path/to/swapfile bs=1024 count=128*1024
mkswap /path/to/swapfile
swapon /path/to/swapfile


OK, tank you Mijself - i tried this...

Code: [Select]
dd if=/dev/zero of=/swap bs=1024 count=131072created an file of zeros in the main directory, named "swap"
Code: [Select]
mkswap /swap"formats" the file as swap - also no problem
Code: [Select]
swapon /swapgets an error "swapon: /swap: invalid argument", so i had set an entry in the fstab and used
Code: [Select]
swapon -a, that had worked without any errors.

after using the command
Code: [Select]
free there is no swap-memory to see;

                  total
Mem:     126084
Swap:              0

so, what's the problem?
« Last Edit: March 13, 2009, 08:21:14 PM by Muffe »

Muffe

  • Guest
Re: swap drive on SD-card ?
« Reply #11 on: March 13, 2009, 08:09:26 PM »
...
But you can create a swapfile:
Code: [Select]
dd if=/dev/zero of=/path/to/swapfile bs=1024 count=128*1024
mkswap /path/to/swapfile
swapon /path/to/swapfile


OK, tank you Mijself - i tried this...

Code: [Select]
dd if=/dev/zero of=/swap bs=1024 count=131072created an file of zeros in the main directory, named "swap"
Code: [Select]
mkswap /swap"formats" the file as swap - also no problem
Code: [Select]
swapon /swapgets an error "swapon: /swap: invalid argument", so i had set an entry in the fstab and used
Code: [Select]
swapon -a, that had worked without any errors.

after using the command
Code: [Select]
free there is no swap-memory to see;

                  total
Mem:     126084
Swap:              0

so, what's the problem?

Mijzelf

  • Guest
Re: swap drive on SD-card ?
« Reply #12 on: March 13, 2009, 08:41:50 PM »
Strange. I tried you sequence, and it doesn't work for me either.
Then I tried /SD/SD_1/swap, and it works. So I tried /tmp/swap and it doesn't work. Maybe it's impossible to create a swapfile on a yaffs filesystem?

Muffe

  • Guest
Re: swap drive on SD-card ?
« Reply #13 on: March 14, 2009, 11:44:33 AM »
so far, the only way to get an swap-file to work is to create one on the SD-card... this also may be the reason, that these LLLs did'nt support suspend-to-disk. For that feature we need an swap-drive/ -file !
I create (for the moment) an swap-file on SD. So far so good. Activated with
Code: [Select]
swapon /SD/SD_1/swap - first test looks good. If the mainmemory gets full, some small parts will be moved out to the swapfile  :)

Next question for me is, how to activate the swap-file on bootup?
There is no /etc/rc.d/boot.localfs and boot.swap on these machines, entrys in /etc/init.d/start also did'nt work!

Mijzelf

  • Guest
Re: swap drive on SD-card ?
« Reply #14 on: March 14, 2009, 03:36:56 PM »
You can add it to /etc/init.d/rcS