Memory management
Administrating a server can be done on many levels. Basic monitoring should be done on a regular basis. This keeps you informed as to the general condition of your server and may warn of impending problems.
This article concentrates on memory management.
Memory management is actually very easy to do. What you do about any problem is a different matter and we'll look at monitoring what is using the memory in a later article.
To start with, log into your server and give the 'free' command:
free
The output consists of four lines:
Well, for a start, that's all a bit confusing as the answer is in Kb. I don't know about you but dividing the reported figures by 1024 is a bit of a pain. Let's make it more readable by adding the '-m' option. Asking the man tells us that 'the -m switch displays it in megabytes':
free -m
That's better:
The first line tells us what is being reported: total, used, free and so on. A common mistake is to read the second line and have a panic attack as that line reports:
. total used free shared buffers cached
Mem: 254 248 6 0 70 21
However, the figure of 248 out of 254MB includes cached and buffered memory.
Put simply: ignore this line!
Concentrate on the third line:
. total used free shared buffers cached
Mem: 254 248 6 0 70 21
-/+ buffers/cache: 157 97
This tells us what memory is actually being used.
This line reports 157 of 254MB being used by various tasks and applications. I have 97MB to play with and for my application to grow into.
Still not great and, if I wanted to, I could try to optimise any installs to reduce the memory usage.
The final line tells me how much swap space I am using (A VPS not using the XEN framework may not have swap available - they usually have a 'burst' RAM capability which, almost, acts like swap space):
. total used free shared buffers cached
Mem: 254 248 6 0 70 21
-/+ buffers/cache: 157 97
Swap: 511 0 511
As you can see, I have 511MB of swap available and have used none of it. That's a Good Thing . If you are using swap space then you need to investigate what is using so much memory that it had to resort to hard drive swapping to work. Usually it's a case of your application 'outgrowing' your VPS and you may need to scale up to include more RAM.
Actually, that's a good example as to why regular monitoring of your server is a good idea - your site may be up and running but it may be struggling and becoming slower and slower.
It's a lot better to catch any concerns before they result in downtime and a non-operational site.
That's it - quick and easy. Next time we'll look at system monitoring with 'top' which can help pinpoint what is using memory and how much.
PickledOnion.
Digg it |
del.icio.us |
reddit |
StumbleUpon

Subscribe to Feed
Article Comments:
Ron 16 May, 2007
Cool article. Apart from top, the following command is be very useful in determining which processes are memory-intensive. It immediately lists all processes by memory usage in descending order:
ps auxk-rssPickledOnion 16 May, 2007
Thanks for the code Ron. I'll repeat your tip in the 'top' article in case it's missed here.