?
Solved

Process memory information

Posted on 2003-02-27
6
Medium Priority
?
15,828 Views
Last Modified: 2007-12-19
There's so many information about memory of a process... I just don't know which one to use... which one do this and which one do that!!
Somebody help me!! I just spend to much time on this!

I'm using LINUX

What I know...
1- /proc/<pid>/status
Give me:
VmSize
VmLck
VmRss
VmData
VmStk
VmExe
VmLib

2- /proc/<pid>/statm
Give me:
SmSize
SmRss
SmShared
SmTrs
SmDrs
SmLrs
SmDt

3- ps -ao pid,fname,m_drs,m_trs,maj_flt,min_flt,rss,vsize
Give me:
PID
COMMAND
DRS
TRS
MAJFL
MINFL
RSS
VSZ

SO... when I test my program, at first I get:
VmSize = 1548
VmLck  = 0
VmRss  = 580
VmData = 32
VmStk  = 60
VmExe  = 56
VmLib  = 1308

SmSize   = 145
SmRss    = 145
SmShared = 116
SmTrs    = 9
SmDrs    = 0
SmLrs    = 136
SmDt     = 29

PID    = 3184
COMMAND= testing
DRS    = 1494
TRS    = 53
MAJFL  = 167
MINFL  = 17
RSS    = 580
VSZ    = 1548


And at the end I get:
VmSize = 782992
VmLck  = 0
VmRss  = 10172
VmData = 781476
VmStk  = 60
VmExe  = 56
VmLib  = 1308

SmSize   = 10084
SmRss    = 2543
SmShared = 72
SmTrs    = 9
SmDrs    = 0
SmLrs    = 2534
SmDt     = 2491

PID    = 3184
COMMAND= testing
DRS    = 782938
TRS    = 53
MAJFL  = 1443
MINFL  = 10132
RSS    = 10172
VSZ    = 782992

Yes I know my program is eating memory without releasing it. That's what I want for my test!

Because I need a way to test my C++ objects and to know when the memory is not releasing!

What I found is VSZ or VmSize is the total memory size allocated to my program.

BUT:
1- what is VmRss,RSS,(SmRss in page). Is it only the RAM used? I'm looking for the total of memory USED by the program... Example: The program start with 1500K but only use 600K. RSS seems to be what I'm looking for. If I allocate 100 more K, RSS move to 700. Good! But In my 'testing' example you can see that I allocate over 780000K and RSS only raise to 10172K

How can I get the quantity of memory used by the program? When I release the 780000K I'm expecting the use of memory to return to 600K (But not VSZ or VmSize because it's the total of memory allocated to the program... used or not used!)    


2- What mean those other factors like:
   *VmData: Why VmSize raise at the same time???

   *SmSize: Documents says it's the total program size but when I look at my example... It mean nothing???

   *SmShared,SmTrs,SmDrs,SmLrs,SmDt: Look like SmRSS=SmShared+SmDt=SmTrs+SmLrs but I need more information to understand when those factors is used!

   *TRS,MAJFL,MINFL: What's that?  

PLEASE CAN YOU GIVE ME AN EXAMPLE?

0
Comment
Question by:slabrie2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 38

Expert Comment

by:yuzh
ID: 8038608
You just want the process size right?

Just simeply type in:

ps -uax

the output %MEM is the process size ! eg if your want to find out process 123(pid). you can do:

ps -uax | grep 123

to find out
0
 

Author Comment

by:slabrie2
ID: 8038844
Well no... It's a little more than that!

I'm expecting an answer from someone who worked with all those factors I mentioned before. My biggest need is to find the way to get the quantity of memory USED by the program... not just VmSize (or VSZ).
 
%MEM seems to be the % of RAM memory used. I can't use this factor to know the memory 'size' used by the process. That doesn't help me much with the example of my process 'testing' who eat more than 700000k. But thanks anyway!
0
 
LVL 38

Expert Comment

by:yuzh
ID: 8039014
You can try:

pmap -l pid

The use the total figure as the totol memory for the process
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Accepted Solution

by:
bryanh earned 300 total points
ID: 8045319
One problem with your question is that you assume there is one universal definition of "used".  There are a dozen different levels at which a particular byte of memory can be considered in use or not.

From context, I assume what you want is to know the total amount of memory that has been allocated by a program with malloc() and not yet freed.  The Linux kernel can't tell you that, because it doesn't know about malloc.  Malloc is a C library (user space) entity.  There are a number of tools that interact in various ways with your program's malloc calls to debug memory leaks.  They can tell you the total amount of malloc-allocated memory at any given time as well as which individual allocations are outstanding.

Malloc allocates from storage that it acquires in large chunks from the kernel.  And it never gives it back.  When the program frees malloc'ed storage, the C library just keeps the memory for future mallocs.  (There's an exception for really large (>128M) individual mallocs).

Another problem with your search is that you seem to be overlooking the distinction between real memory and virtual memory.

VSIZE is the total amount of virtual memory allocated to the process by the kernel.  It includes the space the program text lives in, the program's stack, shared libraries it accesses, and even maps of devices and files if the program has them.  And the ever-growing malloc heap.

DSIZE is VSIZE less the space that contains program code
(which is TSIZE).

RSS is the total amount of real memory allocated to the process.  This goes up as you touch virtual memory pages and goes down when you don't touch virtual pages for a while and the kernel finds other uses for the real memory.

Real memory size is typically a lot less than virtual memory size.

%MEM tells what fraction of the total system real memory RSS is.

MINFL and MAJFL are counts of the number of page faults the process has experienced, minor and major.  A page fault is when you access a virtual memory page that is not backed by a real page frame.  A minor one is one that is easily satisfied by taking a free page frame.  A major one requires the kernel to kick some other page out of a page frame to free it up.
0
 

Author Comment

by:slabrie2
ID: 8049536
Thank you bryanh,

So there's no way to know the ever-growing malloc heap except if I trap all calls ('new' & 'malloc') in my program?
And there's no way to know the free memory left for those calls in VSIZE?

Is it normal having MINFL and MAJFL when running program? It's page faults... I gess that mean I've got bad code in my program?

Thanks!
0
 
LVL 5

Expert Comment

by:bryanh
ID: 8049711
>So there's no way to know the ever-growing malloc heap except
>if I trap all calls ('new' & 'malloc') in my program?
>And there's no way to know the free memory left for those
>calls in VSIZE?

Right.  But note that there are several tools that help you to trap all those things.   They work in various ways -- sometimes it's a library that you link in front of the C library that has its own malloc() and free().  new(), by the way, uses malloc() to get memory.  You don't have to trap it separately.

I don't know any of these tools off the top of my head.  One popular one is called Electric Fence.

>Is it normal having MINFL and MAJFL when running program?
>It's page faults...

Yes. page faults are normal.  It is normal for a virtual page not to be backed by real memory.  If no one is accessing the page, there's no reason for the system to waste memory on it.  When you access a page for the first time, or the first time in a while, it causes a page fault.  The system handles the page fault by getting some real memory, filling it with whatever's supposed to be in that page, and then repeating the access.

So you will see at least one page fault for every page you use.  Malloc 100 pages and then fill the space with data and you will see the page fault counts go up by 100.  (You'll probably also see the RSS go up by 100).
0

Featured Post

How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question