[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Memory usage on debian



Colin Watson wrote:
> On Fri, Jan 24, 2003 at 05:53:19PM -0500, Jason McCarty wrote:
> > So, I understand the output of "free" and all that, but can anyone
> > explain the behavior shown below? This after my computer has been up for
> > a couple hours, doing very little. It usually shows this behavior,
> > especially if I've run a lot of programs first. It seems like memory is
> > being reclaimed from somewhere (kernel data? X11?) without free knowing
> > about it.
 
> The usual cause of this one is as follows: to start with, you have a
> fairly quiet system with lots of data in the kernel's cache - see the
> 'buffers' and 'cached' entries - held there against the possibility that
> it will be needed in the future. Then you run a program that asks for a
> lot of memory. A program running now is of course more important than
> data cached for the future, so, when it runs out of other memory to
> allocate, the kernel throws that data away and gives the reclaimed
> memory to your program. In fact, it eats through about 78Mb of the cache
> like this before it exits.
> 
> When the program does finally exit, it hasn't really done anything
> cacheable: the kernel can cache the executable itself, but nothing else.
> Therefore, it just frees up all the formerly-cached memory your program
> munched through. As time goes on, you'll probably see the count of used
> memory start to swing back towards the previous steady state.

Colin,

Thanks for the response, but I don't think that explains it. The
-/+ buffers/cache line is supposed to eliminate the contribution of cache
already, so sucking all the memory shouldn't change that line too much.
But instead it changed by 78 MB.

Anyway, in trying to figure out what was going on, I found a thread on
LKML [1] about a similar question. Apparently, the inode cache isn't
included in the kernel's memory reports, but only in /proc/slabinfo.
Furthermore, it is only reclaimed when no other memory is available,
which explains why I get these seeming memory leaks that go away when I
malloc all the memory.

I went so far as to write a script to sum the values reported in
/proc/slabinfo, which closely agrees with how much my apparent memory
usage shrinks when I run my memory-eater.
  echo 0 `tail +2 /proc/slabinfo | awk '{print $3, $4, "* +"}'` 1 k \
  1048576 / p | dc

[1] http://www.uwsg.iu.edu/hypermail/linux/kernel/0103.2/0461.html,
    http://www.uwsg.iu.edu/hypermail/linux/kernel/0103.2/0477.html

Hope this interests somebody besides myself ;)

Jason



Reply to: