KeithSloan
Posts: 321
Joined: Tue Dec 27, 2011 9:09 pm

Re: Paging and swapping to SD card.

Sat May 12, 2012 11:58 am

Don't have a Raspberry Pi so please excuse my ignorance but.

Am I right in understanding that the various Linux distributions are set up to page and swap to the SD card. ( After all by default, what else is there that one could page/swap to).

What is the long term prognosis for the SD card? Do they have a limit on the number of read/write cycles? Reminds me of a certain AIX system that was setup to do transaction logging to a DAT tape and the number of read/writes exceeded the recommended maximum within a month. ( Needless to say it was changed to disk logging.)

How much do SD cards vary in their performance.

Jancis
Posts: 25
Joined: Thu Jan 26, 2012 3:54 pm

Re: Paging and swapping to SD card.

Sat May 12, 2012 1:35 pm

i had this swap area on sd card, but it was unused (commented out in /etc/fstab). when I manually turned it on "swapon /dev/mmcblk0p3", it took LONG time to finish. I see why it's commented out - it hangs on this during boot, so it's turned off.

because I use raspi with external drive which has swap partition on it, i use swap partition on external drive and swapon command takes a split second to finish.

i guess swapping on sd isn't such a good idea, you have to watch out for memory usage.

4Gb MicoSD SDHC dd if=/dev/zero of=/tmp/output.img bs=8k count=8k; rm /tmp/output.img
8192+0 records in
8192+0 records out
67108864 bytes (67 MB) copied, 19.1604 s, 3.5 MB/s

vs 320Gb external HDD - http://reviews.cnet.com/extern.....98371.htmldd if=/dev/zero of=/mnt/output.img bs=8k count=32k; rm /mnt/output.img
32768+0 records in
32768+0 records out
268435456 bytes (268 MB) copied, 10.7822 s, 24.9 MB/s


SamuelDebruyn
Posts: 20
Joined: Sat Jan 21, 2012 5:04 pm
Contact: Website

Re: Paging and swapping to SD card.

Tue May 29, 2012 8:47 pm

How did you activate the swap partition on your HDD in Debian? I know how to create partitions but now how to set Debian to use it automatically on boot.

shirro
Posts: 248
Joined: Tue Jan 24, 2012 4:54 am

Re: Paging and swapping to SD card.

Wed May 30, 2012 12:05 am

I use a swapfile and have vm.swappiness=10 in /etc/sysctl.conf. That number could go higher or lower (probably should be lower). The top is 100 which is very swappy. Swapping on SD is a bad idea for many reasons. It is slow, there is wear on your card. But if you can make your machine swap only when it absolutely needs to it isn't so bad. The trick is not to go overboard using too much memory. The swapfile is there to get you out of trouble compiling a big project or to shift some idle stuff out of memory if you are crazy enough to open Firefox - it isn't there to give you 1G of virtual memory and magically turn your Pi into a new computer.

The kernel option to let you monitor swapping is turned off in the default kernel but you can use the debug kernel or compile your own (CONFIG_VM_EVENT_COUNTERS=y) and use a program like vmstat to see how much swapping is going on and when. It will give you more of a sense of what is going on and why it is slowing down and when.

To create my swapfile I dd the file, mkswap on it, then add it to my fstab. You can google the details. There isn't any real difference in performance between a swapfile and partition and a swapfile is more flexible.

Ideally you want to move your swap off the sd card and onto a usb storage device.

SamuelDebruyn
Posts: 20
Joined: Sat Jan 21, 2012 5:04 pm
Contact: Website

Re: Paging and swapping to SD card.

Wed May 30, 2012 12:27 am

Hi

Thank you for your answer, I appreciate it.

What does this value in your settings do?
I enabled my swap partition and rebooted (without that setting). But my system became very slow (50 MB in swap, system load above 6).

shirro
Posts: 248
Joined: Tue Jan 24, 2012 4:54 am

Re: Paging and swapping to SD card.

Wed May 30, 2012 12:45 am

vm.swappiness controls how aggressively the kernel swaps. If you look at your memory usage with the free command you will see cache and buffers which are used to increase the speed of disk access. Reducing swappiness will cause the kernel to prefer to drop some of those and use their memory for your apps rather than swap stuff out.

cat /proc/sys/vm/swappiness will show you the current setting. You can echo 5 > /proc/sys/vm/swappiness (as root) to try a setting temporarily but to have it apply on boot you need to put an entry in /etc/sysctl.conf or as I do have a file of raspberry pi teaks in /etc/sysctl.d.

swappiness defaults to 60 out of a maximum of 100. You want it much lower on the Pi as swap should really be a last resort due to the slowness of sd cards. If you are swapping to a usb hard drive or something then it isn't so much of an issue.

If you change the setting you may want to run some memory hogs and look at performance and have something like vmstat 2 running in a terminal to see what is going on but you need a custom or debug kernel to get the swap and block i/o numbers at the moment.

Return to “Beginners”