APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds RSS Feeds











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version
->
-> Where's the memory?


Where's the memory?



I had happened across How To Remotely Monitor Memory Usage and smiled when I saw this :

As one example of this phenomenon, the SUSE Linux system that I use for my public Web and e-mail server originally only had 512 MB of RAM. This should have been more than adequate for the lightweight load that I was expecting, but the system tools showed that the box was constantly running low on memory. And even after I bumped it up to a full gigabyte, the system still complained.

I had just gotten ready to add another gigabyte when I discovered that most of the memory was actually being consumed by SUSE's aggressive disk-caching algorithm. Every time I added more memory, the operating system drank it up for the disk cache. In reality I was nowhere near hitting any kind of memory limit for the applications themselves, even with just 512 MB.

"That's how Linux memory works", I thought to myself, "he should have known that."

Well, yeah, he probably should have. That once again points out the danger of assuming you know what's going on based upon your knowledge of other systems. Being an expert at Solaris is helpful with Linux but it can also lead you astray. The opposite is just as true, of course.

But knowing something about "Linux" in general can also send you down the wrong path. I said that's how Linux memory works, but that isn't necessarily true either. The same article goes on to say:

RedHat and SUSE have substantially different algorithms when it comes to allocating cache memory. Where SUSE is very aggressive and tries to make full use of the available memory, RedHat leaves unused memory lying around in case it's suddenly needed by something.



So if you've "learned" that Linux uses available memory for buffer caching, a RedHat system that doesn't could confuse you. But wait - that's not all.

"Swappiness" was introduced in 2.6 kernels. When some program wants more ram and the kernel has a bunch being used for caching, it could give up some of that. Or it could just make some other less active program swap out to disk. Which is a better idea? Well, of course that depends on what is going on right now. If there is heavy disk activity and programs that really aren't being used, it would make sense to swap. If there isn't much disk activity, or those swappable programs are apt to become active very soon, it makes sense to give back memory.

The idea was that the admin knows best what his system might require, so the admin should be able to say how much "swappiness" is desirable. If swappiness was set to zero (echo 0 >/proc/sys/vm/swappiness), the kernel would give up cache to anything that wanted ram; if it were set to 100 it would do the opposite and let the processes swap.

Well, great, but what if you don't have a clue because sometimes your system has unused apps and sometimes it doesn't.? No problem, somebody came up with something that would make a good guess on the fly: Autoregulated VM Swappiness Patch.

"[The] amount of swap space consumed is also taken into account, and the size of it compared to the physical ram is taken into consideration when making its effect on the value of swappiness. With this patch, this should make any machine that has swapspace as resistant to OOM as possible. This version by default autoregulates the swappiness, but also allows you to choose a manual setting if you so desire by echo 0 > /proc/sys/vm/autoswappiness and then setting the swappiness the manual way as previously. This makes comparison with autoregulation easy."



But then: ( Bugzilla Bug 54560):

As of 2.6.7, gentoo-dev-sources no longer contains the Con Kolivas autoregulated swappiness patch. This is important for desktop machines, to avoid having large amounts of memory swapped out on prolonged system inactivity (causing an annoying swapstorm when the machine is used again).



Desktops and laptops are apt to sit unused for long periods. Therefore unused processes tend to get swapped. If the kernel were really smart, it would notice that *nothing* of importance is happening and just leave things as is, but apparently we haven't reached that point yet. Or if we could have so much real physical ram that we could eliminate swapping entirely..

Well, the minute you say "eliminate swap", someone will point out that you *need* swap. There's a long discussion of swap and ram at Kernel trap: Is Swap Necessary?, but most of the conversation there is at cross-purposes. For multi-user machines, you definitely want swap because you want to be able to be truly interactive: moving one program aside so that another can run. But for a single user machine, you may not want to swap: it might be preferable to have the system refuse to start up a new app and let you decide what you'd rather get rid of to make room for it.

Or maybe not. I'm in favor of control, but the default probably should be to swap. Then again, maybe the default for desktops and laptops should be different.. it remains a complicated and difficult subject.




If this page was useful to you, please help others find it:  





1 comment




More Articles by - Find me on Google+



Click here to add your comments
- no registration needed!




Sat Jun 17 22:31:58 2006: 2126   drag


Ya.. this was a huge deal for a long time. People bitching about how when they would come back to their machines after a few hours of inactivity would watch the machine chug a bit as they openned up Mozilla and everything came back to life.

One of the deals is, however, that as your gone the machine still does have activity. Not a big deal, but you have your hourly and daily cron job. For instance you run updatedb which builds your man file database and 'locate' command database and such. So there is always something going on.

So I think that 'swapiness' was a sort of a comprimize. People would complain and kernel developers would say something along the lines of "What you want isn't going to do what you think it will do and your not going to like it". But even then it makes sense to regulate it somewhat so users could set the swapiness to 'unswap' or whatever and find out for themselves.

I learned memory management the 'wrong way' with messing around with Windows 95 and 98. I had to arrange it so that as much memory was free so it could be used for my games as possible. With Linux I tried the 'memory reduction' technics I learned from Windows 98 (remove unused services, strip down X, only run certain programs, pay carefull attention to memory usage) but then when I would do anything the memory usage would actually go up! I was a bit shocked.

But then I learned about operating systems that actually have effective memory management and Linux's 'Unused memory is wasted memory' concept and it all made sense.

Nowadays to me the most efficient memory management is about how much RAM you can use and still never have to access harddrive swap during heavy use.

Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar

Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

I am a Kerio reseller. Articles here related to Kerio products reflect my honest opinion, but I do have an obvious interest in selling those products also.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.

pavatar.jpg

This post tagged:

       - Kernel
       - Linux
       - Memory
       - Performance
       - Unix















My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!


book graphic unix and linux troubleshooting guide



Buy Kerio from a dealer
who knows tech:
I sell and support

Kerio Connect Mail server, Control, Workspace and Operator licenses and subscription renewals



Click and enter your name and phone number to call me about Kerio® products right now (Flash required)