View Full Version : Memory Management

22nd March 2005, 06:54 PM
I have noticed this before, and talked about this is a prior thread, but now have decided to create a new thread for it.

I have two machines, one is a Intel PIV 3.0Ghz w/ HT and 2gigs of RAM. It does not run xwindows, it is strictley a dedicated server host. Hosting websites only. It runs Fedora Core 1.

The other is my box which is an AMD Duron 800 with 768megs of ram. It runs Fedora Core 3.

Both seem to start out good on ram usage. Like Machine 1 will use 600megs starting out.. then after uptime of a couple days, it will be down to like 100megs free.. of the 2gigs it has. Running Top, free, and ps -aux doesn't show any major % usage of ram. The usual .7 for each httpd thread, .9 for each mysql thread, etc. But here is the output of free:

[root@server root]# free
total used free shared buffers cached
Mem: 2067164 1995784 71380 0 102676 1509636
-/+ buffers/cache: 383472 1683692
Swap: 2040232 1992 2038240

The other machine is the same way. It starts out only consuming like 400 megs. Then it ends up only have 50 megs free. here is its free:

[daniel@core ~]$ free
total used free shared buffers cached
Mem: 775856 729864 45992 0 181028 78792
-/+ buffers/cache: 470044 305812
Swap: 1572856 208 1572648

Its the same way, nothing in ps -aux is chewing up ram. Same with top. I guess it is putting it all in cache?? Does it ever flush this? Is it bad to have everything cached? As you can see, both are starting to use swap now.

22nd March 2005, 07:35 PM
This is normal, and good.

Keeping things in cache means that they can be retrieved much faster (memory is thousands of times faster than disk access). Even though the information in the cache is written ("flushed" - every five seconds by default on ext3), a copy is kept in cache for quick access.

When the system needs memory it will use some of the cache memory. Memory contents that haven't been used in a while will get pushed into swap. By arranging memory this way, the most used information is "closest" to the CPU.

There are many tuning knobs that allow you to control the system's use of memory. However, subject matter experts in virtual memory tuning recommend the setting that you are using by default. Changing the knobs can have unexpected consequences (even potentially causing loss of data, if the filesystem commit time is extended on an active system).

If you'd like to start learning about the interactions beween the filesystem, virtual memory, and other settings (like laptop mode), this book (http://www.amazon.com/exec/obidos/tg/detail/-/0596002130/qid=1111516370/sr=8-2/ref=pd_csp_2/002-9992523-2109627?v=glance&s=books&n=507846) is probably a good place to start.

22nd March 2005, 07:46 PM
I don't understand people that buy loads of memory and then expect it to be unused... :)

22nd March 2005, 08:11 PM
ROFLMAO, I was fired from a consulting position once when I tuned their Vax-Cluster to use all of it's RAM on each node, the sucker screamed (for a computer at the time), but it REALLY made the administrator angry when he got back from vacation, I think I made him look bad. ;)

I really don't understand people who want to see a lot of "free" memory, that's just money you spent on memory that you aren't using it. You paid for it, might as well use it, and your operating system will be happier too!

22nd March 2005, 08:30 PM
I couldn't remember how it accessed. I was under the impressesion an application would call ram as it needed it, then clear it when it was finished. But instead it holds it lets the calls sit in cache, which is far more efficient when needing to access the same data. So technically, the ram is only caching the data, not really in "use". I didn't expect to see a ton of "free" memory, I just didn't understand if it was all in "use" or just "cached".

10th August 2005, 11:35 AM
I appreciated above comments, that RAM should be used but not FREE !

My case is similar installed FC3, the free memory is little (mostly) out of 512MB.

However, I found my cache is sometimes not much (32MB e.g.).

so I check the ps and seen most memory is being used by around (usually) 20 httpd (each 6% total mem) processes.....

1) is this also normal ?
2) why httpd not free up mem (the memory limit is 16M shown in phpinfo.php)
3) if not normal, how to config the solution for this ?
(meant I want each httpd use less memory and maximize them (allow more httpd processes)) ?
(but not just keep mem free).

Thanks for opinions.

Matthew (Hong Kong)