LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 04:56 AM   #1
Weapon S
Member
 
Registered: May 2011
Location: Netherlands
Distribution: Debian, Archlinux
Posts: 262
Blog Entries: 2

Rep: Reputation: 49
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, 05:16 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
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, 05:32 AM   #3
pingu
Senior Member
 
Registered: Jul 2004
Location: Skuttunge SWEDEN
Distribution: Debian preferably
Posts: 1,350

Rep: Reputation: 127Reputation: 127
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, 09:33 AM   #4
Weapon S
Member
 
Registered: May 2011
Location: Netherlands
Distribution: Debian, Archlinux
Posts: 262

Original Poster
Blog Entries: 2

Rep: Reputation: 49
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 09:45 AM.
 
Old 05-07-2011, 10:29 AM   #5
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
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 10:32 AM.
 
1 members found this post helpful.
Old 05-07-2011, 01:50 PM   #6
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
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, 01:35 AM   #7
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
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, 03:58 AM   #8
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
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, 05:20 AM   #9
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
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, 01:51 PM   #10
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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, 06:18 AM   #11
Weapon S
Member
 
Registered: May 2011
Location: Netherlands
Distribution: Debian, Archlinux
Posts: 262

Original Poster
Blog Entries: 2

Rep: Reputation: 49
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, 06:47 AM   #12
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
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, 09:39 AM   #13
masterclassic
Member
 
Registered: Jun 2007
Distribution: Knoppix, antiX
Posts: 252

Rep: Reputation: 73
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, 11:44 AM   #14
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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, 01:44 PM   #15
masterclassic
Member
 
Registered: Jun 2007
Distribution: Knoppix, antiX
Posts: 252

Rep: Reputation: 73
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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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
Open Source Consulting | Domain Registration