LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 05-07-2011, 05:56 AM   #1
Weapon S
Member
 
Registered: May 2011
Location: Netherlands
Distribution: Debian
Posts: 149
Blog Entries: 1

Rep: Reputation: 12
Swap partition size: huge; any adverse effects? Debian


Hi there,

what (I think) I know is: generally speaking you don't need much swap (about 2x your memory should suffice). If you need more, the sane thing to do is buy more RAM.
Insane situation here Old PC. Challenge: build Linux system that works (slightly?) better than Windows system, with same programs.
In Windows I have seen in rare cases that the virtual memory reaches about 10.0GB(640M of RAM ) The system bodges up, but after an hour or so, when the memory load subsides, at least your work isn't lost.
Three questions:
Can I expect our 'exceptional use' to require as much swap on Linux as virtual memory on Windows?
Would there be some adverse effect of setting up too large swap, excluding the disk space lost? (e.g. swap management taking up RAM)
Would Linux (Debian) actually be able to address so much swap?

Most stuff I read is about 7 years old. (My hardware is older, but my software isn't :P )

It might be tempting for people who love Linux, and have great computers to just say: "Linux is better than Windows" and "do the normal thing". Please refrain from saying so, without good reasoning. Help appreciated.

P.S.
OK, have to be honest. I already partioned for 14GB swap. If I understand the little meter in the lower right corner of my WM correctly it uses almost all of that space... constantly Either my interpretation of 1400.99/1400.56M is wrong, or this could already be such an 'adverse effect' or it could be the systems way of saying: "there's no way I'm using that much swap".
 
Old 05-07-2011, 06:16 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,483

Rep: Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077
The largest potential swap usage depends on page size - which depends on architecture. Let's see the output of "swapon -s".
Generally on 32-bit systems you are better off having multiples of 2 Gig swap partitions.
 
1 members found this post helpful.
Old 05-07-2011, 06:32 AM   #3
pingu
Senior Member
 
Registered: Jul 2004
Location: Skuttunge SWEDEN
Distribution: Debian preferably
Posts: 1,317

Rep: Reputation: 124Reputation: 124
I don't really know how much swap you can use, but I don't think swap handling in itself takes much memory. Just my guess though.
10 GB used in Windows sounds weird to me?
I haven't seen so much memory used on any ordinary home/office pc, even when editing movies 2 GB of RAM is enough to work at a decent pace.

In Linux, one tip is to check your memory (no, the computers memory - not your own! ) with the command "free".
Output like this:
Code:
pingu@edgar:~$ free
             total       used       free     shared    buffers     cached
Mem:       2596312     658688    1937624          0      55300     360472
-/+ buffers/cache:     242916    2353396
Swap:      3156732          0    3156732
(That buffers/cache - it is memory reserved by the system but not actually used.)

Now to be able to answer better, I must know more about your system.
What do you use it for?
How much memory does your programs actually require?
How big harddisk do you have?

If I understand correctly your computer has 640KB ram, is that correct?
What else does it have, mainly cpu, video.
The reason I'm asking is that there is more than memory management to take into account here, in order to get your system to run smoothly - I do know you asked about swap specifically, and hope I/someone can answer that in a good way, but still the bottom line in your question is
"build Linux system that works (slightly?) better than Windows system, with same programs."
Things to consider:
* Build your own kernel - pretty important!
* Put swap as the first partition on the disk
* I read some time ago about swap being slightly faster if whole swap is on a separate disk, can't say whether that is true though.
Also don't know if it's best to spread swap on several disks - theoretically it should be slightly better but I never tried it.
 
1 members found this post helpful.
Old 05-07-2011, 10:33 AM   #4
Weapon S
Member
 
Registered: May 2011
Location: Netherlands
Distribution: Debian
Posts: 149
Blog Entries: 1

Original Poster
Rep: Reputation: 12
Thanks for the replies.
free:
Code:
             total       used       free     shared    buffers     cached
Mem:        384580     319844      64736          0      10224     106968
-/+ buffers/cache:     202652     181928
Swap:      1434616          0    1434616
swapon -s:
Code:
Filename         type        free      used  priority
/dev/sda3   partition   1434616      0        -1
Typed over from virtual terminal logged in as root... that's bad, right?

Quote:
If I understand correctly your computer has 640KB ram, is that correct?
Heck, no! 640MB. Wait... I'm mistaking: that's the other PC...
Quote:
* Build your own kernel - pretty important!
* Put swap as the first partition on the disk
* I read some time ago about swap being slightly faster if whole swap is on a separate disk, can't say whether that is true though.
Also don't know if it's best to spread swap on several disks - theoretically it should be slightly better but I never tried it.
1: can't wait 8-) ( But really should. Really should! :-X )
2: impossible: multiboot with windows. It's the last partition. IIRC that is fast too.
3: separate disk is understandable and feasible. The whole splitting stuff seems overkill IMHO. Though, it might be faster in theory [reconsidering]

I can't remember the specifics of this system. I believe this is a 1.4GHz pentium II, Geforce2 AGP so crappy it doesn't even have a label, 40GB HD x2, 374?MB DDR1 memory.
(I also plan to install on a better PC.
AMD 900MHz (No SSE), Geforce4 440-SE 64MB AGPx4 640MB DDR2 memory.
)

Last edited by Weapon S; 05-07-2011 at 10:45 AM.
 
Old 05-07-2011, 11:29 AM   #5
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 5.4, Mac OS 10.4 (tiger)
Posts: 1,005

Rep: Reputation: 79
to put it simply, your machine is using 0MB of swap... the rule with virtual memory and swap generally is between 1.5 to 3 times the amount of RAM you have as the addressing needs to be stored taking away from RAM and pushing slightly more on to Virtual Memory or Swap, now I am not as familiar with swap as Virtual Memory but I know using too much virtual memory can actually slow a machine down, not sure if that's true with Linux and Swap but it wouldn't surprise me.

To put it in simpler terms you should have your swap somewhere between 960MB and 1920MB. I'd probably personally advise ~1536MB (or ~1.5GB) tho 1280 might be an alternative.

As for Windows, Windows reserves memory for future use, the large usage you are probably seeing is nothing more then reserved memory rather then used and so it'd probably drop if you dropped the virtual memory back to realistic figures. Else wise you have a lot of junk on your windows box that really needs cleaning out.

Last edited by r3sistance; 05-07-2011 at 11:32 AM.
 
1 members found this post helpful.
Old 05-07-2011, 02:50 PM   #6
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,650
Blog Entries: 2

Rep: Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095
Quote:
Originally Posted by r3sistance View Post
the rule with virtual memory and swap generally is between 1.5 to 3 times
May I ask where you have that "rule"from. Sorry I have to say that, but in my eyes this is just nonsense. The amount of swap that you need is only dependent on one thing: The workload of that machine. There are no general rules to determine the amount of swap you should setup. Just an example: While I set up 8GB of swap on my workstation with 8GB physical RAM (because I sometimes run many VMs simultaneous), I only have set up 2GB of swap on my laptop with 4GB physical RAM (which I mainly use for surfing the net and as multimedia machine). I don't see why I should set up 6 to 12GB of swap on this machine, it will never be used.
 
Old 05-08-2011, 02:35 AM   #7
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 5.4, Mac OS 10.4 (tiger)
Posts: 1,005

Rep: Reputation: 79
Quote:
Originally Posted by TobiSGD View Post
May I ask where you have that "rule"from. Sorry I have to say that, but in my eyes this is just nonsense. The amount of swap that you need is only dependent on one thing: The workload of that machine. There are no general rules to determine the amount of swap you should setup. Just an example: While I set up 8GB of swap on my workstation with 8GB physical RAM (because I sometimes run many VMs simultaneous), I only have set up 2GB of swap on my laptop with 4GB physical RAM (which I mainly use for surfing the net and as multimedia machine). I don't see why I should set up 6 to 12GB of swap on this machine, it will never be used.

The rule generally comes from years ago actually, modern day machines are able to run much more effectively off of RAM (because of both more RAM and better optimized code) however back say 10 years ago, that was barely even possible. So in the future it might be a case machines need none at all. It is as you say possible to run with much less, it is also possible to run with much more, machines on the low-end or even mid-end will however likely still be using Swap or Virtual Memory and as such should be made to use 1.5~3 times RAM as Virtual Memory/Swap. Any larger can actually become decremental to the machine (due to addressing). So yes, it's possible to run with no RAM or Virtual Memory, in the cases of machines reaching these points I don't think the word "general" applies anymore however (the number of laptops around with 512MB~2GB of RAM vastly out-numbers those with 3GB+).
 
Old 05-08-2011, 04:58 AM   #8
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,650
Blog Entries: 2

Rep: Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095
Quote:
Originally Posted by r3sistance View Post
machines on the low-end or even mid-end will however likely still be using Swap or Virtual Memory and as such should be made to use 1.5~3 times RAM as Virtual Memory/Swap.
As I stated above, the amount of swap can only be determined by analyzing the workload. It is not dependent of the class of the machine. A machine that really would need that amount of swap would be awfully slow and not fitting to the job it is doing.
 
1 members found this post helpful.
Old 05-08-2011, 06:20 AM   #9
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 5.4, Mac OS 10.4 (tiger)
Posts: 1,005

Rep: Reputation: 79
Quote:
Originally Posted by TobiSGD View Post
As I stated above, the amount of swap can only be determined by analyzing the workload. It is not dependent of the class of the machine. A machine that really would need that amount of swap would be awfully slow and not fitting to the job it is doing.
There should not be too many issues with the sizes I stated, having 1.5~3, there are number of things that could use such without being sluggish or slow, it depends on the tasks themselves. Still 1.5~3 tends to be about the best area for most general machines, high-end machines can get away with none but even mid range machines can be pushed by some tasks.
 
Old 05-08-2011, 02:51 PM   #10
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
I'm with TobiSGD -- a system needs as much swap as it needs and there's no rule that can predict it. Years ago these "swap must be x times RAM" rules appeared but had no basis in practice; nonetheless they persist and it's about time they were consigned to the Bothers Grimm of computing.

If the system uses swap then it is performing slowly and ideally more RAM would be fitted. If you are lucky enough to be able to fit more RAM then swap can be seen as a safety net -- it avoids the messy situation of running out of virtual memory and allows you (by checking to see how much swap is actually being used under a variety of load scenarios) to decide how much extra RAM to get. One easy way to see how much swap you need is to use a file for swap instead of a partition -- it will grow to accommodate what you use.

If you plan to hibernate a system then different swap considerations apply.

On a system with 4 GB RAM, I sometimes run three or four VMs, configured with 1 GB each. That causes swapping but I rarely run so many VMs simultaneously so the swap is needed and the cost of more RAM (in cash and carbon) is not justified. GKrellM nicely shows how much swap is being used at any time.
 
1 members found this post helpful.
Old 05-09-2011, 07:18 AM   #11
Weapon S
Member
 
Registered: May 2011
Location: Netherlands
Distribution: Debian
Posts: 149
Blog Entries: 1

Original Poster
Rep: Reputation: 12
Thanks everybody

Thanks for all the replies. Indeed I've read somewhere that the "2*RAM-size-rule" was just an easy way of explaining all the factors involved.
By the way I counted wrongly It's 1.4GB of swap I have. That is very reasonable. It is funny however, that no-one can actually confirm the adverse effects of setting too much swap.
 
Old 05-09-2011, 07:47 AM   #12
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,483

Rep: Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077
There is no adverse effects.
As in most things, the memory management code is *way* smarter than the users. There are no PTEs for unused swap pages.
 
Old 05-09-2011, 10:39 AM   #13
masterclassic
Member
 
Registered: Jun 2007
Distribution: Knoppix
Posts: 140

Rep: Reputation: 23
As far as I know, that old rule "swap=2xRAM" (or 3x) comes from the old era of personal computers with 128 or 256 MiB RAM. The RAM was very expansive, the hard disk space was (and is) much cheeper. Of course, more swap use means more hard drive load and more CPU load. Rich people could afford more expansive hardware! So, why not 4x or 5x? Because in such cases the work to do would be so big that a more powerful computer was needed!

There is a different approach in m$windows, I think. The virtual memory is used always, even when the memory used is less than the installed memory. There is a reserved disk space, usually in the same drive as the system, in the hope to have a consecutive disk space and avoid fragmentation of the swap file. However, if you increase the memory allocation, the operating system expands this disk space, of course in other parts of the disk space (so, the swap file becomes fragmented). Older (at least) specification was that the virtual memory could be up to 4 or 5 times the installed RAM. I don't know actual specification; but please note that at the time, RAM size was mostly up to 256 of 512 MiB, so 4-5 times RAM was within the addressing space of the 32bit mswindows system (that is 4GiB minus video card memory & firmware memory space; i.e. something like 3GiB+ ).
Nevertheless, I had myself painful experience with such big virtual memory size: this was in case of many running programmes & big cad models. The response of the machine was veeeeeery slow. Sometimes this geant memory allocation (up to 1.6Gib with 500MiB installed physical RAM) was due to malware infection. To change from a displayed window to another or change a web page could take 5 minutes or more.

I think that in the case of Linux, the swap space is used in addition to the physical RAM, not in parallel. I mean that 1GiB RAM + 1GiB swap cover 2GiB total space.
 
1 members found this post helpful.
Old 05-09-2011, 12:44 PM   #14
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
Quote:
Originally Posted by masterclassic View Post
Of course, more swap use means more hard drive load and more CPU load.
Swapping loads the HDD; having swap space on the HDD does not.
 
Old 05-09-2011, 02:44 PM   #15
masterclassic
Member
 
Registered: Jun 2007
Distribution: Knoppix
Posts: 140

Rep: Reputation: 23
Quote:
Originally Posted by catkin View Post
Swapping loads the HDD; having swap space on the HDD does not.
Of course!
My remark had rather to do with performance: bigger swap space doesn't substitute bigger RAM.
 
  


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
Size of the swap partition Nitram Linux - Newbie 5 12-04-2007 06:05 AM
Swap Partition Size Murdock1979 Slackware 11 07-27-2005 02:09 AM
What size should I make my swap partition? bobotoes Linux - Newbie 7 09-30-2004 11:36 PM
swap partition size alaios Linux - General 4 09-27-2004 02:21 PM
swap partition size? Toker Linux - Newbie 16 10-12-2003 12:19 PM


All times are GMT -5. The time now is 04:22 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration