Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Discussion & Documentation Documentation, Tips & Tricks
  • Search

HOWTO: Get rid of that ugly swap partition

Unofficial documentation for various parts of Gentoo Linux. Note: This is not a support forum.
Post Reply
Advanced search
13 posts • Page 1 of 1
Author
Message
Rainmaker
Veteran
Veteran
User avatar
Posts: 1650
Joined: Thu Feb 12, 2004 2:04 am
Location: /home/NL/ehv/

HOWTO: Get rid of that ugly swap partition

  • Quote

Post by Rainmaker » Sun Apr 18, 2004 11:49 pm

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: Select all

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: Select all

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: Select all

mkswap /tmp/swap
//edit----------------------------

For security, chmod your swap file:

Code: Select all

chmod 600 /tmp/swap
//end edit------------------------

Then activate the swap by using:

Code: Select all

swapon /tmp/swap
reformat your swap partition

Code: Select all

*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: Select all

/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: Select all

/sbin/swapoff /tmp/swap
to local.stop.
Last edited by Rainmaker on Tue Apr 20, 2004 1:34 am, edited 5 times in total.
Top
nbensa
l33t
l33t
User avatar
Posts: 799
Joined: Wed Jul 10, 2002 11:09 am
Location: Buenos Aires, Argentina

Re: HOWTO: Get rid of that ugly swap partition

  • Quote

Post by nbensa » Sun Apr 18, 2004 11:50 pm

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.
Top
Rainmaker
Veteran
Veteran
User avatar
Posts: 1650
Joined: Thu Feb 12, 2004 2:04 am
Location: /home/NL/ehv/

  • Quote

Post by Rainmaker » Sun Apr 18, 2004 11:55 pm

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.
Top
Gatak
Apprentice
Apprentice
Posts: 174
Joined: Sun Jan 04, 2004 11:00 pm

  • Quote

Post by Gatak » Mon Apr 19, 2004 9:19 am

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?
Top
Biker
Apprentice
Apprentice
User avatar
Posts: 170
Joined: Wed Jun 11, 2003 10:06 am
Location: A very dark, cold and moisty place...

Re: HOWTO: Get rid of that ugly swap partition

  • Quote

Post by Biker » Mon Apr 19, 2004 11:53 am

Rainmaker wrote: reformat your swap partition

Code: Select all

mkefs /dev/hda2
You may want to:

Code: Select all

swapoff /dev/hda2
first. ;-)

Biker
The Internet never forgets.
Where 'never' points in the direction of a moment in the very, very far future.
Top
guard0
Tux's lil' helper
Tux's lil' helper
Posts: 96
Joined: Thu Jun 26, 2003 11:15 pm

  • Quote

Post by guard0 » Mon Apr 19, 2004 12:55 pm

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
Top
xunil
n00b
n00b
User avatar
Posts: 36
Joined: Wed Jun 18, 2003 4:26 pm
Location: Blacksburg, VA, USA

  • Quote

Post by xunil » Mon Apr 19, 2004 9:13 pm

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

/path/to/swapfile none swap sw 0 0
Top
Earthwings
Bodhisattva
Bodhisattva
User avatar
Posts: 7753
Joined: Mon Apr 14, 2003 8:13 pm
Location: Germany

  • Quote

Post by Earthwings » Mon Apr 19, 2004 9:30 pm

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.
Top
MooktaKiNG
Guru
Guru
User avatar
Posts: 326
Joined: Mon Nov 11, 2002 2:30 pm
Location: London, UK
Contact:
Contact MooktaKiNG
Website

  • Quote

Post by MooktaKiNG » Mon Apr 19, 2004 11:30 pm

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
Top
NecroScumBag
n00b
n00b
Posts: 26
Joined: Sun Feb 15, 2004 11:19 pm

  • Quote

Post by NecroScumBag » Tue Apr 20, 2004 12:44 am

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.
Top
Rainmaker
Veteran
Veteran
User avatar
Posts: 1650
Joined: Thu Feb 12, 2004 2:04 am
Location: /home/NL/ehv/

  • Quote

Post by Rainmaker » Tue Apr 20, 2004 1:10 am

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.
Top
gtaluvit
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 135
Joined: Sat Aug 09, 2003 2:55 pm
Location: Columbia, MD

  • Quote

Post by gtaluvit » Tue Apr 20, 2004 1:14 am

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?
Top
MooktaKiNG
Guru
Guru
User avatar
Posts: 326
Joined: Mon Nov 11, 2002 2:30 pm
Location: London, UK
Contact:
Contact MooktaKiNG
Website

  • Quote

Post by MooktaKiNG » Tue Apr 20, 2004 9:51 am

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
Top
Post Reply

13 posts • Page 1 of 1

Return to “Documentation, Tips & Tricks”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic