linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Berend De Schouwer <bds@jhb.ucs.co.za>
To: linux-mm <linux-mm@kvack.org>
Subject: Memory usage doesn't add up
Date: Mon, 12 Jan 2004 13:35:02 +0200	[thread overview]
Message-ID: <200401121335.03027.bds@jhb.ucs.co.za> (raw)

Hi,

I have a machine that, after some uptime, constantly swaps.  It looks like an 
application eats too much memory, but running 'top' doesn't add up.  I'd like 
a crash course in ps and tops various memory columns.  Google for "linux 
memory usage" doesn't help :)

Err, first things first:

linux 2.4.20, RedHat 9 updates kernel.  512MB RAM.  600MB Swap.  Confirmed 
constant si/so with vmstat.  Runs Java (Sun) and postgresql.

As far as I know, memory-used-by-applications == 'Mem:used' + 'Swap:used' - 
buffers - cached, as reported by free and top:

So if I have:

# free
             total       used       free     shared    buffers     cached
Mem:        513832     504812       9020          0      30712     175616
-/+ buffers/cache:     298484     215348
Swap:       522104     106024     416080

I have 504812 + 106024 - 175616 - 30712 == 404508 kB used by applications.  I 
assume the numbers are kilobytes, and not pages.  However, on the -/+ line 
there is a buffers/cache of 298484 and 215348.


When I run 'top' (as in 'top b -n 1'), I see the following memory columns:
SIZE RSS SHARE %MEM.  I'll ignore '%MEM' for now.  If I add up all the numbers 
in SIZE, I get: SIZE=114996, RSS=165656, and SHARE=39884.  Nowhere close to 
404508, so this does not explain why the kernel swaps.


When I run 'ps aux' I get an additional column VSZ.  (vsize???).  If I add 
those numbers, I get VSZ=950444.  Much too large :(.  The biggest difference 
is Java, which has a VSZ of 577904, but a SIZE of 100M, RSS of 88M and SHARE 
of 3860.


If I use 'SIZE' (from top), and I subtract the buffers from the -/+ line, I 
get 136736, which is close to SIZE=114996 and RSS=165656.  I'm not expecting 
to get exact numbers because of copy-on-write, and a (small) time delay 
between typing free, top, and ps, but I'd like to get close.


So here are the questions:
 1. What is the difference between buffers and cache in the 'Mem:' line and
    the '+/- buffers/cache' line in the output of free.
 2. What is the difference between SIZE, RSS, SHARE, and VSZ?
 3. If the buffers are really 298484 instead of 30712, and the machine is
    swapping lots, isn't it better to shrink the buffers and cache, and
    get the app in RAM instead of swap?

-- 
Berend De Schouwer
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org"> aart@kvack.org </a>

                 reply	other threads:[~2004-01-12 12:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200401121335.03027.bds@jhb.ucs.co.za \
    --to=bds@jhb.ucs.co.za \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox