113%

Story: All about Linux swap spaceTotal Replies: 29
Author Content
erikb5

Dec 04, 2007
12:09 AM EDT
Using a swap space that is twice the physical memory is a rule of thumb approach. After having long conversations with a few RHEL trainers a few years ago, we came up with calculation, what a good swap for a Workstation/Server would be about 113% of the physical memory (1GB Physical, Swap 1.13GB). This would cover the needs of the Swap 1:1 Physical/Disk plus have enough additional swap space for extra tasks and processes, but not enough to waist space on disks (space that is cheaper each year). Anyway, if you have too much swap space and it starts swapping like crazy... you're system will become unresponsive = unusable...

But every can have it's own idea on this very very vast topic.
jezuch

Dec 04, 2007
2:28 AM EDT
This "twice the RAM swap" rule seems strange to me. I would think that if you have more RAM, you need *less* swap. But perhaps it's this law of programming that software is like gas - it expands to fill the space available ;)
dinotrac

Dec 04, 2007
4:09 AM EDT
jezuch -

Yes, you are correct. Ironic, eh? Virtual memory was implemented as a way to make our memory seem larger than it really is, but we increase it when we increase the size our memory really is. Hmmmmm....

In my bad old days as a mainframe performance geek, rules-of-thumb were the bane of my existence.

The trouble is that rules of thumb are OK so long as your use fits normal patterns. I worked for a company that pushed the technology to the limit, so rules of thumb fell apart all over the place. Real PITA whenever I encountered a new manager who wasn't familiar with the oddities of our environment.

In Linuxland, some rules of thumb are born of

a) days of scarcity. It hasn't really been that long that gigabytes of RAM were very common on relatively small machines

b) multi-user Lots of users = lots of address spaces = lots of virtual RAM = pressure on memory.

A form of b lives with us, even in desktops, however. Those multiple users tend to be replace by a pile of processes in a modern GUI-equipped workstation.

Still -- 2:1 is probably goofy on a workstation with lots of ram. Sure, the disk space wasted is cheap, but, if you really use that much virtual, you're likely to have more going on than you really want to deal with.

Sander_Marechal

Dec 04, 2007
5:33 AM EDT
There's another reason why you would want 1:1 or even more swap on a Linux machine: The ability to suspend to swap.
dinotrac

Dec 04, 2007
6:01 AM EDT
Sander -

Yes.

One must not forget laptop land.
vainrveenr

Dec 04, 2007
7:34 AM EDT
Several sources give consistent swap-space suggestions for systems about a half dozen years old, when the typical desktop worstation had RAM in the range of something like 64MB to 512MB :

1. For Slackware Linux http://www.slackbook.org/html/booting-dual.html
Quoting:You would also want to set aside an adequate amount of space for a Linux swap partition. The unwritten rule is to use twice the amount of RAM you have in disk space. A 64MB system would have 128MB of swap, and so on. Adequate swap space is the discussion of many flames on IRC and Usenet. There's no truly “right” way to do it, but sticking with the rule above should be sufficient.


2. For MS-Windows 9x and NT http://articles.techrepublic.com.com/5100-6345-1057031.html http://articles.techrepublic.com.com/5100-6346-1056636.html http://www.windowsitlibrary.com/Content/226/06/1.html

From these pieces are the "rules" Pagefile = RAM + 12 MB [e.g., 128 MB physical + 12 MB extra = 140 MB total] Minimum Pagefile = RAM + 100 MB Maximum Pagefile = Minimum + 20 percent

The interesting point here is that even with the old MS-Windows NT 4.0 and the just-arriving Windows 2000 (piece written in 2001), these pagefiles "rules" have the similar 113% mentioned above for Linux.

3. For MS-Windows 2000/XP http://www.petri.co.il/pagefile_optimization.htm http://www.g4tv.com/techtvvault/features/36099/Optimize_Wind... http://www.aumha.org/win5/a/xpvm.php

Here we have suggestions of page files (same as swap space here) ranging from 1.5:1 to 2:1 -- i.e., 1.5 to 2 times the amount of physical memory installed. The last of these three specifically discusses how paging memory should be variably set for XP and should NOT use the given 1.5 : 1 to 2.5 : 1 rules-of-thumb. Also from this,
Quoting:Why is there so little Free RAM?

Windows will always try to find some use for all of RAM — even a trivial one. If nothing else it will retain code of programs in RAM after they exit, in case they are needed again. Anything left over will be used to cache further files — just in case they are needed. But these uses will be dropped instantly should some other use come along. Thus there should rarely be any significant amount of RAM ‘free’. That term is a misnomer — it ought to be ‘RAM for which Windows can currently find no possible use’. The adage is: ‘Free RAM is wasted RAM’. Programs that purport to ‘manage’ or ‘free up’ RAM are pandering to a delusion that only such ‘Free’ RAM is available for fresh uses. That is not true, and these programs often result in reduced performance and may result in run-away growth of the page file.


Although this last point very specifically applies to XP, even for Linux with too much swap space, similar negative performance results could happen for physical RAM in excess of 512MB using a 2:1 swap ratio. As noted above, "Sure, the disk space wasted is cheap, but, if you really use that much virtual, you're likely to have more going on than you really want to deal with." !!

Bob_Robertson

Dec 04, 2007
10:51 AM EDT
I've often wondered about swap requirements, or suggestions. Sure I can see a reason to have swap, even on a system that has lots of RAM: Take away the ceiling for those few times that that ceiling might get hit.

But that "suspend to swap" mentioned above, I like it! Great idea!

Dino, when I was working in mainframe-land myself, I noticed that the only manager that the systems programmers and DBAs respected was the one that spent visible time turned around and online himself, not just shuffling papers on his desk.

Now, if you will excuse me, I have to lie down. I'm having JES-2 flashbacks.

azerthoth

Dec 04, 2007
11:51 AM EDT
I tossed that rule of thumb out the windows (pun intended) a long time ago. Using a 64bit distro and compiling the software for 64bit enviroment doing media transcodes, which will suck every available resource that you can throw at it dry, I have yet to even touch swapspace.

My new rule, when running 2 gig or more of memory, give it 512meg just to be happy. If you crack into that 512 odds are your disk I/O was already bottlenecking your system and the cached disk writes are what is driving you up.
techiem2

Dec 04, 2007
12:14 PM EDT
Yaknow, I've wondered about that lately. In the last year or two I've noticed linux docs saying you don't HAVE to have a swap partition, but it's still recommended.

I've also notice that on my machine with 2GB, the RAM usage rarely goes above 1GB, and and the swap is even more rarely even touched. About the only time my RAM usage goes above 1GB during typical usage is when I've left firefox running for days on end with tabs and tabs and more tabs and the memory leaks. Once I notice it slowing down, the RAM usage is generally around 1.2GB, so I restart FF to get it back down to the 500-600MB range. :)

So I guess I could reclaim most of that 4GB swap partition.....

Bob_Robertson

Dec 04, 2007
1:07 PM EDT
Firefox _still_ has Netscape's memory leak problem?

Gee. I guess, like my cholesterol level, there are some things you just have to blame on the family tree.
jdixon

Dec 04, 2007
1:26 PM EDT
> Firefox _still_ has Netscape's memory leak problem?

It has at least one memory leak problem. Whether it's one of the many Netscape had is debatable.
Bob_Robertson

Dec 04, 2007
1:49 PM EDT
"It is a logical fallacy to go from 'everyone must submit their arbitration to a 3rd party' to 'there must be a 3rd party to which everyone submits their arbitration'."

So that makes perfect sense. It has at least one memory leak, but there is no way to know that it/they are the same memory leak(s). Very likely why I use Konqueror for everything for which Konqueror works.

:^)

I couldn't help it, it just came out.

ColonelPanik

Dec 04, 2007
2:02 PM EDT
GNOME + Konqueror? That would be cool.
gus3

Dec 04, 2007
8:32 PM EDT
I doubt the Firefox memory consumption is actually a "leak". It's retaining a history of pages and closed tabs, as well as pre-rendered stuff. This was touted as a "feature" in FF2, to help speed things up.
jacog

Dec 05, 2007
2:43 AM EDT
Ah yes, the old "It's not a bug, it's a feature." quip.
Bob_Robertson

Dec 05, 2007
3:35 AM EDT
> GNOME + Konqueror? That would be cool.

Debian. GNOME and KDE apps run just fine together, on whatever "desktop".
techiem2

Dec 05, 2007
10:09 AM EDT
Quoting:I doubt the Firefox memory consumption is actually a "leak". It's retaining a history of pages and closed tabs, as well as pre-rendered stuff. This was touted as a "feature" in FF2, to help speed things up.


I'll have to double check when I get home, but I believe I have the tab history disabled as well as page caching, so it should only be retaining page history.

And I doubt that would amount to 600MB+ of RAM usage over the course of a few days. :)
tuxchick

Dec 05, 2007
10:26 AM EDT
Whatever it is, gus, it made Firefox unusable for me because the sucker would cause slowdowns and then hard lockups on my nice Linux boxes. And the dev team are a big bunch of wankers, because users have been complaining about this for years, and filing bug reports, which were dismissed with a huffy 'well it's not a memory leak, so buzz off', instead of trying to figure out why it was misbehaving. Linux Firefox users are unwanted stepchildren, anyway.
jdixon

Dec 05, 2007
10:31 AM EDT
> And I doubt that would amount to 600MB+ of RAM usage over the course of a few days.

I've seen the effects of letting Firefox run for more than two days first hand. Something is definitely chewing up memory. Whether they call it a memory leak or not is beside the point. Closing and restarting Firefox clears up the problem, at least for me
techiem2

Dec 05, 2007
11:20 AM EDT
Same here. When I notice it slowing down, I close and restart it. Then it's happy for a few more days.
Bob_Robertson

Dec 05, 2007
11:46 AM EDT
I think I haven't seen the problem because I only open Firefox (aka Iceweasel) to view specific sites such as Google Video, YouTube and the finer functions of Gmail and my bank. And when I'm done I close it.

F/OSS does have one major benefit over the proprietary and "Windows" mind-set, agnosticism. Right-click on a link in Konqueror, and one of my options is "Open link in Iceweasel".

There's never a need to ask "X isn't your default browser", because it's entirely configurable without having to make it automatic or whatever. No one is trying to grab your eyes.
dinotrac

Dec 05, 2007
1:25 PM EDT
tc -

Yes, they are wankers, but they always have been.

Remember the need to toss the Netscape codebase because it was a waste?

Essentially an act of Mozilla turning their backs on users to pursue their own ideas and claim the mantle of Netscape legitimacy.

Good thing that

a) Microsoft took its eye off the prize and let IE get even worse. b) Konqueror!!!!!! and Opera were available.

Now the Firefox folk don't care about the poor dumb users. Again!!! But hey, they can't blame the Netscape legacy. After all, the current code base is the wonderful new stuff they developed to bring us all into Nirvana.
hkwint

Dec 05, 2007
2:15 PM EDT
Back to the topic: On this particular PC I'm using at this moment (512MB RAMGentoo + Windowmaker so NO KDE or Gnome!) I never took the effort to create or use a swap partition in first place, untill two months ago or so. That basically means I used this PC without any swap but also without any problem for more than a year (and yes, I did use FF with crappy plugins a lot!) OpenOffice works fine too wile FF runs, no problem at all. Only thing was Azureus, but that's because the number of processes was limited to 100 in /etc/security.conf, and it works fine too at this moment. Azureus, OOo and FF at the same time seems like a lot to me, so if this doesn't need swap, than which house-garden-kitchen apps would?

One time, XMMS was using up all my RAM, and it took like half an hour every time before it halted my computer (hard lock up). I was glad I didn't use swap, because it would only have lasted longer for the memory to fill up (same for Firefox once, but for Firefox it only took three minutes to fill up the 512MB, but normally it is because of the extensions). It also makes finding out where the memory goes to easier, since there's only RAM.

Sometimes I wonder, why do we need swap anyway for machines with >=512MB? Frankly, I don't need it. Using a partition for swap is also a sad thing to do; I prefer to do it the MS-Windows way (honest!) and just use a file, so I don't have to repartition the darn thing if I want to use more or less swap.

But hey, that's just me. Most people are running Gnome instead of Windowmaker, Amarok instead of Audacious, and what have you. More than 1G RAM for Linux seems rather outrageous to me anyway, except for VM's or when doing CAD with 10.000+ parts, but since most of us aren't doing that I don't see the advantage of 6GB virtual RAM?
Bob_Robertson

Dec 06, 2007
9:36 AM EDT
Well, let's see. I run KDE. I have two Konqueror instances with about 8 tabs open, kmail, konsole. That's usual.

Just for kicks, I opened OpenOffice Write, OO Presenter and Google Earth to see what would happen.

# free total used free shared buffers cached Mem: 514576 508384 6192 0 1976 115784 -/+ buffers/cache: 390624 123952 Swap: 1510068 45588 1464480

So that's 45M of swap being used, but 123M of buffer space _not_ being used. Which tells me that, if I had no swap, the system would still be doing everything I'm asking it to do.

Linux systems do seem sufficiently frugal on resources. I think I'll go find the "swap off" command, and then use the system to see what happens without swap.

In this discussion, what has been the most interesting aspect is finding out that Linux will use a swap file, not just a swap partition. That's great, especially if I choose to install on an existing system where repartitioning isn't a viable option.
Bob_Robertson

Dec 06, 2007
9:39 AM EDT
One more comment. The last time I rebuilt my wife's windows machine, I created a swap partition on her disk. I was already using Knoppix for partitioning/formatting, since I wanted her XP machine to use FAT so I wouldn't have to worry about accessing the file system from a Linux boot disk at need.

Then NTFS became fully supported, so my reasoning was moot. Oh well.

At least, when I do boot Knoppix, the swap space is available and very nice to have. Much better than reading stuff from the CD all the time.
hkwint

Dec 06, 2007
3:11 PM EDT
Quoting:I think I'll go find the "swap off" command


Quick&dirty (I was lazy):

$sudo /sbin/swapoff $(awk '{print $1}' /proc/swaps|grep -v Filename|xargs)

Just found out swap can use files and partitions at the same time in a 'distributed' manner, but the above line handles it all.
jezuch

Dec 07, 2007
1:48 AM EDT
Uh, what about swapoff -a ?
hkwint

Dec 07, 2007
2:14 AM EDT
Even better!
Bob_Robertson

Dec 07, 2007
3:49 AM EDT
Since it's in the /etc/fstab list,

# swapoff -a # swapon -a

I'm even lazier. :^)

Bob_Robertson

Dec 07, 2007
3:51 AM EDT
Ah, that's what I get for not refreshing the thread (left up last night) before replying.

Posting in this forum is limited to members of the group: [ForumMods, SITEADMINS, MEMBERS.]

Becoming a member of LXer is easy and free. Join Us!