Latch, mutex and beyond

August 24, 2010

Exclusive latches in memory. Oracle versions 7-11.2

Filed under: 11.2,Latch,Uncategorized — andreynikolaev @ 8:54 am
Tags:

Contrary to popular believe Oracle latches were significantly evolved through the last decade. Not only additional statistics appeared (and disappeared) and new (shared)  latch type was introduced,  the latch  itself was changed

It is interesting to see how the latch was organized in the past and contemporary  versions.

To see the latch in-memory seems hard, since latches typically held for a small amount of time. Hopefully Oracle gives us a possibility to call any its kernel function using oradebug call utility. We only need to know that Oracle itself uses kslgetl(laddr, wait, why, where) function to acquire the exclusive latch. Recently I blogged about this function and its parameters.

This function can be also used to artificially acquire any latch for demonstration by:


SQL> oradebug call kslgetl <latch address> <wait> <why> >where>


Note that this definitely should be done in the test environment only. It is safer to choose not used (GETS=0) latch of level# 0.
To see how this busy latch looks in memory one can use another oradebug command:


SQL> oradebug peek  <latch address> 1

And finally we need to free the latch:


SQL> oradebug call kslfre <latch address>

Now we have all the tools needed. Let us see how the exclusive latch looks in Oracle 11.2 for Linux 32bit:


SQL> oradebug setmypid
Statement processed.
SQL> select addr, name from v$latch_parent where name='test excl. non-parent l0';

ADDR     NAME
-------- ----------------------------------------------------------------
20006248 test excl. non-parent l0

SQL> oradebug peek 0x20006248 1
[20006248, 2000624C) = 00000000   -- Latch is free in memory, let us acquire it
SQL> oradebug call kslgetl 0x20006248 1 2 3
Function returned 1
SQL> oradebug peek 0x20006248 1
[20006248, 2000624C) = 00000017   -- Latch is busy. It is held by pid=0x17, let us free it
SQL> oradebug call kslfre 0x20006248
Function returned 0

Oracle 11g used PID value from v$process to indicate that exclusive latch is busy. Notice that Oracle latch is hold by process, not session.  On the contrary mutexes are hold by sessions.

Oracle not always used PID for this purpose in the past. In fact busy exclusive latch had the value of:

  • 1 in version 7
  • 0xFF in versions 8.0-10.2
  • PID in version 11g
Advertisement

1 Comment »

  1. […] finally I would like to show the latch in memory itself. No problem. On entry to kslgetl the arg0 is the latch address. I will check this location on […]

    Pingback by Appetizer for DTrace « Latch, mutex and beyond — October 28, 2010 @ 3:34 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: