Thursday, December 21, 2017

Oracle Mutex

Mutexes are objects that exist within the operating system to provide access to shared memory structures. They are similar to latches, which will be covered in following chapters, as they are serialized mechanisms used to control access to shared data structures within the Oracle SGA.
Serialization provides benefits via mutexes in that they are required to avoid having database objects being read during modification and to provide consistency as part of the relational database ACID (Atomicity, Consistency, Isolation and Durability) model.

Mutexes can be used and defined in various ways. Each data structure within Oracle which is under the protection of a mutex can also have its own mutex such as a parent cursor may have its own separate mutex as well as each child cursor can also have its own mutex. Structures within Oracle can be protected by multiple mutexes so that each mutex will protect a different area of the database structure. While latches and mutexes are similar regarding both being serialization mechanisms and providing data protection, mutexes differ from latches in the following ways.

Mutexes are smaller and operate faster than latches because they contain fewer instructions than those in a latch get operation. Secondly, mutexes take up fewer memory resources and space than latches. Mutexes also provide less chance of contention within the database than latches do which means that mutexes provide greater protection of data structures and flexibility than latches.
Another key feature of mutexes is that they can be referenced across many sessions concurrently by using shared mode. Mutexes also function in a dual role as both a serialization item similar to a latch and also as pin operator by preventing objects from aging out of the Oracle memory buffers. Since both latches and mutexes are independent mechanisms, a process within Oracle can hold both a latch and mutex at the same time.

Oracle 10g release 2 and beyond replaced some latch mechanisms with the mutex approach, claiming that they are faster and more efficient than traditional locking mechanisms.  To improve cursor execution speed and hard pare time within the library cache, mutexes replace library cache latches and library cache pins. Oracle claims that mutexes are faster and use less CPU, which is important for CPU-bound database where large data buffers remove I/O as a primary source of contention. 
Oracle also claims that a mutex allows for improved concurrency over the older latch mechanism because the code path is shorter.   

No comments:

Post a Comment

Oracle traces including 10053 and 10046 trace

Running various oracle traces including 10053 and 10046 trace file   10053 trace file generation trace 10053 enables you to ...