LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Is a swap partition really necessary? (https://www.linuxquestions.org/questions/linux-newbie-8/is-a-swap-partition-really-necessary-430481/)

YodaCows 03-31-2006 06:48 PM

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! :p )

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

Thanks.

cs-cam 03-31-2006 07:04 PM

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.

YodaCows 03-31-2006 07:12 PM

Sounds good. Thanks for the help

pixellany 03-31-2006 07:15 PM

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.......;)

J.W. 03-31-2006 09:30 PM

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

foo_bar_foo 03-31-2006 10:20 PM

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 .

Jaqui 04-01-2006 01:35 PM

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.

michaelsanford 04-01-2006 10:16 PM

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.

syg00 04-01-2006 10:51 PM

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.

michaelsanford 04-01-2006 11:27 PM

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.

cs-cam 04-02-2006 01:20 AM

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.

J.W. 04-02-2006 03:17 AM

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.

1kyle 04-02-2006 04:49 AM

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

foo_bar_foo 04-02-2006 06:52 PM

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.

J.W. 04-02-2006 07:23 PM

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.


All times are GMT -5. The time now is 07:46 AM.