LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-18-2006, 02:47 PM   #1
scorbett
Member
 
Registered: May 2002
Location: Canada
Distribution: Slackware, Mandriva, RedHat
Posts: 46

Rep: Reputation: 15
Identifying memory usage


I have a linux (slackware) system with 1 gig of physical memory and 2 gigs of swap space. The system hasn't been rebooted in over a month, and it's been pretty stable. However, last few days, I've noticed that there's less and less free physical memory available - I think there's a memory leak in some piece of software I'm running, but I don't know how to find out which application is eating up all my memory.

If I do a top, I see several instances of mysqld and httpd, but the mysqld instances are (according to top) using only 1.8% of memory or less each, and the httpd instances are using only 0.8% or less each. This doesn't add up to the 80% or so memory usage I'm seeing. There are various other services running, but according to top they're only using between 0.1% and 0.4% of memory each.

Output from `cat /proc/meminfo`

Code:
        total:    used:    free:  shared: buffers:  cached:
Mem:  926203904 881004544 45199360        0 74682368 641765376
Swap: 2147467264        0 2147467264
MemTotal:       904496 kB
MemFree:         44140 kB
MemShared:           0 kB
Buffers:         72932 kB
Cached:         626724 kB
SwapCached:          0 kB
Active:         206072 kB
Inactive:       493644 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:       904496 kB
LowFree:         44140 kB
SwapTotal:     2097136 kB
SwapFree:      2097136 kB
Last time I checked (a few days ago), my free physical memory was twice what it is now. There's something eating up my memory, but I don't know what.

The following software is used on this box:
  • Apache 1.3.34
  • PHP 4.4.2
  • MySQL 5.0.18
  • Courier IMAP 4.0.6
  • Postfix 2.2.8

I also have a bunch of PHP scripts that I wrote myself that hit the db (MySQL) quite often, and I'm wondering if that could be responsible for my memory trouble. What I really need is a way to diagnose what's going on - is there a better way (other than top and meminfo) to find out which applications are using memory?

I'm worried that if this keeps up, eventually it's going to start hitting the swap (currently I'm not using any of the 2 gigs of swap space available), which will slow things down significantly.
 
Old 05-18-2006, 03:05 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
This has to do with the fact that Linux automatically preallocates memory to buffers and cache so that processes can grab the memory more quickly. To see what is REALLY in use use the "free" command.

You should see something like:
total used free shared buffers cached
Mem: 8248768 7648536 600232 0 321644 6381176
-/+ buffers/cache: 945716 7303052
Swap: 5245096 216 5244880

The first line shows you essentially what you were seeing (except its in kb rather than bytes). The second line shows you what you're really using up for processes as it adds or subtracts the cache and buffers back. So long as the "free" column on the second line is fairly high you should be fine.
 
Old 05-18-2006, 03:46 PM   #3
scorbett
Member
 
Registered: May 2002
Location: Canada
Distribution: Slackware, Mandriva, RedHat
Posts: 46

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jlightner
The first line shows you essentially what you were seeing (except its in kb rather than bytes). The second line shows you what you're really using up for processes as it adds or subtracts the cache and buffers back. So long as the "free" column on the second line is fairly high you should be fine.

My output shows this:

Code:
             total       used       free     shared    buffers     cached
Mem:        904496     862544      41952          0      72940     627036
-/+ buffers/cache:     162568     741928
Swap:      2097136          0    2097136
So when it says "used" memory, it's actually referring to memory that has been reserved by the OS and is not actually in use by any application? Just trying to understand. If that's the case, great, no problem here. That would also explain why the top command isn't showing any memory-hogging applications - I guess there just aren't any.

Thanks for the insight.
 
Old 05-22-2006, 01:58 PM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Right. In your output it shows 862544 "Used" on first line but that includes the preallocation for cache and buffers. The "Used" you should be concered with the is the 162568 on the second line as that leaves out the cache and buffers. Based on what you displayed it appears you have no memory issue.

Of course you can do the calculation from the /proc/meminfo manually but since "free" does it for you its better to use.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Memory Usage Spaw Usage Swappiness Issues joelunch Linux - Software 3 01-04-2006 06:16 PM
getting realtime info on memory usage-cpu and harddrive usage steering Linux - Newbie 5 03-03-2005 08:43 PM
how to determine cpu usage, memory usage, I/O usage by a particular user logged on li rags2k Programming 4 08-21-2004 04:45 AM
Controlling CPU usage & memory usage Saravana babu Linux - Software 0 02-18-2004 05:55 AM
Memory Usage and RH 9 farside268 Linux - General 7 08-24-2003 08:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration