Pages

Wednesday, February 10, 2016

Linux Memory - By Example

========================================
General
========================================


Customer complain that the server is slow.
How to check if the memory on the server is sufficient?

========================================
Commands to run
========================================
free -m
top
sar
ps - sorted by memory size.
/proc/$PID/map - Each process memory consumption
Optionally collect this data in a script over time

========================================
Analyze data
========================================
=====================
free -m
=====================
Thu Jan 28 12:56:15 ICT 2016

             total       used       free     shared    buffers     cached

Mem:         40200      40010        172          0        502      24503

-/+ buffers/cache:      15004      25178

Swap:        10240       2502       7738

Linux does pre-allocation/caching of the host RAM memory, so when a process needs a chunk of a memory, the allocation to the process would be faster.
So, it appears that 99.5% of the server RAM memory is used.
But on Linux that would be normal situation.

The actual memory usage, is displayed in the -/+ buffers/cache used and free values.
RAM Memory Allocated: 40010/40200*100=99.5% 
Meaning 99.5% of RAM memory is "used" - actually it is allocated/cached.

Out of total 40010 "used", 502Mb are allocated for file system metadata, and 24503 for I/O buffer.

RAM Memory Usage: 15004/40200*100 =37% of RAM memory is used.

SWAP usage: 2502/10240*100 = 25% of SWAP memory is used.


=====================
top
=====================

By default top would sort the output by CPU usage.
To change this behavior:

top -> Shift+f -> get sort options list -> chose memory (n)

top - 12:29:15 up 153 days, 12:34,  7 users,  load average: 11.03, 11.88, 11.50
Tasks: 2206 total,   1 running, 2202 sleeping,   0 stopped,   3 zombie
Cpu(s): 12.2%us,  5.9%sy,  0.0%ni, 69.1%id, 12.2%wa,  0.1%hi,  0.4%si,  0.0%st
Mem:  65968640k total, 65669104k used,   299536k free,    33612k buffers
Swap: 10485752k total,  8537300k used,  1948452k free, 11815512k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND               
 1957 iu        15   0 29.4g  23g  13m S  0.0 37.7  26:40.09 notification
11410 oracle    15   0 8449m 4.6g 4.6g S  0.0  7.4  70:39.95 oracle                 11390 oracle    15   0 8442m 4.6g 4.6g S  0.0  7.2  13:07.52 oracle 
11394 oracle    16   0 8456m 4.3g 4.3g D  0.6  6.8   7796:57 oracle                 

CPU
Cpu(s):  5.4%us,  1.4%sy,  0.0%ni, 92.8%id,  0.2%wa,  0.0%hi,  0.1%si,  0.0%st
92.8%id - 92% of the time it is in idle state.

Memory
Mem:  41146860k total, 40936740k used,   210120k free,   603392k buffers

Swap: 10485752k total,  2561952k used,  7923800k free, 24739192k cached



or in Mb, to be in sync with free -m output



Mem:  40182Mb total, 40000Mb used,   205Mb free,   590Mb buffers
Swap: 10240Mb total,  2502Mb used,  7738Mb free, 24160Mb cached





RAM Memory Allocated: 40000/40182*100 99.5% of RAM memory is "used" - In Linux that is normal.
SWAP usage: 2502/10240*100 = 25% of SWAP memory is used.


The output of the memory in top is not informative.

Because by default Linux would allocate most of host RAM memory, and distribute to applications as needed.



Processes using most memory:

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
 6069 iu        15   0  504m  64m  21m S  7.5  0.2   3533:35 mpi                
 6281 iu        15   0  504m  64m  21m S  5.6  0.2   3450:47 mpi                
  874 iu        15   0  410m 130m  14m S  3.7  0.3   6:05.08 notification       
  531 iu        15   0  623m 372m  14m S  1.9  0.9  23:38.78 notification       
12565 oracle    18   0 8447m  32m  28m S  1.9  0.1 107:55.56 oracle             
20396 oracle    15   0 8447m 301m 298m S  1.9  0.8   3:49.01 oracle             
25046 oracle    15   0 8448m 3.8g 3.8g S  1.9  9.7   8:19.16 oracle    

PR - Priority.
The lower this value, the higher the priority.
The highest priority is -20 and the lowest is 20.


NI - Nice.

RES stands for the Resident Size, which is an accurate representation of how much actual physical memory,RAM memory, a process is consuming. This also corresponds to the %MEM column.


VIRT stands for the Virtual Size of a process, which is the sum of memory it is actually using, shared libraries, and memory shared with other processes. VIRT represents how much memory the program is able to access at the present moment.


SHR indicates how much of the VIRT size is actually Sharable (memory or libraries). In the case of libraries, it does not necessarily mean that the entire library is resident. For example, if a program only uses a few functions in a library, the whole library is mapped and will be counted in VIRT and SHR, but only the parts of the library file containing the functions being used will actually be loaded in and be counted under RES.

S is the Process Status : 
The status of the task which can be one of:
'D' = Uninterruptible sleep
'R' = Running
'S' = Sleeping
'T' = Traced or stopped
'Z' = Zombie

%MEM
Based upon Memory Usage (RES) value.
A task's currently used share of available physical memory (RAM).

TIME+
Total CPU time the task has used since it started.


=====================
sar
=====================
Total CPU time the task has used since it started.
sar -S => Get SWAP usage
sar -r => Get Memory free and used 

=====================
ps
=====================
ps -eo pid,ppid,rss,size,vsize,pcpu,pmem,cmd -ww --sort=vsize

Sample output:
  PID  PPID     RSS   SZ    VSZ %CPU %MEM CMD
28756     1 3442212 3008 8659216 0.0  8.3 oracleigt (LOCAL=NO)
27088     1 4048484 3016 8659224 0.0  9.8 oracleigt (LOCAL=NO)
14187     1 4334060 3024 8659232 0.0 10.5 oracleigt (LOCAL=NO)
28230     1 827388  2968 8666344 0.0  2.0 oracleigt (LOCAL=NO)
28200     1 739872  2972 8666348 0.0  1.7 oracleigt (LOCAL=NO)
28222     1 824800  2972 8666348 0.0  2.0 oracleigt (LOCAL=NO)
11412     1 2554320 2996 8666372 1.0  6.2 oracleigt (LOCAL=NO)
11404     1 2463452 3000 8666376 1.2  5.9 oracleigt (LOCAL=NO)
13056     1 204308  2980 8678196 0.0  0.4 oracleigt (LOCAL=NO)
11421     1 2653716 3000 8687944 1.1  6.4 oracleigt (LOCAL=NO)



ps -eo pmem,pcpu,pid,rss,vsize,args | sort -k 1 -n -r | head -20 


pmem pcpu  pid  rss     vsize   args
8.1  1.4   3242 2665160 6230672 /software/java/x64/jdk1.8.0_77/bin/java -Dcom.sun.management.jmxremote.port=1108 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -XX:NewSize=200m -XX:SurvivorRatio=6 -XX:MaxTenuringThreshold=4 -XX:CMSInitiatingOccupancyFraction=60 -XX:+UseCMSInitiatingOccupancyOnly -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -DserviceName=sparx -DclusterStartDelay=120000 -Djava.net.preferIPv4Stack=true -DisCluster=true -Xms4096m -Xmx4096m -Djava.library.path=/starhome/igate/pru-ent-sx2/bin -classpath /starhome/igate/pru-ent-sx2/lib/wrapper-3.5.17.jar:/starhome/igate/pru-ent-sx2/lib/log4j-1.2.17.jar:/starhome/igate/pru-ent-sx2/lib/ojdbc8-12.2.0.1.jar:/starhome/igate/pru-ent-sx2/lib/javolution-1.0.99.jar:/starhome/igate/pru-ent-sx2/lib/commons-pool-1.6.jar:/starhome/igate/pru-ent-sx2/lib/ig2-common.jar:/starhome/igate/pru-ent-sx2/lib/sparx.jar:/starhome/igate/pru-ent-sx2/lib/jaxb-api-
6.4  0.0   124235 2123600 4496808 ora_dbw0_igt
5.9  0.1   123633 1955316 4446704 oracleigt (LOCAL=NO)
5.7  0.0   125467 1898732 4446708 oracleigt (LOCAL=NO)
5.7  0.0   126547 1872568 4446672 oracleigt (LOCAL=NO)
5.1  0.0   125675 1692532 4446636 oracleigt (LOCAL=NO)
4.3  0.0   123456 1413616 4445596 oracleigt (LOCAL=NO)

4.2  0.0   124580 1385260 4446656 oracleigt (LOCAL=NO)



pmem - 
Percent memory of the process out of host resources.
pcpu - Percent CPU of the process out of host resources.

The size for RSS, SZ, VSZ is in Kb

* To see the command line parameters, use: xargs -0 < /proc/<pid>/cmdline

This command, is displaying selected fields, and sorts the output by vsize.
Similar to top, ps also displays three memory types:

RSS - Resident Set Size.
RSS Is a memory currently used by a process. 
How much RAM the process is actually using.
It include stack and heap process memory.

VSIZE - Virtual Set Size
VSZ is how much memory a process can access for its execution.
It include memory that is from shared libraries.

SIZE - Virtual Size of the data section of the process. 
            The data segment contains any global or static variables.


top vs ps
in top => in ps
res    => rss
virt   => vsize 


batch mode
top -b - The default. Output is sorted by CPU.
top -ba - The output is sorted by %MEM.


=====================
/proc/$PID/map and pmap
=====================
To see each process memory consumption, check out /proc/$PID/map file.

RSS is how much memory this process currently has in main memory (RAM). 
VSZ is how much virtual memory the process has in total. 
This includes all types of memory, both in RAM and swapped out. 
These numbers can get skewed because they also include shared libraries and other types of memory. 
To have a  more detailed idea about the memory footprint of a process, need to look at  /proc/$PID/maps.
If lists shared libraries and additional memory usage per process.
To see the data listed in  /proc/$PID/maps in a more human form, use pmap $PID command.
ps -ef | grep ora

oracle   24812     1  0  2015 ?        00:01:23 ora_pmon_igt
oracle   24814     1  0  2015 ?        00:00:00 ora_mman_igt
oracle   24816     1  0  2015 ?        07:08:47 ora_dbw0_igt
oracle   24818     1  0  2015 ?        03:51:26 ora_lgwr_igt
oracle   24820     1  0  2015 ?        01:42:20 ora_ckpt_igt
oracle   24822     1  0  2015 ?        00:21:07 ora_smon_igt
oracle   24824     1  0  2015 ?        00:00:09 ora_reco_igt
oracle   24826     1  0  2015 ?        00:12:52 ora_cjq0_igt
oracle   25112     1  0  2015 ?        00:00:44 ora_arc0_igt
oracle   25114     1  0  2015 ?        04:33:05 ora_arc1_igt
oracle   25121     1  0  2015 ?        00:00:01 ora_qmnc_igt
oracle   25123     1  0  2015 ?        00:09:23 ora_mmon_igt
oracle   25125     1  0  2015 ?        00:01:48 ora_mmnl_igt
oracle   25401     1  0  2015 ?        00:00:00 ora_q000_igt
oracle   18812     1  0 Apr16 ?        00:00:00 ora_q001_igt
oracle   18680    1  0 06:38 ?        00:00:00 oracleigt (LOCAL=NO)
oracle   18710     1  0 06:38 ?        00:00:00 oracleigt (LOCAL=NO)
oracle   19557     1  0 06:39 ?        00:00:00 oracleigt (LOCAL=NO)
oracle   22466     1  0 06:44 ?        00:00:00 oracleigt (LOCAL=NO)
oracle   27122     1  0 06:52 ?        00:00:00 oracleigt (LOCAL=NO)
oracle   29435     1  0 06:56 ?        00:00:00 oracleigt (LOCAL=NO)
oracle   28329     1  0 13:28 ?        00:00:01 oracleigt (LOCAL=NO)
oracle   28334     1  0 13:28 ?        00:00:01 oracleigt (LOCAL=NO)
oracle   28336     1  0 13:28 ?        00:00:00 oracleigt (LOCAL=NO)
oracle    2773     1  4 13:40 ?        00:02:48 oracleigt (LOCAL=NO)
oracle   31244     1  0 14:29 ?        00:00:00 oracleigt (LOCAL=NO)

less /proc/18680/maps

0089a000-008af000 r-xp 00000000 fd:01 213125     /lib/ld-2.3.4.so
008af000-008b0000 r-xp 00015000 fd:01 213125     /lib/ld-2.3.4.so
008b0000-008b1000 rwxp 00016000 fd:01 213125     /lib/ld-2.3.4.so
008b3000-009d7000 r-xp 00000000 fd:01 213127     /lib/tls/libc-2.3.4.so
009d7000-009d8000 r-xp 00124000 fd:01 213127     /lib/tls/libc-2.3.4.so
009d8000-009db000 rwxp 00125000 fd:01 213127     /lib/tls/libc-2.3.4.so
009db000-009dd000 rwxp 009db000 00:00 0
009df000-009e1000 r-xp 00000000 fd:01 213139     /lib/libdl-2.3.4.so
009e1000-009e3000 rwxp 00001000 fd:01 213139     /lib/libdl-2.3.4.so
009e5000-00a06000 r-xp 00000000 fd:01 213136     /lib/tls/libm-2.3.4.so
00a06000-00a08000 rwxp 00020000 fd:01 213136     /lib/tls/libm-2.3.4.so
00afb000-00b09000 r-xp 00000000 fd:01 213128     /lib/tls/libpthread-2.3.4.so
00b09000-00b0b000 rwxp 0000d000 fd:01 213128     /lib/tls/libpthread-2.3.4.so
00b0b000-00b0d000 rwxp 00b0b000 00:00 0
00bdd000-00bef000 r-xp 00000000 fd:01 213159     /lib/libnsl-2.3.4.so
00bef000-00bf1000 rwxp 00011000 fd:01 213159     /lib/libnsl-2.3.4.so
00bf1000-00bf3000 rwxp 00bf1000 00:00 0
08048000-0bfeb000 r-xp 00000000 fd:08 300759     /software/oracle/101/bin/oracle
0bfeb000-0c191000 rwxp 03fa2000 fd:08 300759     /software/oracle/101/bin/oracle
0c191000-0c20e000 rwxp 0c191000 00:00 0
50000000-a2200000 rwxs 00000000 00:06 8192002    /SYSV16e137cc (deleted)
b73d7000-b73e7000 rwxp 00000000 00:0d 2047       /dev/zero
b73e7000-b73f7000 rwxp 00000000 00:0d 2047       /dev/zero
b73f7000-b7407000 rwxp 00000000 00:0d 2047       /dev/zero
b7407000-b7417000 rwxp 00000000 00:0d 2047       /dev/zero
b7417000-b7427000 rwxp 00000000 00:0d 2047       /dev/zero
b7427000-b7437000 rwxp 00000000 00:0d 2047       /dev/zero
b7437000-b7447000 rwxp 00000000 00:0d 2047       /dev/zero
b7447000-b7457000 rwxp 00000000 00:0d 2047       /dev/zero
b7457000-b74d7000 rwxp 0012f000 00:0d 2047       /dev/zero
b74d7000-b74f7000 rwxp 00000000 00:0d 2047       /dev/zero
b74f7000-b7507000 rwxp 00000000 00:0d 2047       /dev/zero
b7507000-b7517000 rwxp 00000000 00:0d 2047       /dev/zero
b7517000-b7527000 rwxp 00000000 00:0d 2047       /dev/zero
b7527000-b7537000 rwxp 00000000 00:0d 2047       /dev/zero
b7537000-b7547000 rwxp 00000000 00:0d 2047       /dev/zero
b7547000-b7557000 rwxp 00000000 00:0d 2047       /dev/zero
b7557000-b7560000 r-xp 00000000 fd:01 213042     /lib/libnss_files-2.3.4.so
b7560000-b7562000 rwxp 00008000 fd:01 213042     /lib/libnss_files-2.3.4.so
b756f000-b75c0000 rwxp 00000000 00:0d 2047       /dev/zero
b75c0000-b75d0000 rwxp 00000000 00:0d 2047       /dev/zero
b75d0000-b75e0000 rwxp 00000000 00:0d 2047       /dev/zero
b75e0000-b75ef000 rwxp 00071000 00:0d 2047       /dev/zero
b75ef000-b75f9000 rwxp b75ef000 00:00 0
b75f9000-b75fa000 --xp b75f9000 00:00 0
b75fa000-b76fe000 rwxp b75fa000 00:00 0
b76fe000-b76ff000 r-xp 00000000 fd:02 70039      /usr/lib/libaio.so.1.0.1
b76ff000-b7700000 rwxp 00000000 fd:02 70039      /usr/lib/libaio.so.1.0.1
b770d000-b7886000 r-xp 00000000 fd:08 250228     /software/oracle/101/lib/libnnz10.so
b7886000-b78a0000 rwxp 00178000 fd:08 250228     /software/oracle/101/lib/libnnz10.so
b78a0000-b78a1000 rwxp b78a0000 00:00 0
b78a1000-b78ac000 r-xp 00000000 fd:08 250414     /software/oracle/101/lib/libdbcfg10.so
b78ac000-b78ad000 rwxp 0000a000 fd:08 250414     /software/oracle/101/lib/libdbcfg10.so
b78ad000-b7e8d000 r-xp 00000000 fd:08 250588     /software/oracle/101/lib/libjox10.so
b7e8d000-b7ecf000 rwxp 005e0000 fd:08 250588     /software/oracle/101/lib/libjox10.so
b7ecf000-b7ed0000 rwxp b7ecf000 00:00 0
b7ed0000-b7ed4000 r-xp 00000000 fd:08 250415     /software/oracle/101/lib/libocrutl10.so
b7ed4000-b7ed5000 rwxp 00003000 fd:08 250415     /software/oracle/101/lib/libocrutl10.so
b7ed5000-b7ed6000 rwxp b7ed5000 00:00 0
b7ed6000-b7efb000 r-xp 00000000 fd:08 250409     /software/oracle/101/lib/libocrb10.so
b7efb000-b7efc000 rwxp 00024000 fd:08 250409     /software/oracle/101/lib/libocrb10.so
b7efc000-b7f2c000 r-xp 00000000 fd:08 250407     /software/oracle/101/lib/libocr10.so
b7f2c000-b7f2d000 rwxp 00030000 fd:08 250407     /software/oracle/101/lib/libocr10.so
b7f2d000-b7f2e000 r-xp 00000000 fd:08 250412     /software/oracle/101/lib/libskgxn2.so
b7f2e000-b7f2f000 rwxp 00001000 fd:08 250412     /software/oracle/101/lib/libskgxn2.so
b7f2f000-b7fec000 r-xp 00000000 fd:08 250419     /software/oracle/101/lib/libhasgen10.so
b7fec000-b7ff1000 rwxp 000bc000 fd:08 250419     /software/oracle/101/lib/libhasgen10.so
b7ff1000-b7ff5000 rwxp b7ff1000 00:00 0
b7ff5000-b7ff7000 r-xp 00000000 fd:08 250298     /software/oracle/101/lib/libskgxp10.so
b7ff7000-b7ff8000 rwxp 00001000 fd:08 250298     /software/oracle/101/lib/libskgxp10.so
b7ff8000-b7ff9000 r-xp 00000000 fd:08 250672     /software/oracle/101/lib/libodmd10.so
b7ff9000-b7ffa000 rwxp 00000000 fd:08 250672     /software/oracle/101/lib/libodmd10.so
b7ffa000-b7ffb000 rwxp b7ffa000 00:00 0
b7ffb000-b7fff000 r-xp 00000000 fd:08 250395     /software/oracle/101/lib/libunwind.so.3
b7fff000-b8000000 rwxp 00003000 fd:08 250395     /software/oracle/101/lib/libunwind.so.3
bffec000-c0000000 rwxp bffec000 00:00 0
ffffe000-fffff000 --xp 00000000 00:00 0

pmap 18680
18680:   oracleigt (LOCAL=NO)
0089a000     84K r-x--  /lib/ld-2.3.4.so
008af000      4K r-x--  /lib/ld-2.3.4.so
008b0000      4K rwx--  /lib/ld-2.3.4.so
008b3000   1168K r-x--  /lib/tls/libc-2.3.4.so
009d7000      4K r-x--  /lib/tls/libc-2.3.4.so
009d8000     12K rwx--  /lib/tls/libc-2.3.4.so
009db000      8K rwx--    [ anon ]
009df000      8K r-x--  /lib/libdl-2.3.4.so
009e1000      8K rwx--  /lib/libdl-2.3.4.so
009e5000    132K r-x--  /lib/tls/libm-2.3.4.so
00a06000      8K rwx--  /lib/tls/libm-2.3.4.so
00afb000     56K r-x--  /lib/tls/libpthread-2.3.4.so
00b09000      8K rwx--  /lib/tls/libpthread-2.3.4.so
00b0b000      8K rwx--    [ anon ]
00bdd000     72K r-x--  /lib/libnsl-2.3.4.so
00bef000      8K rwx--  /lib/libnsl-2.3.4.so
00bf1000      8K rwx--    [ anon ]
08048000  65164K r-x--  /software/oracle/101/bin/oracle
0bfeb000   1688K rwx--  /software/oracle/101/bin/oracle
0c191000    500K rwx--    [ anon ]
50000000 1345536K rwxs-    [ shmid=0x7d0002 ]
b73d7000     64K rwx--  /dev/zero
b73e7000     64K rwx--  /dev/zero
b73f7000     64K rwx--  /dev/zero
b7407000     64K rwx--  /dev/zero
b7417000     64K rwx--  /dev/zero
b7427000     64K rwx--  /dev/zero
b7437000     64K rwx--  /dev/zero
b7447000     64K rwx--  /dev/zero
b7457000    512K rwx--  /dev/zero
b74d7000    128K rwx--  /dev/zero
b74f7000     64K rwx--  /dev/zero
b7507000     64K rwx--  /dev/zero
b7517000     64K rwx--  /dev/zero
b7527000     64K rwx--  /dev/zero
b7537000     64K rwx--  /dev/zero
b7547000     64K rwx--  /dev/zero
b7557000     36K r-x--  /lib/libnss_files-2.3.4.so
b7560000      8K rwx--  /lib/libnss_files-2.3.4.so
b756f000    324K rwx--  /dev/zero
b75c0000     64K rwx--  /dev/zero
b75d0000     64K rwx--  /dev/zero
b75e0000     60K rwx--  /dev/zero
b75ef000     40K rwx--    [ anon ]
b75f9000      4K --x--    [ anon ]
b75fa000   1040K rwx--    [ anon ]
b76fe000      4K r-x--  /usr/lib/libaio.so.1.0.1
b76ff000      4K rwx--  /usr/lib/libaio.so.1.0.1
b770d000   1508K r-x--  /software/oracle/101/lib/libnnz10.so
b7886000    104K rwx--  /software/oracle/101/lib/libnnz10.so
b78a0000      4K rwx--    [ anon ]
b78a1000     44K r-x--  /software/oracle/101/lib/libdbcfg10.so
b78ac000      4K rwx--  /software/oracle/101/lib/libdbcfg10.so
b78ad000   6016K r-x--  /software/oracle/101/lib/libjox10.so
b7e8d000    264K rwx--  /software/oracle/101/lib/libjox10.so
b7ecf000      4K rwx--    [ anon ]
b7ed0000     16K r-x--  /software/oracle/101/lib/libocrutl10.so
b7ed4000      4K rwx--  /software/oracle/101/lib/libocrutl10.so
b7ed5000      4K rwx--    [ anon ]
b7ed6000    148K r-x--  /software/oracle/101/lib/libocrb10.so
b7efb000      4K rwx--  /software/oracle/101/lib/libocrb10.so
b7efc000    192K r-x--  /software/oracle/101/lib/libocr10.so
b7f2c000      4K rwx--  /software/oracle/101/lib/libocr10.so
b7f2d000      4K r-x--  /software/oracle/101/lib/libskgxn2.so
b7f2e000      4K rwx--  /software/oracle/101/lib/libskgxn2.so
b7f2f000    756K r-x--  /software/oracle/101/lib/libhasgen10.so
b7fec000     20K rwx--  /software/oracle/101/lib/libhasgen10.so
b7ff1000     16K rwx--    [ anon ]
b7ff5000      8K r-x--  /software/oracle/101/lib/libskgxp10.so
b7ff7000      4K rwx--  /software/oracle/101/lib/libskgxp10.so
b7ff8000      4K r-x--  /software/oracle/101/lib/libodmd10.so
b7ff9000      4K rwx--  /software/oracle/101/lib/libodmd10.so
b7ffa000      4K rwx--    [ anon ]
b7ffb000     16K r-x--  /software/oracle/101/lib/libunwind.so.3
b7fff000      4K rwx--  /software/oracle/101/lib/libunwind.so.3
bffec000     80K rwx--    [ stack ]
ffffe000      4K --x--    [ anon ]
 total  1426920K

Compare the total from pmap to data from top:
top -b | grep 18680
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
18680 oracle    16   0 1393m  45m  43m S  0.0  1.5   0:00.23 oracle

The total number reported by pmap is close to virtual memory reported by top.

============================
Sum of all processes, collected by ps
============================
ps -eo pid,ppid,rss,size,vsize,pcpu,pmem,cmd -ww --sort=vsize" 

----------- ----------- ----------- ----------- ------- ----
Processes   RSS        SZ          VSZ        %CPU %MEM
----------- ----------- ----------- ----------- ------- ----
Oracle    13585300 422944    1522421180 0.6 29.2
Java    4421972 27383820    28059964 0.9 10.5
Starhome    3841628     7190628    10834928 14.7 8   

Total    21848900 34997392    1561316072 16.2 47.7

RSS = 21848900Kb = 21,336Mb
per ps output, the actual used memory is 21.336Mb

========================================
Comparing the results
========================================
The important data is the 
Each command provide slightly different numbers:

RAM Memory Allocated.
free: 15,004Mb
top : not possible to tell
ps  :  21,336Mb

Free Memory
free: 25,178Mb
top : not possible to tell
ps  : not possible to tell

========================================
script to collect data from top, free, ps commands into a log
========================================
top -b -n 1 
-b => batch
-n 1 => execute 1 time.


#!/bin/bash

touch top_trace.log
touch free.log
touch sorted_processes.log

while [ 1 -eq 1 ] ; do
  date >> top_trace.log
  top -b -n 1 | head -30 >> top_trace.log

  date >> free.log
  free >> free.log  

  date >> sorted_processes.log

  ps -eo pid,ppid,rss,size,vsize,pcpu,pmem,cmd -ww --sort=vsize > sorted_processes.log

  sleep 10

  #------------------------------------------
  #prevent the log files from growing forever
  #------------------------------------------
  mv -f `find . -name "sorted_processes.log" -size +1000000k` sorted_processes.log_bak
  mv -f `find . -name "top_trace.log" -size +1000000k` top_trace.log_bak
  mv -f `find . -name "free.log" -size +1000000k` free.log_bak

done

========================================
Reference
========================================
Tuning and Optimizing Red Hat Enterprise Linux for Oracle 9i and 10
top command - Linux.about.com


Linux Memory Explained


No comments:

Post a Comment