Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
HOWTO: Get rid of that ugly swap partition
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
Rainmaker
Veteran
Veteran


Joined: 12 Feb 2004
Posts: 1650
Location: /home/NL/ehv/

PostPosted: Sun Apr 18, 2004 11:49 pm    Post subject: HOWTO: Get rid of that ugly swap partition Reply with quote

If you have only 1 *nix system installed, you don't really need a swap partition. A swap file is much more flexible, and you can alter the size when you're in need of extra disc space.

*edit (thanks to nbensa / Earthwings)
Warning: swap files are a bit slower then swap partitions. If you have a lot of memory, this should not make a difference because the swap file will hardly ever get used. If you have a small amount of RAM, and are aiming for maximum performance, stick with the swap partition.

To check the amount of RAM and swap currently used and available, use the command
Code:
free -m

This will display the amount of swap you're currently using (in MB's).

*edit (tanks to MooktaKiNG)
If you want dynamic swap files (as in Windows), use swapd (http://cvs.linux.hr/swapd/). Unfortunatly, it's not in the portage tree.

To covert your swap PARTITION to a (static) swap FILE do the following:

Make an empty file using the following command:

Code:
dd if=/dev/zero of=/tmp/swap bs=1024 count=65536


Replace "count=65536" with the size of your swap file in kilobytes, and "/tmp/swap" with the name of your swap file.

After this, make the file into a swap file by using:

Code:
mkswap /tmp/swap


//edit----------------------------

For security, chmod your swap file:
Code:
chmod 600 /tmp/swap


//end edit------------------------

Then activate the swap by using:

Code:
swapon /tmp/swap


reformat your swap partition
Code:

*edit (thanks Biker)
swapoff /dev/hda2
mkefs /dev/hda2


You can then edit your fstab to reflect the changes (i.e. let /dev/hda2 mount on /apps/ or something)
Look at /proc/swaps to see if it actually changed.

You should put the "swapon" command to run at boot time. It added this line to local.start:
Code:
/sbin/swapon /tmp/swap


Local.start might not be the best place (it should activate swap earlier), but as long as you don't start to many services at boot time, local.start should be fine.

Don't forget to deactivate it by adding
Code:
/sbin/swapoff /tmp/swap


to local.stop.


Last edited by Rainmaker on Tue Apr 20, 2004 1:34 am; edited 5 times in total
Back to top
View user's profile Send private message
nbensa
l33t
l33t


Joined: 10 Jul 2002
Posts: 799
Location: Buenos Aires, Argentina

PostPosted: Sun Apr 18, 2004 11:50 pm    Post subject: Re: HOWTO: Get rid of that ugly swap partition Reply with quote

Rainmaker wrote:
A swap file is much more flexible, and you can alter the size when you're in need of extra disc space.


Flexible, perhaps. But flexibility comes with a price: performance.
Back to top
View user's profile Send private message
Rainmaker
Veteran
Veteran


Joined: 12 Feb 2004
Posts: 1650
Location: /home/NL/ehv/

PostPosted: Sun Apr 18, 2004 11:55 pm    Post subject: Reply with quote

You're absolutely right...

The only thing is, and you find this all over the forum, is that the swap partition / file rarely gets used.

The only reason why it's a good idea to have swap space, is if a program has a memory leak, it won't crash your entire system immediatly.

If you really use memory-intensive programs (running KDE + listening to mp3's + compiling in the background + web browsing + that photoshop clone + ....) it might not be a good idea to do this. But if you only do 5 or 6 things at the time, the performance decrease will not be that big.
Back to top
View user's profile Send private message
Gatak
Tux's lil' helper
Tux's lil' helper


Joined: 04 Jan 2004
Posts: 111

PostPosted: Mon Apr 19, 2004 9:19 am    Post subject: Reply with quote

It would be nice to be able to have a swapfile that can grow and shrink to needs, or within a boundary. Is this possible?
Back to top
View user's profile Send private message
Biker
Apprentice
Apprentice


Joined: 11 Jun 2003
Posts: 165
Location: A very dark, cold and moisty place...

PostPosted: Mon Apr 19, 2004 11:53 am    Post subject: Re: HOWTO: Get rid of that ugly swap partition Reply with quote

Rainmaker wrote:

reformat your swap partition
Code:
mkefs /dev/hda2



You may want to:
Code:
swapoff /dev/hda2

first. ;-)

Biker
_________________
The Internet never forgets.
Where 'never' points in the direction of a moment in the very, very far future.
Back to top
View user's profile Send private message
guard0
Tux's lil' helper
Tux's lil' helper


Joined: 26 Jun 2003
Posts: 96

PostPosted: Mon Apr 19, 2004 12:55 pm    Post subject: Reply with quote

couldnt you use a loopback filesystem for this so you could skip all the swapon and swapoff stuff at boot/shutdown by editing your line in /etc/fstab?
_________________
Linux on an AMD processor: an OS for people who dont use deoderant with a CPU for people who can't afford deoderant
Back to top
View user's profile Send private message
xunil
n00b
n00b


Joined: 18 Jun 2003
Posts: 36
Location: Blacksburg, VA, USA

PostPosted: Mon Apr 19, 2004 9:13 pm    Post subject: Reply with quote

It's safe to add your swap file to /etc/fstab:

/path/to/swapfile none swap sw 0 0
Back to top
View user's profile Send private message
Earthwings
Bodhisattva
Bodhisattva


Joined: 14 Apr 2003
Posts: 7753
Location: Karlsruhe, Germany

PostPosted: Mon Apr 19, 2004 9:30 pm    Post subject: Reply with quote

I second nbensa - think you should put a warning on top to check the usage of swap. Not everybody has 512 MB RAM lying around, and at the point swap space gets used frequently it's not a good idea to decrease performance even more.
Back to top
View user's profile Send private message
MooktaKiNG
Guru
Guru


Joined: 11 Nov 2002
Posts: 326
Location: London, UK

PostPosted: Mon Apr 19, 2004 11:30 pm    Post subject: Reply with quote

Gatak wrote:
It would be nice to be able to have a swapfile that can grow and shrink to needs, or within a boundary. Is this possible?



There's already something like that available, or was available. Don't know what happened to it though,
its called swapd.

lets see if i can find a link......

.....
ah: http://cvs.linux.hr/swapd/

Have fun :)

PS: nowadays HD's are on average 80Gb (or thats the size they sell them on new computers these days). So therefore sparing 1Gb of swap won't really effect people :):):)

I usually always create 1Gb or swap. i just do. even though i might not need it, probably.
_________________
http://www.mooktakim.com
Athlon XP 2001, Giga-Byte GA-7VRXP MB, 640Mb DDR RAM 333MHz, MSI Geforce 4800SE 128Mb DDR, 40x12x48 Liteon CDRW drive, Flower Cooler, ADSL Router
Back to top
View user's profile Send private message
NecroScumBag
n00b
n00b


Joined: 15 Feb 2004
Posts: 26

PostPosted: Tue Apr 20, 2004 12:44 am    Post subject: Reply with quote

How dependant is gentoo to a sawp file/partition.. if the size is small.. One could setup a scrip on boot up to make a ram drive and have the swap file or partition to run from memory. Which in this case would speed up the proformance even more. This might be a option advailible.
Back to top
View user's profile Send private message
Rainmaker
Veteran
Veteran


Joined: 12 Feb 2004
Posts: 1650
Location: /home/NL/ehv/

PostPosted: Tue Apr 20, 2004 1:10 am    Post subject: Reply with quote

NecroScumBag wrote:
How dependant is gentoo to a sawp file/partition.. if the size is small.. One could setup a scrip on boot up to make a ram drive and have the swap file or partition to run from memory. Which in this case would speed up the proformance even more. This might be a option advailible.


But... what is the use of a swap partition??

If you're memory is full, linux switches to your swap to write some extra info. Placing a swap in memory actually just wastes memory.
Back to top
View user's profile Send private message
gtaluvit
Tux's lil' helper
Tux's lil' helper


Joined: 09 Aug 2003
Posts: 135
Location: Columbia, MD

PostPosted: Tue Apr 20, 2004 1:14 am    Post subject: Reply with quote

Necro, I don't know if you're actually serious or not but just to assume you are, it defeats the whole purpose. Linux (and most OS's) use all the available RAM, and when that's gone, starts using the HD as a swap file. If you use a RAM disk, all you're doing is reducing the amount of available RAM you have to use it as swap with added overhead. RAMDisk for swap is NOT a good idea.
_________________
I'm out of bed and dressed, what more do you want?
Back to top
View user's profile Send private message
MooktaKiNG
Guru
Guru


Joined: 11 Nov 2002
Posts: 326
Location: London, UK

PostPosted: Tue Apr 20, 2004 9:51 am    Post subject: Reply with quote

Gentoo is a source based distro. Therefore it requires large swap spaces for all the compiling.

Its not funny when you start compiling xfree or something and spend all night compiling, then it says "out of memory"!!!

its not very nice either :D:D:D
_________________
http://www.mooktakim.com
Athlon XP 2001, Giga-Byte GA-7VRXP MB, 640Mb DDR RAM 333MHz, MSI Geforce 4800SE 128Mb DDR, 40x12x48 Liteon CDRW drive, Flower Cooler, ADSL Router
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum