• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2499
  • Last Modified:

Script for AIX processes working set size

I am trying to write a korn shell script for AIX to determine the working set size of all running processes on a system.
IBM provided a bit of perl code to minimize the output of  svmon  to just the summary line. From that, I can read
inuse memory, pinned memory, paging space and virtual memory values.
Here is what I have so far:
--------------------------------------
#!/bin/ksh
# Working set size
# svmon -P

let cnt=0

svmon -P | perl -e 'while(<>){print if($.==2||$&&&!$s++);$.=0 if(/^-+$/)}' | \
while read -r pid cmd inuse pin pgsp virt flags ; do

# Note, the above two lines are actually one script line
# It is broken out for readability

let cnt=cnt+1
if [ cnt -lt 3 ] # read only from 3rd line forward (ignore heading lines)
then
 continue
else

 let wspg=$inuse+$pgsp+$virt
 let ws=$wspg*4
# Convert from 4K pages to KBytes
 echo "PID $pid Working Set Size $ws KB"

fi
done
--------------------------------------

Am I on the right track here?  Are the values obtained this way (in use memory +  paging space + virtual memory) going to give me a close approximation to the point-in-time working set size of a process?
Thank you.

0
jonkreisler
Asked:
jonkreisler
  • 4
  • 3
1 Solution
 
cpc2004Commented:
Unless you want to have a detail storage break down, otherwise pg vg has what you want
$ ps vg | pg
   PID    TTY STAT  TIME PGIN  SIZE   RSS   LIM  TSIZ   TRS %CPU %MEM COMMAND
31740      - A    15:13 737873  3860  1956 32768    34    16  8.2  0.0 db2agent
Where
RSS  - Real Memory Resident Size in 1KB =  1956K
SIZE - Size of Page space in 1KB = 3860K


0
 
jonkreislerAuthor Commented:
On my system, (AIX 5.2) "svmon -P" and "ps vg"  numbers do not match. In some cases, not even close.

0
 
cpc2004Commented:
Attach your output of svmon and "ps vg | pg" here
0
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.

 
jonkreislerAuthor Commented:
Here is a sample:

svmon -P

     Pid Command          Inuse      Pin     Pgsp  Virtual 64-bit Mthrd LPage
   20656 ksh               9378     2451      824     9320      N     N     N
   29710 ksh               9375     2451      824     9318      N     N     N
   30210 telnetd           9365     2451      824     9344      N     N     N
   30600 sleep             9220     2451      824     9219      N     N     N
   34696 bsh               9399     2451      824     9378      N     N     N
   44418 ksh               9367     2451      824     9310      N     N     N
   46134 ksh               9367     2451      824     9310      N     N     N
   47380 ksh               9365     2451      824     9308      N     N     N
   90906 ping              9278     2451      824     9269      N     N     N
  100374 ksh               9376     2451      824     9319      N     N     N
  104490 sleep             9220     2451      824     9219      N     N     N
  110046 grep              9234     2451      824     9229      N     N     N
  111598 wc                9221     2451      824     9219      N     N     N
  117334 sadc              9238     2451      824     9222      N     N     N
  117786 topas            10598     2451      824    10586      N     N     N
  120870 ksh               9373     2451      824     9315      N     N     N
-------------------------------------------------------------------------------
ps vg

    PID    TTY STAT  TIME PGIN  SIZE   RSS   LIM  TSIZ   TRS %CPU %MEM COMMAND
  20656  pts/5 A     0:00    0   588   804 32768   188   216  0.0  0.0 -ksh
  29710  pts/3 A     0:00    0   580   796 32768   188   216  0.0  0.0 -ksh
  30210      - A     0:00    0   680   760 32768    56    80  0.0  0.0 telnetd
  30600      - A     0:00    0   184   188 32768     2     4  0.0  0.0 sleep 60
  34696      - A     0:00    0   820   900 32768   523   360  0.0  0.0 bsh /usr
  44418      - A     0:00    0   548   764 32768   188   216  0.0  0.0 ksh /hom
  46134      - A     0:00    0   548   764 32768   188   216  0.0  0.0 ksh /pro
  47380  pts/5 A     0:00    0   540   756 32768   188   216  0.0  0.0 ksh ./ws
  90906      - A     0:00    0   384   416 32768    22    32  0.0  0.0 ping -c
 100374  pts/5 A     0:00    0   584   800 32768   188   216  0.0  0.0 -ksh
 104490      - A     0:00    0   184   188 32768     2     4  0.0  0.0 sleep 60
 105962      - A     0:00    0   368   376 32768     4     8  0.0  0.0 /usr/sbi
 110046      - A     0:00    0   224   244 32768    15    20  0.0  0.0 grep 100
 111598      - A     0:00    0   184   192 32768     4     8  0.0  0.0 wc -l
 117334      - A     0:00    0   196   212 32768     9    16  0.0  0.0 /usr/lib
 117786  pts/3 A     5:27    0   896   944 32768    32    48  0.2  0.0 topas
 120870      - A     0:00    0   568   784 32768   188   216  0.0  0.0 ksh /pro
0
 
cpc2004Commented:
The value of virtual of SVMON of a process including the shared library and it is in terms of paging slot (ie 4K). The size of virtual shared library and kernel segment is common to all the processes. Hence it is more meaningful to use the value of size from PS VG as it only contain the private data.

The value of Size of PS VG is in terms of 1K
The formula
Size of PS VG =  SVMON virtual (work process private + work shared library data  Shmat/mmap) *4


Sample output of svmon -Pu
     Pid Command        Inuse      Pin     Pgsp  Virtual   64-bit    Mthrd
   27954 r4edi           7579     1485     7177     9004        N        N

  Vsid     Esid Type Description           Inuse   Pin Pgsp Virtual Addr Range
 38b7c        2 work process private        3069     1 5605  6469   0..6496 :
                                                                    65309..65535
 30018        d work shared library text    2304     0  151   160   0..65535
     0        0 work kernel seg             1810  1484 1372  2326   0..21860 :
                                                                    65474..65535
 26653        - pers /dev/amtrix:55355       210     0    -     -   0..259
 1a74d        1 pers code,/dev/amtrix:230    117     0    -     -   0..151
 36b7b        f work shared library data      40     0   49    49   0..897
 1e7af        - pers /dev/amtrix:4898         16     0    -     -   0..18
 3c7de        - pers /dev/amtrix:4543         13     0    -     -   0..18
 1a80d        - pers /dev/amtrix:12635         0     0    -     -
 32779        - pers /dev/amtrix:10283         0     0    -     -   0..0
   800        - pers /dev/amtrix:426149        0     0    -     -  

$ ps vg | pg
           PID  TTY STAT  TIME  PGIN  SIZE   RSS   LIM  TSIZ   TRS %CPU %MEM COMMAND
         27954    - A     1:34  6096 26072 13716 65536   546   468  0.0  1.0 r4edi
0
 
jonkreislerAuthor Commented:
cpc2004 - thank you for that explanation.
To clarify, though, are you saying all I need are the values "SIZE" and "RSS" from "ps vg" to determine a process' working set size?
Thanks,
Jon
0
 
cpc2004Commented:
Yes. I've extracted the explanation of SIZE and RSS from "AIX 5L Performance and System Tuning"

Use of the ps command in a memory usage study
The ps command can also provide useful information on memory usage.

The SIZE column
The v flag generates the SIZE column. This is the virtual size (in the paging
space), in kilobytes, of the data section of the process (displayed as SZ by other
flags). This value is equal to the number of working segment pages of the
process that have been touched times four. If several working segment pages
are currently paged out, this number is larger than the amount of real memory
being used. SIZE includes pages in the private segment and the shared-library
data segment of the process, as in the following example:
# ps av |sort +5 -r |head -n 5
PID TTY STAT TIME PGIN SIZE RSS LIM TSIZ TRS %CPU %MEM COMMAND
25298 pts/10 A 0:00 0 2924 12 32768 159 0 0.0 0.0 smitty
13160 lft0 A 0:00 17 368 72 32768 40 60 0.0 0.0/usr/sbin
27028 pts/11 A 0:00 90 292 416 32768 198 232 0.0 1.0 ksh
24618 pts/17 A 0:04 318 292 408 32768 198 232 0.0 1.0 ksh

The RSS column
The v flag also produces the RSS column, as shown in the previous example.
This is the real-memory (resident set) size in kilobytes of the process. This
number is equal to the sum of the number of working segment and code segment
pages in memory times four. Remember that code segment pages are shared
among all of the currently running instances of the program. If 26 ksh processes
are running, only one copy of any given page of the ksh executable program
would be in memory, but the ps command would report that code segment size
as part of the RSS of each instance of the ksh program
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now