How do I find out what's using the memory on a Linux box
I have a Linux server with about 20 websites on it. None of them (as far as I know) receives a particularly large amount of traffic.
Recently we've been getting out of memory errors in PHP pages across various web sites on that server, e.g. Quote:
# free ... it seems that most of the memory is in use: Code:
total used free shared buffers cached # top ... and hit "M" to sort by memory usage. The results don't seem to lead me anywhere: Code:
PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME CPU COMMAND Is top the wrong tool to be using to profile memory? Is there another way to see what's causing the large amount of memory to be used? Thanks and take care, Antun |
Quote:
The bigger question I have is why you have 463MB of RAM free for applications, but your machine is swapping 95MB... |
All you memory is being used by PHP.
Quote:
So you need to find out whats wrong with that script and why its using all your memory. |
What do you mean - is that something that I mis-set? Is there a place on a Linux machine where you can configure how much memory it allocates for different tasks?
-Antun Quote:
|
Thanks, but it's not just that PHP script that's throwing that error. Other scripts are throwing it too. So it's not that particular PHP script, but I guess it could be *any* PHP script.
What I'm trying to do is figure out what script or service is using up all the memory and leaving none for PHP. If PHP is using up all the memory, how come it doesn't show up on top? Will some things not get written out to top? Take care, Antun Quote:
|
Something in the script, like a variable, is becoming too large and using all the memory. It looks like the script currently has access to the entire amount of memory. There will be a file called php.ini usually in /etc/ that has a setting called memory_limit. If you set that to something like 8M it will limit the PHP script to only be able to use 8megs of ram. But you will still have the problem of that script failing, it will just fail earlier.
|
The /etc/php.ini file caps the amount of memory for a PHP script to 300MB at the moment. That's in the global /etc/php.ini. We use Ensim control panel to divide the server into separate sites, each of which has its own php.ini file. The one for the site in question has memory_limit = 32M.
The error I'm getting says this: Quote:
-Antun Quote:
|
Whoops my bad. Calculated the amount wrong.
In top make sure it is showing both RES and VIRT memory usages. |
My version of top doesn't seem to have RES and VIRT. The man page says that SIZE (which is displayed in the output I get) is the virtual size of the process (code+data+stack). I'm guessing that VIRT is the virtual size, so it appears that I am seeing that value.
I'm not sure what RES is. Take care, Antun Quote:
|
You could give `ps aux` a try see if that gives you any helpful information.
|
Wow - that turns up some much more interesting information.
There are a bunch of apache processes guzzling 40% of my memory. I wonder why top didn't show anything like that up and ps did? -Antun Quote:
|
Quote:
Run top, then type "G1", or "G2", or "G3", or "G4" to switch between the various groups (you need to use a capital "G"). Default display is "G1", but "G3" is the memory group. Quote:
|
Quote:
When using ps, often times the display of the command being run is truncated, to fit your horizontal screen width. Add a few w's to the command to make it "wide", "wider", "widest" Code:
$ ps aux |
All times are GMT -5. The time now is 09:29 AM. |