AIX程式記憶體佔用數的計算

denglt發表於2013-06-20
 
今天,我們來分析下AIX下程式記憶體佔用。
 
AIX  man ps 提示"RSS   (v flag) The real-memory (resident set) size of the process (in 1KB units)."
但與linux一樣,RSS並不是程式實際佔用實體記憶體的大小。
 
下面是IBM官方的詳細解釋:
RSS:
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 4. Remember that code segment pages are shared among all of the currently running instances of the program 
TRS : Size of the resident set (real memory) of text. This is the number of code segment pages times 4. This number exaggerates memory use for programs of which multiple instances are running.
 
 
見下面命令:
[oracle@gxtest] $ps axv |head -1;ps axv | grep oracle | head -10

      PID    TTY STAT  TIME PGIN  SIZE   RSS   LIM  TSIZ   TRS %CPU %MEM COMMAND
    33118      - A     0:00    0  8436 106112    xx 88895 97676  0.0  0.0 oracle
   946452      - A     0:00    0  8436 106112    xx 88895 97676  0.0  0.0 oracle
  1360266      - A     0:00    0  8436 106112    xx 88895 97676  0.0  0.0 oracle
  1970596      - A     0:00    0  8440 106116    xx 88895 97676  0.0  0.0 oracle
  2838910      - A     0:00    0  8424 106100    xx 88895 97676  0.0  0.0 oracle
  2949614      - A     0:00    0  9372 107048    xx 88895 97676  0.0  0.0 oracle
  2970004      - A     0:16    0  9028 106704    xx 88895 97676  0.1  0.0 oracle
...
 
上面所有oracle的程式trs都為97676,是所有oracle程式共享的,所以他們的trs都一樣。
我們可以使用RSS-TRS做為程式的佔用記憶體,實際上RSS-TRS就是SIZE。
 
見SIZE的解釋:
SIZE Virtual size (in paging space) in kilobytes of the data section of the process (displayed as SZ by other flags). This number is equal to the number of working segment pages of the process that have been touched times 4. If some 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.  
看上面ps結果中的size對應的資料基本在8m左右,即oracle的server process 佔用的實體記憶體在8m左右。
 
再使用nmon看看:
[root@GXDB1:/]#nmon -r oracle
 
+-topas_nmon--S=WLMsubclasses----Host=GXDB1----------Refresh=2 secs---11:37.14---------------------
| Top-Processes-(4279) ----Mode=3  [1=Basic 2=CPU 3=Perf 4=Size 5=I/O 6=Cmds]----------------------
|  PID       %CPU     Size      Res     Res      Res     Char    RAM      Paging         Command  
|            Used       KB      Set     Text     Data     I/O     Use   io   other repage         
|44564902    94.2   201840   244616   131648   112968        0    0%      0   1832      0 oracle  
|27657376    93.4    94536   137316   131648     5668        4    0%      0      0      0 oracle  
|46924802    82.0    98412   141192   131648     9544        5    0%      0     77      0 oracle  
|16844250    74.4   105400   148180   131648    16532       28    0%      0      0      0 oracle  
|60555840    30.0    95912   138692   131648     7044      892    0%      0      0      0 oracle  
|33686028    28.3   101872   144652   131648    13004       15    0%      0      0      0 oracle  
| 4786076    22.5   105308   148088   131648    16440      399    0%      0      0      0 oracle  
| 7602648    21.3    95816   138596   131648     6948    25055    0%      0      0      0 oracle  
|17236030    20.7    99892   142672   131648    11024       67    0%      0    144      0 oracle  
|26018880    19.0    99056   141836   131648    10188       45    0%      0      0      0 oracle  
|46269150    17.5   129028   126620     3844   122776    18845    0%      0      0      0 extract 
|36110992    16.3   122768   120288     3740   116548    18806    0%      0      0      0 extract 
|46203274    15.8    96684   139464   131648     7816      335    0%      0   4050      0 oracle  
|23069706    15.4    99968   142748   131648    11100       30    0%      0      0      0 oracle
 
上面 Res Set 對應 ps 中的rss;Res Text即為trs;Res Data 即為佔用的實體記憶體。
 
附:
 

Memory usage determination with the ps command

The ps command can also be used to monitor memory usage of individual processes.

The ps v PID command provides the most comprehensive report on memory-related statistics for an individual process, such as:

  • Page faults
  • Size of working segment that has been touched
  • Size of working segment and code segment in memory
  • Size of text segment
  • Size of resident set
  • Percentage of real memory used by this process
The following is an example:
# ps v
   PID    TTY STAT  TIME PGIN  SIZE   RSS   LIM  TSIZ   TRS %CPU %MEM COMMAND
 36626  pts/3 A     0:00    0   316   408 32768    51    60  0.0  0.0 ps v

The most important columns on the resulting ps report are described as follows:

PGIN Number of page-ins caused by page faults. Since all I/O is classified as page faults, this is basically a measure of I/O volume. SIZE Virtual size (in paging space) in kilobytes of the data section of the process (displayed as SZ by other flags). This number is equal to the number of working segment pages of the process that have been touched times 4. If some 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. RSS 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 4. 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. TSIZ Size of text (shared-program) image. This is the size of the text section of the executable file. Pages of the text section of the executable program are only brought into memory when they are touched, that is, branched to or loaded from. This number represents only an upper bound on the amount of text that could be loaded. The TSIZ value does not reflect actual memory usage. This TSIZ value can also be seen by executing the dump -ov command against an executable program (for example, dump -ov /usr/bin/ls). TRS Size of the resident set (real memory) of text. This is the number of code segment pages times 4. This number exaggerates memory use for programs of which multiple instances are running. The TRS value can be higher than the TSIZ value because other pages may be included in the code segment such as the XCOFF header and the loader section. %MEM Calculated as the sum of the number of working segment and code segment pages in memory times 4 (that is, the RSS value), divided by the size of the real memory in use, in the machine in KB, times 100, rounded to the nearest full percentage point. This value attempts to convey the percentage of real memory being used by the process. Unfortunately, like RSS, it tends the exaggerate the cost of a process that is sharing program text with other processes. Further, the rounding to the nearest percentage point causes all of the processes in the system that have RSS values under 0.005 times real memory size to have a %MEM of 0.0.
Note: The ps command does not indicate memory consumed by shared memory segments or memory-mapped segments. Because many applications use shared memory or memory-mapped segments, the svmon command is a better tool to view the memory usage of these segments.
 
 

 

 
 
 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/195110/viewspace-764380/,如需轉載,請註明出處,否則將追究法律責任。

相關文章