16 March 2011

process memory usage in Linux

In linux, the amount of physical memory a single process might use 
can be roughly divided into following categories.

* M.a anonymous mapped memory
o .p private
+ .d dirty == malloc/mmapped heap and stack allocated and written memory
+ .c clean == malloc/mmapped heap and stack memory once allocated,
written, then freed, but not reclaimed yet
o .s shared
+ .d dirty == there should be none
+ .c clean == there should be none
* M.n named mapped memory
o .p private
+ .d dirty == file mmapped written memory private
+ .c clean == mapped program/library text private mapped
o .s shared
+ .d dirty == file mmapped written memory shared
+ .c clean == mapped library text shared mapped

m.a.p.d
awk '/^[0-9a-f]/{if ($6=="") {anon=1}else{anon=0}} /Private_Dirty/{if(anon) {asum+=$2}else{nasum+=$2}} END{printf "sum=%d\n",asum}' /proc/<pid>/smaps

m.a.p.c
awk '/^[0-9a-f]/{if ($6=="") {anon=1}else{anon=0}} /Private_Clean/{if(anon) {asum+=$2}else{nasum+=$2}} END{printf "sum=%d\n",asum}' /proc/<pid>/smaps


Reference:
http://stackoverflow.com/questions/131303/linux-how-to-measure-actual-memory-usage-of-an-application-or-process

No comments:

Post a Comment