LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-31-2006, 06:48 PM   #1
YodaCows
LQ Newbie
 
Registered: Apr 2005
Posts: 19

Rep: Reputation: 0
Question Is a swap partition really necessary?


I'm about to install SuSE 9.3 Pro x64 and I'm wondering if I actually need a swap.

Here's the specs:
AMD64 3500
ASUS A8V-E Mobo
250GB SATAII 16MB cache
OCZ 1GB PC3200 (2x512)
BFG nVidia 7800GT
(I know, its a killer gaming rig! )

I'll also mention that I'm planning to use this as an ftp server.

Thanks.
 
Old 03-31-2006, 07:04 PM   #2
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Rep: Reputation: 57
Quote:
I know, its a killer gaming rig!
Don't try and start a pissing contest here, you'll lose.

If you're only going to be running a FTP server off it then you probably won't need swap with 1GB of physical memory. If you want to use it for gaming on the other hand then you still probably wouldn't need it but I'd have it. I have 2GB RAM and I still have a 512MB swap partition.
 
Old 03-31-2006, 07:12 PM   #3
YodaCows
LQ Newbie
 
Registered: Apr 2005
Posts: 19

Original Poster
Rep: Reputation: 0
Smile

Sounds good. Thanks for the help
 
Old 03-31-2006, 07:15 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Try it and see. Use the old rule of shade-tree mechanics and the like: "If it works, it's OK"

OR: Note that the downside risk of allocating <1% of your HD to swap space is not terribly high.......
 
Old 03-31-2006, 09:30 PM   #5
J.W.
LQ Veteran
 
Registered: Mar 2003
Location: Boise, ID
Distribution: Mint
Posts: 6,642

Rep: Reputation: 84
Swap is only needed when RAM is pushed beyond capacity and the system is forced to write memory pages to disk. If you've got 32Mg of RAM, that's not too hard to do, but with >256Mg or >512Mg, it becomes increasinly less likely that you would ever actually need swap.

Personally, I allocate a swap partition of 256Mg regardless of my RAM, just on the off chance that my system might need it. From time to time it does get used (I'm running with 512Mg RAM, BTW) but usually it's not. Allocating bigger swap spaces at least to me pretty much is a waste of disk space, but that's just my 2 cents
 
Old 03-31-2006, 10:20 PM   #6
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 52
i think swap is always necessary especially with 64 bit.
the kernel put all anon data into a swap Q the instant it is created.
kernel is designed to have swap. also on non swap system you will get swapd kicking in and booting out executable code and slowing you system down if some app make alot of useless anon data and stays running for a long time .
 
Old 04-01-2006, 01:35 PM   #7
Jaqui
Member
 
Registered: Jan 2006
Location: Vancouver BC
Distribution: LFS, SLak, Gentoo, Debian
Posts: 291

Rep: Reputation: 36
As foo_bar_foo says, the kernel is designed for using a swap partition.

the rule for the partition, specially with a journalised filesystem, is DOUBLE your ram.
so 1 gig ram = 2 gig swap partition.
 
Old 04-01-2006, 10:16 PM   #8
michaelsanford
Member
 
Registered: Feb 2005
Location: Ottawa/Montréal
Distribution: Slackware + Darwin (MacOS X)
Posts: 468

Rep: Reputation: 30
To reiterate, swap is used when you run out of physical ram. You probably won't ever BUT if you do you'll suddenly be in big trouble. If you add services or change what you use your system for and suddenly need more RAM, adding a swap partition later will require reformatting your HD, something you don't want to do if you have 250 GB to back up and restore...

Do it now, save the headache later.
 
Old 04-01-2006, 10:51 PM   #9
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,533

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
Quote:
Originally Posted by michaelsanford
... adding a swap partition later will require reformatting your HD, something you don't want to do if you have 250 GB to back up and restore...
Rubbish.
Adding a partition is simple if there is sufficient unallocated space. Else maybe some resizing may be required - more trouble, but do-able. Swap can also be allocated as a file - the alleged performance impact in 2.4 kernels is supposedly fixed in 2.6.
Quote:
Do it now, save the headache later.
This bit I certainly agree with.
 
Old 04-01-2006, 11:27 PM   #10
michaelsanford
Member
 
Registered: Feb 2005
Location: Ottawa/Montréal
Distribution: Slackware + Darwin (MacOS X)
Posts: 468

Rep: Reputation: 30
syg00, I assumed that there would be no unallocated space as the question seems to centre around using every possible available bit. And I've had shakey experiences resizing existing partitions. But, as I've not had to do it often, maybe I've just been going about it the wrong way.

Last edited by michaelsanford; 04-02-2006 at 01:08 PM.
 
Old 04-02-2006, 01:20 AM   #11
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Rep: Reputation: 57
Quote:
Originally Posted by Jaqui
the rule for the partition, specially with a journalised filesystem, is DOUBLE your ram.
so 1 gig ram = 2 gig swap partition.
This is also rubbish. I use my computer as a desktop machine and I do a large amount of compiling on it as I'm a packager/bug squisher for a linux distro. Convince me why I would need a 4GB swap partition, I dare ya.
 
Old 04-02-2006, 03:17 AM   #12
J.W.
LQ Veteran
 
Registered: Mar 2003
Location: Boise, ID
Distribution: Mint
Posts: 6,642

Rep: Reputation: 84
Agreed - the old "swap = RAM x 2" is a holdover from ancient times, when a system might only have 32Mg of RAM (as I mentioned earlier). These days, when having 256Mg or 512Mg of RAM is common (or maybe even regarded as small/underpowered) the likelihood of actually needing swap is diminished.

Keep in mind that Linux does everything it can to *not* use swap -- after all, access times from within RAM are measured in nanoseconds; access times that require reading from the hard drive are measured in milliseconds. Reading from swap therefore equates to a a massive, massive performance slowdown. Honestly, if your swap space is being both consistently and heavily used, it's worthwhile to consider adding more RAM. The alternative of making swap bigger really won't help.
 
Old 04-02-2006, 04:49 AM   #13
1kyle
Member
 
Registered: Feb 2004
Location: 'Ol Blighty
Distribution: SLED 10, SUSE 10.3
Posts: 722

Rep: Reputation: 32
This is a newbie forum, so I don't want to go too deeply into the mechanics of Operating System design internals however there seems to be a little bit of "less than Gospel Truth" spreading around here.

Most modern computer Operating systems are built which incorporate a system known as "Virtual Memory" or "Demand paging".

By Modern I'm talking about anything from the old IBM mainframes (MVS/370 back in the early 70's) to todays Windows, UNIX, Linux and other various systems.

When you run an application the operating system essentially allocates storage for it in what's known as "segments" or pages and stores this in a page map. The allocation of this is a highly complex algorithm -- if it's designed badly your OS will run like a "One Legged Dog on a perfectly smooth icepond".

A typical algorithm will be the "LRU or Last recently used".

What this essentially does is to ensure that pages that have been "Swapped out" are reloaded back to main memory in time for the next request for them by the application.

This reload is usually done while the processor is not busy so you shouldn't see any degradation. When to reload is done on all sorts of complex calculations way beyond the scope of this post but for those interested more detail can be obtained by Googling as detailed OS internal design as explained is well beyond the scope of this post.

A decent operating system will try and maximize the amount of available RAM it has at all times and try and balance the I/O (Disk access etc) with using the main processor.

If your application is not actually running -- for example waiting for input from you etc. it will actually "Swap out" those parts of the application that haven't' actually been used to the swap area to make more RAM available for any possible new application that the user or the system might start. ("Task Dispatcher" goes around looking for work to do).

For example if your application is going to write out say 100 MB to a disk the OS will simply allocate space away from the main RAM for that and pass control over to the I/O processor and the look for another task to do. Since most Disk units have a fairly small cache it doesn't make sense to lock up 100 MB of main RAM when you are probably only transferring to the disk in 8KB chunks in any case. In these cases using temporary ("swap") storage won't interfere with the main computer processes --in fact they will actually enhance them.

If you don't have an external swap space then the computer system will still allocate pages as before but because it can't overlap the Disk activity with main memory processing your OS will actually have to WAIT for the paging algorithms to run before it can do other processing.

Even if you have a LARGE amount of RAM it's ALWAYS a good idea to have a swap space. Disk storage is cheap and it won't degrade your system -- in fact it should improve it as the stuff will only be "swapped out" when that part of the application is not busy.

How much swap space is another question --true the old adage of 1/2 the RAM doesn't apply anymore but with really cheap large disks these days a 1GB swap partition will ususally be more than adequate, or even a 512MB one. Keep the swap partition away from disks with a lot of activity if you can.

Of course as you load the system more then the OS will have to use the swap areas more -- this is where the design of the OS is paramount.

If your RAM size is too small then the OS simply spends all it's time looking for pages to allocate and de-allocate ("Thrashing") which you can see easily enough when your disk activity or light is solid on and the computer is doing nothing.

You should always have a decent amount of RAM in any case.

Anyway to get back to the point --you *could* run without swap space but even with large amounts of RAM it's not a good idea.

The OS can decide far better than us what it needs --and most Linux distros are well written OS'es.

Cheers

-K

Last edited by 1kyle; 04-02-2006 at 05:31 AM.
 
Old 04-02-2006, 06:52 PM   #14
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 52
yes paging on demand loads pages into virtual memory and load on demand loads whats actually needed from that into actual RAM.

only pages labled swappable are a part of the swap que and cantidates for swapping. anonymous pages in user spaces and mapped shared memory. thats it. nothing else ever gets to the swap partition/file.
because everything else exists on disk somewhere else already.

so when Linux starts reclaiming pages it starts from the bottom of the inactive list and just ejects pages not swaps accept for the specific cases above.
Quote:
Originally Posted by 1kyle
The allocation of this is a highly complex algorithm
A typical algorithm will be the "LRU or Last recently used".
the last recenty used bit is quite simple just two lists active and inactive. each list is done FIFO. get called on by the teacher go to the head of the class in the active list. don't get called on and fall slowly to the back till you become food for the sharks.



Quote:
Originally Posted by 1kyle

What this essentially does is to ensure that pages that have been "Swapped out" are reloaded back to main memory in time for the next request for them by the application.

This reload is usually done while the processor is not busy so you shouldn't see any degradation. When to reload is done on all sorts of complex calculations way beyond the scope of this post but for those interested more detail can be obtained by Googling as detailed OS internal design as explained is well beyond the scope of this post.
as far as i know Linux does not in any way do this and it would be a violation of the basic load on demand concept.
Quote:
Originally Posted by 1kyle
If your application is not actually running -- for example waiting for input from you etc. it will actually "Swap out" those parts of the application that haven't' actually been used to the swap area to make more RAM available for any possible new application that the user or the system might start. ("Task Dispatcher" goes around looking for work to do).

For example if your application is going to write out say 100 MB to a disk the OS will simply allocate space away from the main RAM for that and pass control over to the I/O processor and the look for another task to do. Since most Disk units have a fairly small cache it doesn't make sense to lock up 100 MB of main RAM when you are probably only transferring to the disk in 8KB chunks in any case. In these cases using temporary ("swap") storage won't interfere with the main computer processes --in fact they will actually enhance them.
as far as i know Linux doesn't do this either.
swapping and page ejection is only done when memory comes under preasure.
writing pending I/O to swap before writing is writing twice which is one time too many.
Quote:
Originally Posted by 1kyle
If you don't have an external swap space then the computer system will still allocate pages as before but because it can't overlap the Disk activity with main memory processing your OS will actually have to WAIT for the paging algorithms to run before it can do other processing.
In Linux asyncronouse I/O doesn't have anything to do with swap at all as far as i know.
Linux used to do kernel space DMA through the kernel buffer cache i think. thats something real different than swap. But now i thing block I/O is done in user space through the page cache. also something way different than swap.

Last edited by foo_bar_foo; 04-02-2006 at 07:11 PM.
 
Old 04-02-2006, 07:23 PM   #15
J.W.
LQ Veteran
 
Registered: Mar 2003
Location: Boise, ID
Distribution: Mint
Posts: 6,642

Rep: Reputation: 84
Quote:
Originally Posted by 1kyle
Even if you have a LARGE amount of RAM it's ALWAYS a good idea to have a swap space. Disk storage is cheap and it won't degrade your system -- in fact it should improve it as the stuff will only be "swapped out" when that part of the application is not busy.
Consider two systems: One has to physically write data out to the hard drive, then read it from the hard drive back into RAM. The other has so much RAM that the physical swap space is not needed, due to the fact that the system load never requires >100% of the available RAM.

Which system will perform better? Obviously, the second one. Don't get me wrong, I always allocate a 256Mg swap space, but for someone with 1G of RAM, setting up a 2G swap space is just a waste of storage capacity. Either way though, if your system is forced to continually load data that's stored on a hard drive back into RAM, your overall performance will suffer. Significantly.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
swap partition Cheechi Linux - Newbie 11 06-24-2004 10:24 PM
more then one swap partition? SLaCk_KiD Linux - General 5 06-22-2003 10:50 PM
Newbie Installing Debian3 on m68k w/250M Partition Needs help creating swap partition AppleMac Linux - Newbie 2 11-01-2002 08:45 AM
swap partition Xreagan Linux - Newbie 19 08-29-2002 12:47 PM
Swap partition Thomas_Delrue Linux - Newbie 3 07-12-2001 08:35 PM


All times are GMT -5. The time now is 12:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration