Tuning Latch Contention: Cache-buffers-chain latches
Recently, I had an opportunity to tune latch contention for cache buffers chain (CBC) latches. The problem was high CPU-usage combined with poor application performance. A quick review of the statspack report for 15 minutes showed a latch-free wait as the top event, consuming approximately 3600 seconds in an 8-CPU server. CPU usage was quite high, which is a typical symptom of latch contention, due to the spinning involved. v$session_wait showed that hundreds of sessions were waiting for latch free event.
SQL> @waits10g
SID PID EVENT P1_P2_P3_TEXT
------ ------- ------------ --------------------------------------
294 17189 latch free address 15873156640-number 127-tries 0
628 17187 latch free address 15873156640-number 127-tries 0
....
343 17191 latch free address 15873156640-number 127-tries 0
599 17199 latch: cache address 17748373096-number 122-tries 0
buffers chains
337 17214 latch: cache address 17748373096-number 122-tries 0
buffers chains
.....
695 17228 latch: cache address 17748373096-number 122-tries 0
buffers chains
....
276 15153 latch: cache address 19878655176-number 122-tries 1
buffers chains
I will use a two-pronged approach to find the root cause scientifically. First, I’ll find the SQL suffering from latch contention and objects associated with the access plan for that SQL. Next,I will find the buffers involved in latch contention, and map that back to objects. Finally, I will match these two techniques to pinpoint the root cause.
Before I go any further, let’s do a quick summary of the internals of latch operations.

