Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Process memory information

Posted on 2003-02-27
Medium Priority
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:

2- /proc/<pid>/statm
Give me:

3- ps -ao pid,fname,m_drs,m_trs,maj_flt,min_flt,rss,vsize
Give me:

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.

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?  


Question by:slabrie2
  • 2
  • 2
  • 2
LVL 38

Expert Comment

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

Author Comment

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!
LVL 38

Expert Comment

ID: 8039014
You can try:

pmap -l pid

The use the total figure as the totol memory for the process
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Accepted Solution

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.

Author Comment

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?


Expert Comment

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).

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

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

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
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…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

578 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