DB2内存浅谈
DB2的内存架构感觉比较乱,而且除了文档没有一个直观的认识,这里简单的分析下
$ db2start 11/09/2011 21:41:34 0 0 SQL1026N The database manager is already active. SQL1026N The database manager is already active. 首先启动实例,这里看到 $ ps avx | head -1 ;ps avx |grep db2 PID TTY STAT TIME PGIN SIZE RSS LIM TSIZ TRS %CPU %MEM COMMAND 225444 - A 0:00 0 288 364 32768 56 88 0.0 0.0 db2ckpwd 266286 pts/0 A 0:00 0 216 252 32768 26 36 0.0 0.0 grep db2 295120 - A 0:00 0 496 572 32768 56 88 0.0 0.0 db2wdog 307378 - A 0:00 0 296 364 32768 56 88 0.0 0.0 db2ckpwd 315562 - A 0:00 0 292 364 32768 56 88 0.0 0.0 db2ckpwd 323766 - A 0:00 0 2256 2300 32768 12 44 0.0 0.0 db2vend 331960 - A 0:00 62 6444 6512 32768 56 88 0.0 1.0 db2sysc 356528 - A 0:00 66 6996 7040 32768 12 44 0.0 1.0 db2acd 0 $ db2mtrk -i Tracking Memory on: 2011/11/09 at 21:57:01 Memory for instance other fcmbp monh 10.3M 832.0K 64.0K $ db2pd -memset Database Partition 0 -- Active -- Up 0 days 00:24:09 -- Date 11/09/2011 21:57:53 Memory Sets: Name Address Id Size(Kb) Key DBP Type Unrsv(Kb) Used(Kb) HWM(Kb) Cmt(Kb) Uncmt(Kb) DBMS 0x0780000000000000 1048582 49920 0x50151D61 0 0 10240 11520 11520 11520 38400 FMP 0x0780000010000000 1048583 22592 0x0 0 0 2 0 192 22592 0 Trace 0x0770000000000000 1048581 137576 0x50151D74 0 -1 0 137576 0 137576 0 $ db2pd -dbptnmem Database Partition 0 -- Active -- Up 0 days 00:24:20 -- Date 11/09/2011 21:58:04 Database Partition Memory Controller Statistics Controller Automatic: Y Memory Limit: 1598364 KB Current usage: 75648 KB HWM usage: 75776 KB Cached memory: 11648 KB Individual Memory Consumers: Name Mem Used (KB) HWM Used (KB) Cached (KB) ======================================================== DBMS-db2inst1 49920 49920 10240 FMP_RESOURCES 22528 22528 0 PRIVATE 3200 3200 1408 抓了这些数据之后,问题出现了,每一项之间都对不上db2pd -dbptnmem和db2pd -memset感觉最接近,而从ps出的命令及db2mtrk -i感觉和前俩个差了很多。 这次用db2pd -mempool看下db2pd -memset的细节 Memory Pools: Address MemSet PoolName Id Overhead LogSz LogUpBnd LogHWM PhySz PhyUpBnd PhyHWM Bnd BlkCnt CfgParm 0x07800000000012A8 DBMS fcm 74 0 0 1931054 0 0 1966080 0 Ovf 0 n/a 0x0780000000001160 DBMS fcmsess 77 65376 1401568 1687552 1401568 1572864 1703936 1572864 Ovf 3 n/a 0x0780000000001018 DBMS fcmchan 79 65376 259584 507904 259584 393216 524288 393216 Ovf 3 n/a 0x0780000000000ED0 DBMS fcmbp 13 65376 656896 925696 656896 851968 983040 851968 Ovf 3 n/a 0x0780000000000D88 DBMS fcmctl 73 111872 1594189 8675456 1594189 1769472 8716288 1769472 Ovf 11 n/a 0x0780000000000C40 DBMS monh 11 0 0 368640 224 65536 393216 65536 Ovf 0 MON_HEAP_SZ 0x0780000000000AF8 DBMS resynch 62 41216 155320 2752512 155320 262144 2752512 262144 Ovf 2 n/a 0x07800000000009B0 DBMS apmh 70 4512 737036 7929856 737036 786432 7929856 786432 Ovf 13 n/a 0x0780000000000868 DBMS kerh 52 96 196520 4128768 196520 262144 4128768 262144 Ovf 27 n/a 0x0780000000000720 DBMS bsuh 71 0 38408 15138816 74803 131072 15138816 131072 Ovf 12 n/a 0x07800000000005D8 DBMS sqlch 50 0 2683025 2752512 2683025 2752512 2752512 2752512 Ovf 203 n/a 0x0780000000000490 DBMS krcbh 69 0 146088 131072 146176 196608 131072 196608 Ovf 10 n/a 0x0780000000000348 DBMS eduah 72 65440 2621384 2621408 2621384 2686976 2621440 2686976 Ovf 1 n/a 0x0780000010000348 FMP undefh 59 8000 122900 22971520 122900 131072 23003136 131072 Phy 1 n/a 有点长,这里可以发现db2mtrk -i 中的mon对应的其实就是 0x0780000000000C40 DBMS monh 11 0 0 368640 224 65536 393216 65536 Ovf 0 MON_HEAP_SZ 也就是 MON_HEAP_SZ参数,而fcm对应的是 0x0780000000000ED0 DBMS fcmbp 13 65376 656896 925696 656896 851968 983040 851968 Ovf 3 n/a 把db2pd -mempool所有值除去刚才提到的俩个及fmp其实就是db2mtrk -i中other的值,这样二者就对应起来了。
对于操作系统而言,程序的内存分配分为代码段,私有内存,共享内存,栈等。接下来我们从操作系统角度来继续观察DB2的内存分配及使用状况。
OS:AIX 6100-06
db2level: V9.7.0.2
-------------------------------------------------------------------------------
Pid Command Inuse Pin Pgsp Virtual 64-bit Mthrd 16MB
299158 db2sysc 56655 8291 0 56600 Y Y N
Vsid Esid Type Description PSize Inuse Pin Pgsp Virtual
1022011 90000000 work shared library text s 22582 0 0 22582
1004382 70000003 work default shmat/mmap s 12052 0 0 12052
4002 0 work fork tree s 8608 8243 0 8608
children=872b20, 0
102a3d5 78000000 work default shmat/mmap s 3184 0 0 3184
103e3ff 11 work text data BSS heap s 2681 0 0 2681
parent=101e40f
a005 9ffffffd work fork tree s 2231 0 0 2231
children=85f1ec, 0
10203d0 77000000 work default shmat/mmap s 1541 0 0 1541
10262f3 70000002 work default shmat/mmap s 1364 0 0 1364
10383dc 9001000a work shared library data s 1071 0 0 1071
parent=1026413
1026013 90020014 work shared library s 1000 0 0 1000
1006443 - work s 104 26 0 104
1a00d 9ffffffe work fork tree s 69 0 0 69
children=5f93e4, 0
10063a3 80020014 work USLA heap s 60 0 0 60
parent=1022411
103a3fd f00000002 work process private s 30 22 0 30
parent=101a40d
100c3e6 10 clnt text data BSS heap, s 22 0 - -
/dev/hd1:16522
102c3f6 78000001 work default shmat/mmap s 21 0 0 21
1000000 9fffffff clnt USLA text,/dev/hd2:2235 s 14 0 - -
10003e0 8fffffff work private load data s 9 0 0 9
。。。
这里我们可以很清楚的看到数据库各个区域的内存,也可以关联db2pd -memset来对比下。
先看共享内存
1004382 70000003 work default shmat/mmap s 12052 0 0 12052
102a3d5 78000000 work default shmat/mmap s 3184 0 0 3184
10203d0 77000000 work default shmat/mmap s 1541 0 0 1541
10262f3 70000002 work default shmat/mmap s 1364 0 0 1364
102c3f6 78000001 work default shmat/mmap s 21 0 0 21
这些分别对应着每一块分配的内存,其中
102a3d5 78000000 work default shmat/mmap s 3184 0 0 3184
Name Address Id Size(Kb) Key DBP Type Unrsv(Kb) Used(Kb) HWM(Kb) Cmt(Kb) Uncmt(Kb)
DBMS 0x0780000000000000 1048577 49920 0x65A4A761 0 0 10240 12672 12736 12736 37184
12736=3184*4(K)
这里可以很清楚的把db2的memset和操作系统中分配的对应起来。
然后再看私有内存。
$ ps aux |head -1;ps uax | grep db2
USER PID %CPU %MEM SZ RSS TTY STAT STIME TIME COMMAND
db2inst1 299158 0.1 2.0 16748 16760 - A 19:12:51 0:29 db2sysc 0
db2inst1 340152 0.0 1.0 13204 13240 - A 19:12:56 0:04 db2acd 0
db2fen1 241740 0.0 0.0 4484 4520 - A 21:13:01 0:00 db2fmp (C) 0
db2inst1 188658 0.0 0.0 4012 3076 - A 19:12:40 0:00 /home/db2inst1/s
db2inst1 323766 0.0 0.0 2276 2312 - A 19:12:55 0:00 db2vend (PD Vend
db2inst1 327860 0.0 1.0 6696 6288 - A 19:12:56 0:00 /opt/IBM/db2/V9.
root 311448 0.0 0.0 352 364 - A 19:12:52 0:00 db2ckpwd 0
root 307350 0.0 0.0 348 364 - A 19:12:52 0:00 db2ckpwd 0
root 290954 0.0 0.0 560 580 - A 19:12:51 0:00 db2wdog 0
root 303254 0.0 0.0 344 364 - A 19:12:52 0:00 db2ckpwd 0
RSS一列即代表数据库分配的私有内存大小。
但是私有内存从数据库角度很难看到。