Tugger the SLUGger!SLUG Mailing List Archives

Re: [SLUG] Oddball memory usage?


On 22/02/07, Peter Hardy <peter@xxxxxxxxxxxxxxxxxxxx> wrote:
On Thu, 2007-02-22 at 16:24 +1100, Zhasper wrote:
> On 22/02/07, Peter Hardy <peter@xxxxxxxxxxxxxxxxxxxx> wrote:
> > I'm a little puzzled by this:
> >
> >               total       used       free     shared    buffers     cached
> > Mem:        5005084    4816352     188732          0     156644    3165540
> > -/+ buffers/cache:     1494168    3510916
> > Swap:       1052616    1052616          0
> >
> > Is this sort of usage normal? Filling a gigabyte of swap space while
> > just under 1.5GB of memory is going towards buffers seems odd to me. And
> > vmstat reports no usage of this swap space over a 15 minute period.
> >
> > What sort of utilities are around to analyse swap space? I'd like to get
> > an idea of exactly what's using all of that memory.
>
> You're running Linux, right?

Aye. It's a 2.4 kernel dating from somewhere before swappiness became
tuneable.

> This can be really great on a system with not much ram where large
> apps that you haven't used in a while (eg, OOo) will get swapped out
> when they're not being used, to make lots of space to cache all the
> pr0^H^H^Himages of your grandmother's birthday party that you're
> scanning through agressively..

In my rush to be as detailed as possible, I completely forgot to mention
what the machine in question is actually doing. Well, it's a web server
for a single (fairly high-traffic) domain. Apart from apache and the web
application software, there's nothing running on it apart from the usual
collection of processes that are essential to a well behave unix system.
init, crond, syslogd.

I'd be looking at top (or other tools which give similar output),
particular at the "RES" and "VIRT" columns. VIRT shows the total
amount of memory used by a process; RES shows the amount of that
that's located in RAM (the rest has been swapped out)

Given what you said, my two-seconds-thought-while-sitting-in-armchair
hunch is that Apache (or more likely, come CGI you're using) does have
some kind of memory leak, and is slowly gobbling ram - but the kernel
is smart enough to see that the pages, although claimed, are unused,
so it's swapping them.

I would also guess that your site either has a lot of static content
which, rather than being read from disk a lot, the kernel is caching
in ram. You mentioned web application software, so it could be files
used by that too - config files, databases, etc.

Check your RRDTool graphs to see if swap/memory usage has been growing
over time - particular that really handy graph that differentiates
between buffers/cache/actually-used-by-applications ram usage, so that
you can see if, perhaps, the amount of "used" and "buffers/cache" have
remained about the same, while swap usage has been creeping up

I think I'm agreeing with everyone else - the kernel usually does a
pretty good job of handling the balance between buffers/cache and
application ram. If you're seeing performance issues, check
sar/iostat/vmstat/similar to see if there's a lot of swapping
happening; if that's the case, you might have a problem. If there's a
lot of disk IO that's not swapping, you might have the opposite
problem - not enough swapped out to cache all the frequently used
files.

Either way, extra ram should help a lot, and extra swap may help out
as well - allow more files to be cached, at the expense of infrequent
extreme performance issues as those files get dumped from ram as the
system frantically swaps pages back in...

The other possibility is that you actually do have a memory leak,
which is going to be a lot of fun.

As always, monitoring is your friend... Looking at the output of free
tells you what the system is like now, looking at historical trends
tells you how it got there - whether this is a normal condition,
something that has gradually arisen, or something that abruptly
occured overnight...


This is easily the biggest system I've found myself responsible for, and
the way the memory's been allocated doesn't line up with anything else
I've seen before. Just curious as to how and why it's being used like
this.



--
There is nothing more worthy of contempt than a man who quotes himself
- Zhasper, 2004