maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Nokia N800 (https://talk.maemo.org/forumdisplay.php?f=25)
-   -   Swap partition size limit and recommendations (https://talk.maemo.org/showthread.php?t=14058)

gnexus 2007-12-29 21:05

Swap partition size limit and recommendations
 
I scoured ITT and the net via Google and couldn't find much info on this subject. So I'm going to start a new thread. Since I'm relatively new here I don't know if this is the best area for the thread, but I don't know where else to put it since it applies to N800/810 and OS2007/2008.

Please note:
Quote:

This thread is not about the standard Nokia FAT swapfile.

This thread is also not for newbies or normal users and is intended for Linux administrators and power users ONLY. What is being discussed in this thread involves major changes to critical parts of the tablet OS which could cause memory corruption, data loss and failure of your SD card. The procedures listed in this thread are not recommended by me, Nokia or most likely anybody else :D
OK, now that the disclaimers are out of the way, here is the question:

I just now set up a swap partition to replace the Nokia FAT swapfile. I have a 2GB internal SD card which was partitioned into two primary partitions. The second partition is formatted as ext2 for a dual-boot setup. The first partition was set up as fat32, but since I have no use or desire for dos partitions I decided to resize it and convert it to a swap partition which wouldn't be dismounted (causing insufficient memory problems) when the tablet is connected via USB. Since I didn't feel like resizing the partition right away, I decided it would be easier just to make the whole 1GB as swap and see if that worked.

So after creating the partition, running mkswap and then swapon I looked to see if it works. Here is the output of free:

Quote:

[root@N800 /root]# free
total used free shared buffers
Mem: 127244 84984 42260 0 4
Swap: 998376 0 998376
Total: 1125620 84984 1040636
So, at least according to free, the tablet now has 1GB additional RAM available for programs! :D

So here is the question for discussion:

What is the optimal size for swap on the N800/810 and what is the max?

Normally the recommended size for swap (for any OS) is
Quote:

[ 1.5-2 * ( total installed memory ) ]
That has always been the standard. In this instance that would be about 256MB. However, in the case of the N8xx the installed memory is very low and the swap device is uber fast. So how does that affect performance. Will there be thrashing problems which will slow things down? Another question for users of big (somewhat expensive and with lots of data) flash cards is about flash reliability. I could care less about that since my card was $10 and the data is just a backup of my rootfs.

gnexus 2007-12-29 21:12

Re: Swap partition size limit and recommendations
 
Just one little observation:

Holy @#%$^ it's a lot faster faster :D

Update:
The speed increase seems to be more related to the swap type rather than size. In its present configuration the tablet seems more contrained by processor speed than memory. I opened up every app on the tablet at once to test swap usage. Even with 20-30 apps and videos and quake running in the background, and 10 mozilla windows open, the swap usage was only 50% of installed memory. Good news was that there was no thrashing and no crashes - except for Quiver trying to find nonexistent pictures

skeezer65134 2007-12-30 01:53

Re: Swap partition size limit and recommendations
 
I actually did the same thing, but with about 128MB of SWAP. I don't really use the rest of the 512 card though, so I could theoretically bump it out. I noticed immediately that things ran way faster than with the swap file on a FAT32 filesystem. I thought the 128MB limit would still apply though, good to know it doesn't ;)

EDIT: I don't know if this has changed, but the tablet doesn't load swap partitions on reboot. There's a nice workaround here. I fixed the script and here it is:

Code:

#!/bin/sh
# workaround an issue with mounting swap partition at startup

SWAPX='/dev/mmcblk0p2'

case "$1" in
 start)
  swapon $SWAPX
 ;;
 stop)
  swapoff $SWAPX
 ;;
 restart)
  swapoff $SWAPX
  swapon $SWAPX
 ;;
 reload|force-reload)
  echo "$0: not implemented"
 ;;
 *)
 ;;
esac

Put that in /etc/init.d/swappart.sh and make it executable (chmod 755 /etc/init.d/swappart.sh). You'll have to change the SWAPX location to match your own setup; the one in my example is for the second partion on the internal card. You'll also need make the file execute on boot by linking it in the startup scripts (ln -s /etc/init.d/swappart.sh /etc/rc2.s/S19swappart). Of course, you'll need to be root for all this to work too ;)

gnexus 2007-12-30 03:45

Re: Swap partition size limit and recommendations
 
Quote:

EDIT: I don't know if this has changed, but the tablet doesn't load swap partitions on reboot.
No, it sure doesn't. . .

I already had a script, however, after scouring the net for a while to find something decent and then making my own ( swap wouldn't do much good otherwise, would it?). I still greatly appreciate your nicer looking one, though. I'll likely take yours, add it to mine and revise it a bit. It would be good if we all got on the same page with the scripts so it could be standardized, posted somewhere to help others, and maybe build a deb. The ideal situation would be to scan for existing swap partitions and mount them automagically. Then you could also have a script for users to create a new one on tablets that haven't implemented it.

A couple of pointers:

1) Linux initscripts don't need or use .sh extensions.
2) 'swapon -a' mounts any swap partitions defined in fstab

But first we need to know what the optimal size is, and that's what this thread is for!

Come on people, what's the optimal size for the swap partition when running OpenOffice, KDE and Mplayer all at the same time. ;)

TA-t3 2007-12-30 17:47

Re: Swap partition size limit and recommendations
 
Note that the old "swap size should be at least 2xRAM size" advice only applies to those Unix systems where RAM is mapped to swap, that is, if you have X size RAM you _must_ also have X size swap, and then your virtual memory (VM) is still just X. Only when you add even more swap will your VM get extended.

There are only a few such systems left out there (AIX 4.x was one I think). Linux is not one of them. For Linux, the rule is: "The more RAM you have the less swap you'll need". As 128MB RAM isn't that much it's helpful with some amount of swap. But if you add too much (say, 4-5-6 times RAM size) you may experience that things actually slow down after a while, because lots of application data/code may have been pushed out to swap over the weeks (if you leave applications up and running). I haven't experimented on my N800 yet, but to start with I think I would limit myself to 512MB swap, and probably begin with just 128MB or 256MB.

gnexus 2007-12-30 17:57

Re: Swap partition size limit and recommendations
 
Thanks for the post. You are quite correct.

I just used the old rule since it was easy to post. I used 1GB as a starter because I'm lazy and the partition was already there. I've since reduced it down since it had no benefit and I needed the extra space.

Quote:

But if you add too much (say, 4-5-6 times RAM size) you may experience that things actually slow down after a while, because lots of application data/code may have been pushed out to swap over the weeks (if you leave applications up and running).
That doesn't seem to happen with the N800 for some reason. It's actually quite difficult to get it to use the swap. Maybe thats a kernel config issue. I haven't had it up with swap for weeks yet, however. . .

JeffElkins 2007-12-30 18:01

Re: Swap partition size limit and recommendations
 
I have an internal 8Gb card formatted as ext3. I created a 128Mb swapfile and activate it from /etc/init.d/rcS by adding the command: swapon -a /swapfile. I don't know of any advantages for a separate swap partition for the N800. Am I mistaken?

TA-t3 2007-12-30 18:21

Re: Swap partition size limit and recommendations
 
A swap partition should in principle be faster than a swap file, because with a swap partition the kernel memory management system writes directly to the partition while with a swap file it'll have to go through the filesystem driver and then to the partition the file resides on (longer code and data paths)

fanoush 2007-12-30 18:48

Re: Swap partition size limit and recommendations
 
Quote:

Originally Posted by TA-t3 (Post 117886)
A swap partition should in principle be faster than a swap file, because with a swap partition the kernel memory management system writes directly to the partition while with a swap file it'll have to go through the filesystem driver and then to the partition the file resides on (longer code and data paths)

AFAIK for linux (2.6 at least, maybe 2.4 too) there is no difference. Even with swap file direct device access is used. When swap to file is enabled the file is scanned and logical to physical mapping is done. Apart from speed this solves also deadlocks when filesystem (with swap file) needs to allocate memory.

If file is fragmented there may be some (insignificant?) overhead though. See dmesg log about number of extents when swapon is run.

TA-t3 2007-12-30 19:04

Re: Swap partition size limit and recommendations
 
Ah, thanks for the updated info. When swap-to-file was introduced it was an issue (and at least through the 2.2 series, not sure about 2.4 because I didn't use swap-to-file there).

Do you know if this is still true with a FAT32 file system? In principle it should, because an application like the LILO loader does the same kind of mapping you describe. But in an earlier post skeezer reported that there was a noticable difference ("way faster").

fanoush 2007-12-30 19:49

Re: Swap partition size limit and recommendations
 
Quote:

Originally Posted by TA-t3 (Post 117902)
Ah, thanks for the updated info. When swap-to-file was introduced it was an issue (and at least through the 2.2 series, not sure about 2.4 because I didn't use swap-to-file there).

did a search and it is 2.6 only
http://en.wikipedia.org/wiki/Paging#Swapping_in_Linux
Quote:

Originally Posted by TA-t3 (Post 117902)
Do you know if this is still true with a FAT32 file system? In principle it should, because an application like the LILO loader does the same kind of mapping you describe. But in an earlier post skeezer reported that there was a noticable difference ("way faster").

Not sure about this but I think it doesn't require any fancy features from the filesystem. Any normal (i.e. block based) filesystem should allow this.

BruceL 2007-12-30 20:04

Re: Swap partition size limit and recommendations
 
Could the "way faster" be because of the 1gb of swap space?

lazuli 2008-07-29 12:29

Re: Swap partition size limit and recommendations
 
Quote:

Originally Posted by gnexus (Post 117464)
Just one little observation:

Holy @#%$^ it's a lot faster faster :D

Update:
Even with 20-30 apps and videos and quake running in the background, and 10 mozilla windows open, the swap usage was only 50% of installed memory.

sorry for bumping an old thread but has anyone tried this with diablo? im interested in putting a dedicated 1 gig memory card solely for swap if the performance increase is significant. :)

dan 2008-07-29 13:56

Re: Swap partition size limit and recommendations
 
I'm a newbie at swap and when I got a 32gb card several weeks ago I decided to add Diablo and dual boot from Penguinbait along with KDE. I decided to add swap feature from PB's list of options on dual boot menu. I put aside 1gb for swap. I did notice that speed of loading of apps and how many apps I could run at the same time was tremendous. I no longer have crashes on apps like Quiver. When I added Debian I put it on same card as swap and have been having trouble with loading apps int Debian. No such problems on Hildon side. Apps load fine and behave properly. It keeps telling me that I've run out of devise space. Anyone have any expertise or experience with this? My other question is do I need to use gnexus fix to use swap partition properly? Any help, guidance or advise would greatly be appreciated. TIA, Dan

Edit: Solution do not put Debian in a card that has swap partition. Major problems with Debian if you do.

Ricky-Lee 2008-08-08 20:27

Re: Swap partition size limit and recommendations
 
Is there a way to add swap to a internal booting mmc clone with deablo if this will speed things up an stop the mem probs I would really like to know :) thanks

gnexus 2008-09-01 22:33

Re: Swap partition size limit and recommendations
 
Quote:

Originally Posted by dan (Post 208198)
I put aside 1gb for swap. When I added Debian I put it on same card as swap and have been having trouble with loading apps int Debian.
Edit: Solution do not put Debian in a card that has swap partition. Major problems with Debian if you do.

I'm not sure which "fix" of mine you are referring to. I simply set up swap as in a normal Linux install. I'm using Debian on a partition which is on the same card as the swap, and haven't had any problems, but I haven't had time to try and add any apps to it yet. Since having swap and data on the same interface can create data transfer bandwith bottlenecks your solution is a good one. I always put a swap partition on every SD card I use (as the first partition on the internal card, and the last partition on external card).

I have found that, unfortunately, flash-based devices seem unable to take good advantage of large amounts of swap memory. So currently I'm using 256MB. Unfortunately even that seems to be excessive, since I've never seen a flash-based device take advantage of anything over say 100MB.

But then again with the size of the new SD cards memory is cheap, so it never hurts to have way too much. 1GB, however, is probably way too excessive.

You must also remember that using swap will wear out the flash very quickly, so always have a backup of any data on your SD card. It would probably also be best to put the swap on a smaller and less expensive SD card, just in case it dies. . .


All times are GMT. The time now is 13:28.

vBulletin® Version 3.8.8