delicious-pi
Posts: 20
Joined: Thu Mar 15, 2012 8:49 pm

Re: Linux swap partition

Fri Mar 16, 2012 10:31 am

Being quite new to linux, i have been reading up on terms aswell as other things.

One thing i have come across is the linux swap partition. As far a i know its a performance booster for the ram department. Read in numerous places that it is good to mirror the amount of ram you have eg. 256mb partition will suit hardware with 256mb ram.

The debian image on my SD card shows a swap file in gparted, however the fedora remix does not. Will it be created on first boot? (with image resizing etc..) Or is it even needed?

Any general info on the swap partition is appreciated.

User avatar
piglet
Posts: 900
Joined: Sat Aug 27, 2011 1:16 pm

Re: Linux swap partition

Fri Mar 16, 2012 10:48 am

I thought swap on SD cards wasn't a great idea.  Will be interested to read an expert opinion.

User avatar
jojopi
Posts: 3078
Joined: Tue Oct 11, 2011 8:38 pm

Re: Linux swap partition

Fri Mar 16, 2012 10:54 am

delicious-pi said:

As far a i know its a performance booster for the ram department.
Swap does not improve performance in most cases.  It stops your applications from crashing the instant you run out of physical RAM, and makes them run very slowly instead.

The fedora remix does not use a swap partition.  The Seneca wiki includes instructions for making a swap file instead.  There is only room to do this if you use a 4GB or bigger card.

http://zenit.senecac.on.ca/wik.....Swap_Space

Kernel
Posts: 395
Joined: Sat Mar 03, 2012 12:53 pm

Re: Linux swap partition

Fri Mar 16, 2012 10:58 am

It also says:


since the advisability of swapping to SD is debated


and from this topic: http://www.raspberrypi.org/for.....xip-kernel

shirro said:


Best to think of the SD card as a hard disk - just one with a limited number of writes in its lifetime and negligible seek time. Don't use filesystems designed for ROM/flash. Keep it simple with something like ext2 as the SD card does stuff like wear levelling. You probably don't want a journalling fs or swap if you want the card to last.


hyena
Posts: 44
Joined: Mon Nov 14, 2011 7:55 pm

Re: Linux swap partition

Fri Mar 16, 2012 11:09 am

the pi only has 256mb of ram, like the hacked ARM iconnect i have .. mine has been running a lightweight debian CLI and runs squeezebox server and minidlna server for a couple of years 24/7 and the swap makes a big difference performance wise .. in terms of wear levelling by the swap on the SD card .. the sd or usb stick should outlast the life of the device (pi) .. i say go for it and try it .. ive just got an 8GB 30mb/s sandisk sd card for a tenner on play.com and a cheap sd card is less than a fiver so

you also might want to get in to the habit of doing regular backups of the sd card .. if youre a PC user theres a great simple little usbstick  backup/restore program  a lot of people (and me) use on the plug scene which will be fine for the pi's sd card (with a usb card reader) as well im sure .. remember to right click and select run as admin (i didnt read the instructions first and could work out why it wasnt seeing the usb drive)

http://www.alexpage.de/softwar.....tool-1-58/

hope it helps

ian

User avatar
ArborealSeer
Posts: 300
Joined: Tue Jan 24, 2012 9:48 am
Location: South West, UK

Re: Linux swap partition

Fri Mar 16, 2012 11:12 am

windows readyboost probably shows the pro's / con's of using these types of storage as swap

http://en.wikipedia.org/wiki/ReadyBoost
Pi Status > Farnell, Arrived 24/5- RS, Arrived 1/6

delicious-pi
Posts: 20
Joined: Thu Mar 15, 2012 8:49 pm

Re: Linux swap partition

Fri Mar 16, 2012 11:21 am

Some really helpful people here, thanks guys. Ian, that post was really imformative, cheers! ill have a look at tool you posted.

bredman
Posts: 1415
Joined: Tue Jan 17, 2012 2:38 pm

Re: Linux swap partition

Fri Mar 16, 2012 11:26 am

Note that ReadyBoost has nothing at all to do with swap, so please ignore it.

ReadyBoost is a flash cache for a magnetic hard disk.

hyena
Posts: 44
Joined: Mon Nov 14, 2011 7:55 pm

Re: Linux swap partition

Fri Mar 16, 2012 12:26 pm

p.s.  ... when you create the swap and put the relevant entries in the fstab file  dont forget to check the swap is activated properly on boot ...

just enter the top command and you will see if any swap is being used

from recollection you can also use the swapoff and swapon commands to easily test the effect of having swap off and on

rgds

ian

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Linux swap partition

Fri Mar 16, 2012 2:21 pm

A modern Linux doesn't need swap - unless it's really short on RAM... Which is the case on the RPi... So a little bit of swap isn't going to do you any harm at all.

The question then a swap partition or file? Fro a performance point of view, there really is no discernable difference to using a file over a partition - unless the partition is on a separate physical device (for example, but you can still do that with a file). I perfer a partition because that's the ay I've been doing it for more years than I care to remember, but...

Now with SSDs that support the TRIM instruction, there *may* be an advantage to using a file, and periodically deleting the file - assuming you have a new enough kernel and are using ext4. Then Linux should send TRIM instructions to the SSD which will let it free-up those blocks and add them back into the SSDs wear-levelling free block list...

Then question now is; Does an SD card support TRIM? A quick google suggests that they don't )-: However it still might be advantageous to delete it and re-create it from time to time to move it to different physical sectors if you're concerend about wearing out the SD card. (actually, I'd create a new one first, then delete the old one if I had the space - going through the sequence of create new,  swapoff, adjust /etc/fstab, swapon to move to the new swap file. Actually, you could add in the 2nd one, then swapoff the first one if your system really won't run without swap.

Gordon
--
Gordons projects: https://projects.drogon.net/

hyena
Posts: 44
Joined: Mon Nov 14, 2011 7:55 pm

Re: Linux swap partition

Fri Mar 16, 2012 4:57 pm

remember SD manufacturers cards that use A grade memory in the sd card will (in terms of write cycles) last much longer 10-50x  .. so the samsungs, sandisks of this world higher end sd cards

you have wear levelling and bad block replacement as well on these sd cards which also make things a lot better

remember though youre talking about a £5-10 card not a £100 hard drive .. if it worries people that much after a year bin the sd card and get another ... its nothing to get excited about IMHO

what you should make sure you do is take a regular image backup of the sd card  (ive p[osted a link to a very simple and its proven for me an excellent pc usb stick/sd card image backup tool

i have found this simple method of backing up images invaluable when playing around with linux (if i cock it up i just restore the image) .. i cocked up setting up a compiling environment several times and it was a godsend to restore the image pre cockup than try and clean up my mess

also theres a good bit of of sparcity in the image backups and you may find that if you RAR the disk image file after you have backed the sd card up it will compress to a fraction of its unRAR'd size ... i'm using 8GB sticks so i have a lot more sparcity as theres a lot more unused space

hope it helps

rgds

ian

SANGER_A2
Posts: 59
Joined: Sun Mar 04, 2012 7:39 pm
Contact: Website

Re: Linux swap partition

Tue Mar 20, 2012 10:20 am

I was planning on having an 8GB USB key plugged in permanently. I've made a 1GB swap partition on that so whichever SD card I have plugged in to my PI (I have three), they can use it. USB must be faster than USB for read-write - especially as it's a separate device. When preparing my SD cards I deleted the SWAP partition on Debian and just increased the root size partition.

Am I wrong here???

I was going to use the other 7GB of the USB for the home folder/storing files etc. I'll have  three folders on it like "debian-home", "fedora-home" etc in case they overwrite files. I don't have a Pi yet so I have no idea how well this will work in practice.

I'm also still undecided whether to leave the partition as FAT32 so I can read/write to it on my Windows machines or switch to EXT3.

User avatar
grumpyoldgit
Posts: 1452
Joined: Thu Jan 05, 2012 12:20 pm

Re: Linux swap partition

Tue Mar 20, 2012 10:37 am

I'm not sure why you are complicating matters by having multiple operating systems writing to a single partition on a separate stick or why you thought that was better than leaving the images alone. My initial thoughts are that you will have the wrong card in at the wrong time and overwrite the wrong files. I have Linux computers with external ext4 HD but if I have a film or music files that I want to use elsewhere I just copy the files to a FAT32 stick.

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Linux swap partition

Tue Mar 20, 2012 10:41 am

SANGER_A2 said:


I was planning on having an 8GB USB key plugged in permanently. I've made a 1GB swap partition on that so whichever SD card I have plugged in to my PI (I have three), they can use it. USB must be faster than USB for read-write - especially as it's a separate device. When preparing my SD cards I deleted the SWAP partition on Debian and just increased the root size partition.

Am I wrong here???

I was going to use the other 7GB of the USB for the home folder/storing files etc. I'll have  three folders on it like "debian-home", "fedora-home" etc in case they overwrite files. I don't have a Pi yet so I have no idea how well this will work in practice.

I'm also still undecided whether to leave the partition as FAT32 so I can read/write to it on my Windows machines or switch to EXT3.



Guessing you mean USB faster than SD... I really don't know though - I'd sort of expect SD to be faster myself... You won't need much swap - my expeirences with the QEMU system and 192MB of RAM and no swap have been OK so-far, and although I've run up X, I've not tried to run up a browser - I'm just compiling and running my BASIC interpreter and poking stuff to my Arduinos from it.

And I don't have any Windows machines, so using ext4 (not three!) is my choice, although I understand the boot partition of the SD card must be FAT32. I'd probably be incluned myself to use a bigger SD card with swap, but I also will be NFS mounting partitions from my home/office server on it for development work - possibly not an option for you, but you should be able to mount a windows share if CIFS is in the kernel.

you could have several partitions - the main Linux one ext3/4 and a separate FAT32 one for copying files to/from your Win box. You could even run Samba on the RPi and mount a directory on the SD card on your Win machine, so do it the other way round

It's just another Linux box, although one with somewhat limited resources!

Gordon
--
Gordons projects: https://projects.drogon.net/

XAPBob
Posts: 91
Joined: Tue Jan 03, 2012 2:40 pm

Re: Linux swap partition

Tue Mar 20, 2012 12:21 pm

On more powerful machines I've seen people set up a ram disk (i.e. dedicate some RAM as an ultrafast disk partition) which is then compressed and used as swap space.

That increases the total memory available, at a much lower latency than disks (at the time SSDs weren't common, but it might still be true) at the expense of some CPU time.

Now CPU time on the RPi probably isn't cheap enough to warrant that behaviour...

Under most unixes (possibly windows, although I don't know) the kernel will start to kill processes when it is really running out of memory...

That can trigger some fun bugs

User avatar
hayesey
Posts: 78
Joined: Mon Nov 28, 2011 12:46 pm
Location: Manchester, England

Re: Linux swap partition

Tue Mar 20, 2012 12:45 pm

XAPBob said:


On more powerful machines I've seen people set up a ram disk (i.e. dedicate some RAM as an ultrafast disk partition) which is then compressed and used as swap space.

That increases the total memory available, at a much lower latency than disks (at the time SSDs weren't common, but it might still be true) at the expense of some CPU time.


I am misunderstanding something here?  They are using extra RAM as a tmpfs swapfile?  Erm, why not just use the extra RAM as RAM?  Or is it the compression that is the reason?  Is this any faster than just using an uncompressed, fast disk as swap (I guess it must be or they wouldn't bother)?

SANGER_A2
Posts: 59
Joined: Sun Mar 04, 2012 7:39 pm
Contact: Website

Re: Linux swap partition

Tue Mar 20, 2012 3:45 pm

XAPBob said:


On more powerful machines I've seen people set up a ram disk (i.e. dedicate some RAM as an ultrafast disk partition) which is then compressed and used as swap space.

That increases the total memory available, at a much lower latency than disks (at the time SSDs weren't common, but it might still be true) at the expense of some CPU time.


This sounds like an unusual use of a RAM disk. Sacrificing CPU-time to compress/decompress your data must slow the system down a LOT! Normally, RAM disks are just used if you have loads of free memory and want to speed up something that needs a lot of disk reads/writes (eg a game) without having an SSD. There used to be a UnrealTournament demo you could get on a bootable CD that gave you the option to copy all the files to a RAM disk instead of reading them from the CD and this made it run much quicker.

SANGER_A2
Posts: 59
Joined: Sun Mar 04, 2012 7:39 pm
Contact: Website

Re: Linux swap partition

Tue Mar 20, 2012 3:45 pm

Grumpyoldgit said:


I'm not sure why you are complicating matters by having multiple operating systems writing to a single partition on a separate stick or why you thought that was better than leaving the images alone. My initial thoughts are that you will have the wrong card in at the wrong time and overwrite the wrong files. I have Linux computers with external ext4 HD but if I have a film or music files that I want to use elsewhere I just copy the files to a FAT32 stick.


They aren't going to be running at the same time! I can't see it causing any harm. Each SD card will automatically mount it's \home folder to /dev/hda2/debian-home or whatever so it won't be dependent on me doing anything apart from the initial setup. Then I can access the files I create no matter which SD card I am using (I only have 2GB cards so not a lot of room to spare for user files). I will not use the SAME folder on the USB for \home - each OS will have it's own uniquely named folder.

User avatar
fodi
Posts: 112
Joined: Wed Mar 14, 2012 9:03 pm
Location: Hungary

Re: Linux swap partition

Wed Mar 21, 2012 8:43 pm

what you think about using microdrives for swapping?

they have not a bad price and afaik they are hdd's with a cf adapter, so they can take a lot of writing on them, and with a decent usb cf card reader they should have normal speed

i'm thinking about something like this:


User avatar
grumpyoldgit
Posts: 1452
Joined: Thu Jan 05, 2012 12:20 pm

Re: Linux swap partition

Wed Mar 21, 2012 9:05 pm

It still seems a lot of faffing around rather than the simple solution of having an 8GB SD card, or similar. They are dirt cheap now whereas the very few microdrives that are on Amazon are several times the price for the same capacity. I'm not even sure I've ever seen one in the flesh

User avatar
fodi
Posts: 112
Joined: Wed Mar 14, 2012 9:03 pm
Location: Hungary

Re: Linux swap partition

Wed Mar 21, 2012 9:10 pm

here i can get a 6gigs microdrive for about 12 usd which is comparable for an sd card with a capacity of 8gigs, for that price it's not that bad i guess

User avatar
grumpyoldgit
Posts: 1452
Joined: Thu Jan 05, 2012 12:20 pm

Re: Linux swap partition

Wed Mar 21, 2012 9:37 pm

I've had a quick check on Wikipedia because I am unfamiliar with them They appear to require more power than flash memory, which could be a problem. They are also down as being obsolete, which may explain why there are few for sale on Amazon.

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Linux swap partition

Wed Mar 21, 2012 9:49 pm

I do wonder if some of you are being overly concerend about this swap thing. I'd suggest you just relax a bit - go with the 1GB partition on the supplied image(s) and see how you get on. I've been running the Debian image OK in QEMU with 192MB of RAM, even running up X a few times and while it's slow (I suspect much slower than real hardware due to my slow desktop), it's still usable and that's without swap.

Lets get the things in our grubby little paws first, then we can start to tinker!

Gordon

(Linux & Unix sysadmin for a very long time FWIW)
--
Gordons projects: https://projects.drogon.net/

SANGER_A2
Posts: 59
Joined: Sun Mar 04, 2012 7:39 pm
Contact: Website

Re: Linux swap partition

Thu Mar 22, 2012 9:13 pm

Grumpyoldgit said:


It still seems a lot of faffing around rather than the simple solution of having an 8GB SD card, or similar. They are dirt cheap now whereas the very few microdrives that are on Amazon are several times the price for the same capacity. I'm not even sure I've ever seen one in the flesh


I have lots of spare 2GB SD-cards, but nothing larger. I do have spare USB keys, that was the main reasoning behind it!

There are two reasons I put the swap onto a different device: because I was going to have one anyway to get storage space that will be available to any operating system (and can be unplugged and put into a computer easily) and also because SD cards are pretty terrible for multiple and random read-writes and I didn't want to slow the system down any more than I needed to!

IMO too much swap will never be a problem, but not enough will cause the OS to refuse applications memory or crash!

User avatar
SN
Posts: 1014
Joined: Mon Feb 13, 2012 8:06 pm
Location: Romiley, UK
Contact: Website

Re: Linux swap partition

Thu Mar 22, 2012 9:18 pm

fodi said:


what you think about using microdrives for swapping?

they have not a bad price and afaik they are hdd's with a cf adapter, so they can take a lot of writing on them, and with a decent usb cf card reader they should have normal speed

i'm thinking about something like this:




God I thought you meant one of these when you mentioned Microdrive

Steve N – binatone mk4->intellivision->zx81->spectrum->cbm64->cpc6128->520stfm->pc->raspi ?

Return to “General discussion”