[20190419]shared latch spin count 2.txt
–//上午测试shared latch xx模式的情况,链接:http://blog.itpub.net/267265/viewspace-2641902/
–//继续测试其它情况.
–//链接:http://andreynikolaev.wordpress.com/2011/01/14/spin-tales-part-2-shared-latches-in-oracle-9-2-11g/
s mode get x mode get
held in s mode compatible 2*_spin_count
held in x mode 0 2*_spin_count
blocking mode 0 2*_spin_count
1.环境:
scott@book> @ ver1
port_string version banner
—————————— ————– ——————————————————————————–
x86_64/linux 2.4.xx 11.2.0.4.0 oracle database 11g enterprise edition release 11.2.0.4.0 – 64bit production
sys@book> @ hide spin_count
name description default_value session_value system_value
—————– ———————————- ————- ————- ————
_mutex_spin_count mutex spin count true 255 255
_spin_count amount to spin waiting for a latch true 2000 2000
$ cat shared_latch.txt
/* 参数如下: @ latch.txt latch_name willing why where mode sleep_num */
–//connect / as sysdba
col laddr new_value laddr
col vmode new_value vmode
select decode(lower(‘&&5′),’s’,8,’x’,16,’8′,8,’16’,16) vmode from dual ;
select addr laddr from v$latch_parent where name=’&&1′;
oradebug setmypid
oradebug call kslgetsl_w 0x&laddr &&2 &&3 &&4 &vmode
host sleep &&6
oradebug call kslfre 0x&laddr
–//exit
–//注:我前几天的测试脚本有connect / as sysdba,exit这两行,我为了调式方便,先注解这2行,避免反复退出进入会话.
2.测试1:
–//选择一个shared latch测试,我选择”test shared non-parent l0″ latch测试:
sys@book> select * from shared_latches where name=’test shared non-parent l0′;
version latch# name s
———- —— ————————- –
11.2.0.4.0 6 test shared non-parent l0 y
2.测试一些细节不再列出,参考链接:http://blog.itpub.net/267265/viewspace-2641902/
–//测试xs模式的情况:
–//session 1:
sys@book> @ shared_latch.txt “test shared non-parent l0” 1 1 2 x 100000
–//session 2:
sys@book> @ spid
sid serial# process server spid pid p_serial# c50
———- ———- ———————— ——— —— ——- ———- ————————————————–
1 11 31454 dedicated 31455 24 5 alter system kill session ‘1,11’ immediate;
–//记下spid=31455.
sys@book> @shared_latch.txt “test shared non-parent l0” 1 3 4 s 1
–//注意session 申请s mode.
–//window 3:执行:
$ rlwrap gdb -p 31455 -x spin_s.gdb
breakpoint 1 at 0x93f97a8
breakpoint 2 at 0x93f9b74
breakpoint 3 at 0x9808932
breakpoint 4 at 0x9809840
breakpoint 5 at 0x37990d6400
breakpoint 6 at 0x93f9ddc
breakpoint 7 at 0x93faa36
breakpoint 8 at 0xa865ca
breakpoint 9 at 0xa874fa
breakpoint 10 at 0xa875be
(gdb) c
continuing.
…
kslgetl 6010d860, 1, 2126093176, 3991
ksl_get_shared_latch laddr:85f7f4c8, willing:1, where:-2043602896, why:96, mode:16
ksl_get_shared_latch laddr:85f7f4c8, willing:1, where:-2043602896, why:95, mode:8
ksl_get_shared_latch laddr:85f7f4c8, willing:1, where:-2043602896, why:96, mode:16
ksl_get_shared_latch laddr:85f7f4c8, willing:1, where:-2043602896, why:95, mode:8
ksl_get_shared_latch laddr:85f7f4c8, willing:1, where:-2043602896, why:96, mode:16
ksl_get_shared_latch laddr:85f7f4c8, willing:1, where:-2043602896, why:95, mode:8
ksl_get_shared_latch laddr:85f7f4c8, willing:1, where:-2043602896, why:96, mode:16
ksl_get_shared_latch laddr:60009a18, willing:1, where:3, why:4, mode:8
kslgess 60009a18, 8, 0, 3
kslskgs 60009a18, 0, 1129096976, 1129097520
kslskgs 60009a18, 0, 1129096976, 1129097520
—type <return> to continue, or q <return> to quit—
skgpwwait 1129096760, 202182304, -2044672536, 0
sskgpwwait 1129096760, 202182304, -2044672536, 0
semop 315588608, 1129096560, 1, -1
–//按ctrl+c出现如下:
kslskgs 60009a18, 0, 1129096976, 1129097520
–//可以看出x模式的情况,申请s mode,第2进程直接调用semop.根本不做spin操作.
3.测试2:
–//测试sx模式的情况:
–//session 1:
sys@book> @ shared_latch.txt “test shared non-parent l0” 1 1 2 s 100000
–//session 持有s mode.
–//session 2:
sys@book> @shared_latch.txt “test shared non-parent l0” 1 3 4 x 1
–//注意session 申请x mode.
–//window 3:执行:
$ rlwrap gdb -p 31455 -x spin_s.gdb
..
ksl_get_shared_latch laddr:85f7f4c8, willing:1, where:-2043602896, why:95, mode:8
ksl_get_shared_latch laddr:85f7f4c8, willing:1, where:-2043602896, why:96, mode:16
ksl_get_shared_latch laddr:60009a18, willing:1, where:3, why:4, mode:16
kslgess 60009a18, 16, 0, 3
kslskgs 60009a18, 0, 1129096976, 1129097520
spin count loop: 2000 a875be
spin count loop: 1999 a875be
spin count loop: 1998 a875be
spin count loop: 1997 a875be
…
spin count loop: 3 a875be
spin count loop: 2 a875be
spin count loop: 1 a875be
kslskgs 60009a18, 0, 1129096976, 1129097520
spin count loop: 1 a875be
skgpwwait 1129096760, 202182304, -2044672536, 0
sskgpwwait 1129096760, 202182304, -2044672536, 0
semop 315588608, 1129096560, 1, -1
–//按ctrl+c后.
kslskgs 60009a18, 0, 1129096976, 1129097520
spin count loop: 2000 a875be
–//可以s模式的情况,申请x mode,第2进程spin_count=2000.
4.测试3:
–//blocking mode,首先我对这个模式的理解不是非常清晰.
–//我的理解
a.当前x mode持有,不管s,x模式申请都会阻塞,再有进程申请的情况.
b.当前s mode持有,x模式申请,后续再有进程申请的情况.
–//也就是这个情况至少3个会话,我分别测试看看
–//session 1:
sys@book> @ shared_latch.txt “test shared non-parent l0” 1 1 2 s 100000
–//session 2:
sys@book> @ shared_latch.txt “test shared non-parent l0” 1 3 4 x 1
–//session 3:
–//spid=31572
sys@book> @ shared_latch.txt “test shared non-parent l0” 1 5 6 s 1
–//gdb监测session 3进程:
$ rlwrap gdb -p 31572 -x spin_s.gdb
…
ksl_get_shared_latch laddr:85f7fa68, willing:1, where:-2042914736, why:95, mode:8
ksl_get_shared_latch laddr:85f7fa68, willing:1, where:-2042914736, why:96, mode:16
ksl_get_shared_latch laddr:60009a18, willing:1, where:5, why:6, mode:8
kslgess 60009a18, 8, 0, 5
kslskgs 60009a18, 0, -1923148048, -1923147504
kslskgs 60009a18, 0, -1923148048, -1923147504
skgpwwait -1923148264, 202182304, -2044655416, 0
sskgpwwait -1923148264, 202182304, -2044655416, 0
semop 315588608, -1923148464, 1, -1
kslskgs 60009a18, 0, -1923148048, -1923147504
–//申请s mode,没有spin.
–//session 1:
sys@book> @ shared_latch.txt “test shared non-parent l0” 1 1 2 s 100000
–//session 2:
sys@book> @ shared_latch.txt “test shared non-parent l0” 1 3 4 x 1
–//session 3:
–//spid=31572
sys@book> @ shared_latch.txt “test shared non-parent l0” 1 5 6 x 1
–//gdb监测session 3进程:
$ rlwrap gdb -p 31572 -x spin_s.gdb
…
ksl_get_shared_latch laddr:85f7fa68, willing:1, where:-2042914736, why:96, mode:16
ksl_get_shared_latch laddr:60009a18, willing:1, where:5, why:6, mode:16
kslgess 60009a18, 16, 0, 5
kslskgs 60009a18, 0, -1923148048, -1923147504
spin count loop: 2000 a875be
spin count loop: 1999 a875be
spin count loop: 1998 a875be
spin count loop: 1997 a875be
…
spin count loop: 1 a875be
kslskgs 60009a18, 0, -1923148048, -1923147504
spin count loop: 1 a875be
skgpwwait -1923148264, 202182304, -2044655416, 0
sskgpwwait -1923148264, 202182304, -2044655416, 0
semop 315588608, -1923148464, 1, -1
kslskgs 60009a18, 0, -1923148048, -1923147504
spin count loop: 2000 a875be
–//申请x mode,spin_count=2000.
–//xss的情况:
ksl_get_shared_latch laddr:85f7fa68, willing:1, where:-2042914736, why:96, mode:16
ksl_get_shared_latch laddr:60009a18, willing:1, where:5, why:6, mode:8
kslgess 60009a18, 8, 0, 5
kslskgs 60009a18, 0, -1923148048, -1923147504
kslskgs 60009a18, 0, -1923148048, -1923147504
skgpwwait -1923148264, 202182304, -2044655416, 0
sskgpwwait -1923148264, 202182304, -2044655416, 0
semop 315588608, -1923148464, 1, -1
kslskgs 60009a18, 0, -1923148048, -1923147504
–//xsx的情况:
ksl_get_shared_latch laddr:85f7fa68, willing:1, where:-2042914736, why:96, mode:16
ksl_get_shared_latch laddr:60009a18, willing:1, where:5, why:6, mode:16
kslgess 60009a18, 16, 0, 5
kslskgs 60009a18, 0, -1923148048, -1923147504
spin count loop: 2000 a875be
spin count loop: 1999 a875be
spin count loop: 1998 a875be
spin count loop: 1997 a875be
spin count loop: 1996 a875be
spin count loop: 1995 a875be
…
sskgpwwait -1923148264, 202182304, -2044655416, 0
semop 315588608, -1923148464, 1, -1
kslskgs 60009a18, 0, -1923148048, -1923147504
spin count loop: 2000 a875be
–//总之:阻塞申请x mode,spin_count=2000.s mode 直接调用semop休眠.
5.总结
–//画一个表格:
s mode get x mode get
held in s mode compatible _spin_count
held in x mode 0 _spin_count
blocking mode 0 _spin_count