PDA

View Full Version : Good Memory Tool/Technique


OOagent137
2003-08-11, 09:51 AM
After running free -m, I found that I have a bunch of memory taken up.

What I want is an explanation, in megabytes, of where my memory is going? I mean, top doesn't seem to help b/c it can only sort by memory percentage.

I tried top -m | grep M and it displays all the entries that are taking up megabytes, but that only shows maybe 120mb worth of stuff (we have a total of 480mb being taken up).

Also, it shows httpd will be taking up 15mb of memory or so (there will be several entries like that). I have Apache on extended mode, so is there any way to time the process so I can match the PIDs to figure out what websties are eating up my memory?

Now, I might actually have this information available to me in the Apache Extended mode. I'm just not sure. I have the following columns in the extended mode:

Conn Kilobytes transferred this connection
Child Megabytes transferred this child
Slot Total megabytes transferred this slot

I don't quite understand what those mean. Could anyone explain them?

Basically, I just want to be able to figure out what sort of memory each site is taking up AND sort every server process by memory size (couldn't figure out how to do this w/ top). That SHOULD be simple enough :)

knightfoo
2003-08-11, 19:54 PM
The output of free-m can be a little misleading if you do not look at the right numbers. For example:

# free -m
total used free shared buffers cached
Mem: 1009 990 18 0 35 824
-/+ buffers/cache: 130 878
Swap: 1027 4 1023

This server has 1GB total memory .. and only 18MB free? Nope. The kernel allocates almost all of the available memory so it is able to manage memory and manage filesystem caching. If you subtract the amount of memory being used for filesystem caching (look at the buffers/cache line) you will see how much memory is really free .. 878MB. This is split up like this because memory being used for buffers and cache is immediately freed if a process needs memory.

Running top and hitting "M" will give you a good idea of what processes are using the most memory. You can also use the command "ps aux | sort -k5" to sort out the big memory users. You mentioned httpd using about 15MB of memory .. you might also notice that all of the httpd processes use the same amount. This is due to the fact that httpd (and many other forking or threading daemons) share their memory pool, so all of the processes use the same 15MB of memory. If your sites are simple HTML, then there really isn't much of a hit on memory and you don't have to worry about tracking it. The big memory hogs are PHP and Perl (especially if they are poorly written) but there are ways to limit these to certain amounts of memory (see my other posts about Apache RLimit* directives).

-knightfoo

OOagent137
2003-08-12, 01:46 AM
Knightfoo, I appreciate the reply.

Thanks for letting me know that, I feel a whole lot better now. I actually have half my memory free still :)

That command "ps aux | sort -k5" is a good command and I like that a bit better than the one I came up. I'm wondering (still new to this linux thing, obviously) what the sort -k5 is?

As far as your limits post goes, I looked at it and the included link, and I have a few questions about it. One of them has been answered, but the others remained unanswered (hint hint :) )

http://www.serverbeach.com/forums/showthread.php?threadid=234

Anyway, you've helped me out a bunch and I thank you for that. You reflect very well on SB.