<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: OC 4 Locks and Latches</title>
	<atom:link href="http://jonathanlewis.wordpress.com/oracle-core/oc-4-locks-and-latches/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanlewis.wordpress.com</link>
	<description>Just another Oracle weblog</description>
	<lastBuildDate>Wed, 22 May 2013 12:40:08 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Martin Maletinsky</title>
		<link>http://jonathanlewis.wordpress.com/oracle-core/oc-4-locks-and-latches/#comment-55152</link>
		<dc:creator><![CDATA[Martin Maletinsky]]></dc:creator>
		<pubDate>Wed, 01 May 2013 16:45:27 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?page_id=7139#comment-55152</guid>
		<description><![CDATA[Hello Jonathan,

I just finished reading chapter 7 which motivated me to revisit mutexes in chapter 4 (and to have a look at my previous questions / your answers relating to mutexes). In doing so, a new question regarding mutexes crossed my mind. On page 91 you write &quot;Mutexes are small, and don&#039;t have lists associated with them, we now have information pointing one way, the session knows which mutexes it is holding, but the mutex doesn&#039;t know which sessions are holding it.&quot;.
My question is, what happens when a session is holding mutexes and terminates unexpectedly (e.g. somebody killing the OS process with kill -9 on Unix)? There must be a way to notice that the mutex is being held by a no longer existing session, otherwise e.g. a library cache hash chain might remain unaccessible for all other sessions throughout the lifetime of the instance which I believe would not be acceptable.
So the question is where is the information stored that points from the session to the mutexes it holds? From my understanding of the Oracle memory achitecture, if it was in the PGA, it would not be accessible to other processes of the instance and therefore the information would be lost, once the session&#039;s server process terminates. So I believe it must be in the SGA (or are there other, less known memory areas that are shared memory accessible to all processes of the instance)? Can you confirm (or rectify) this assumption and if it is in the SGA, do you know in which of the SGA components this information is stored?

Thank you
kind regards
Martin]]></description>
		<content:encoded><![CDATA[<p>Hello Jonathan,</p>
<p>I just finished reading chapter 7 which motivated me to revisit mutexes in chapter 4 (and to have a look at my previous questions / your answers relating to mutexes). In doing so, a new question regarding mutexes crossed my mind. On page 91 you write &#8220;Mutexes are small, and don&#8217;t have lists associated with them, we now have information pointing one way, the session knows which mutexes it is holding, but the mutex doesn&#8217;t know which sessions are holding it.&#8221;.<br />
My question is, what happens when a session is holding mutexes and terminates unexpectedly (e.g. somebody killing the OS process with kill -9 on Unix)? There must be a way to notice that the mutex is being held by a no longer existing session, otherwise e.g. a library cache hash chain might remain unaccessible for all other sessions throughout the lifetime of the instance which I believe would not be acceptable.<br />
So the question is where is the information stored that points from the session to the mutexes it holds? From my understanding of the Oracle memory achitecture, if it was in the PGA, it would not be accessible to other processes of the instance and therefore the information would be lost, once the session&#8217;s server process terminates. So I believe it must be in the SGA (or are there other, less known memory areas that are shared memory accessible to all processes of the instance)? Can you confirm (or rectify) this assumption and if it is in the SGA, do you know in which of the SGA components this information is stored?</p>
<p>Thank you<br />
kind regards<br />
Martin</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vicky</title>
		<link>http://jonathanlewis.wordpress.com/oracle-core/oc-4-locks-and-latches/#comment-54453</link>
		<dc:creator><![CDATA[Vicky]]></dc:creator>
		<pubDate>Wed, 03 Apr 2013 14:01:01 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?page_id=7139#comment-54453</guid>
		<description><![CDATA[Hi Jonathan,

First let me congratulate you on this wonderful book. As many have pointed out, it requires several round of readings to get the internal workings and mechanism clear. But, it is worth putting these efforts.

On the Exclusive and Shared Latch concept, as I understand, as the exclusive get is compatible with shared, the latch can be obtained in an exclusive mode. However, the work to be done in an exclusive mode will only be initiated once all the reader value is dropped to ZERO. In this case, while a process has obtained a latch or mutex (a session) in exclusive mode, it will wait until the count drops to ZERO. The session wating for the count drop however not wait for &quot;Library Cache Mutex&quot; wait. But, in the same scenario, if there is another session that requires the latch to be obtained in exclusive mode, since there is already a session that has set a write bit and is waiting for the reader count to drop zero, the new session has to wait on &quot;Library Cache Mutex&quot;.  Also, the duration for this wait will become longer, if there are many readers holding the latch in shared mode. Am I correct ?

Regards
Vicky]]></description>
		<content:encoded><![CDATA[<p>Hi Jonathan,</p>
<p>First let me congratulate you on this wonderful book. As many have pointed out, it requires several round of readings to get the internal workings and mechanism clear. But, it is worth putting these efforts.</p>
<p>On the Exclusive and Shared Latch concept, as I understand, as the exclusive get is compatible with shared, the latch can be obtained in an exclusive mode. However, the work to be done in an exclusive mode will only be initiated once all the reader value is dropped to ZERO. In this case, while a process has obtained a latch or mutex (a session) in exclusive mode, it will wait until the count drops to ZERO. The session wating for the count drop however not wait for &#8220;Library Cache Mutex&#8221; wait. But, in the same scenario, if there is another session that requires the latch to be obtained in exclusive mode, since there is already a session that has set a write bit and is waiting for the reader count to drop zero, the new session has to wait on &#8220;Library Cache Mutex&#8221;.  Also, the duration for this wait will become longer, if there are many readers holding the latch in shared mode. Am I correct ?</p>
<p>Regards<br />
Vicky</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/oracle-core/oc-4-locks-and-latches/#comment-53235</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Mon, 28 Jan 2013 18:13:35 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?page_id=7139#comment-53235</guid>
		<description><![CDATA[Martin,

I don&#039;t think you&#039;ve misunderstood any of the points. But I think there&#039;s always the need to remember history. Some of the things that might look like unbalanced in terms of (say) CPU or memory utilisation may have seemed much more sensible 15 or 20 years ago; but the cost of change may override any consideration of change to a better strategy now.

Having said that, I have only come across a couple of occasions where the number of cache buffers chains latches really did need to be made much larger (factor of 2 or 4) than their default - so the current choice doesn&#039;t seem to have too much of a negative impact]]></description>
		<content:encoded><![CDATA[<p>Martin,</p>
<p>I don&#8217;t think you&#8217;ve misunderstood any of the points. But I think there&#8217;s always the need to remember history. Some of the things that might look like unbalanced in terms of (say) CPU or memory utilisation may have seemed much more sensible 15 or 20 years ago; but the cost of change may override any consideration of change to a better strategy now.</p>
<p>Having said that, I have only come across a couple of occasions where the number of cache buffers chains latches really did need to be made much larger (factor of 2 or 4) than their default &#8211; so the current choice doesn&#8217;t seem to have too much of a negative impact</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Maletinsky</title>
		<link>http://jonathanlewis.wordpress.com/oracle-core/oc-4-locks-and-latches/#comment-53141</link>
		<dc:creator><![CDATA[Martin Maletinsky]]></dc:creator>
		<pubDate>Wed, 23 Jan 2013 20:39:57 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?page_id=7139#comment-53141</guid>
		<description><![CDATA[Hello Jonathan,

Just one more word regarding the size of the latch structure. I noticed that on page 66 you write there are between 100 and 200 bytes of infrastructure and instrumentation (in addition to the memory location used for the state and session information). If this really is the entire size of a latch, it would mean that a mutex would only use between 4 and 8 bytes of memory (assuming the factor 25 you mention)? 
Also this would mean that the size of the latch structure is similar to the size of  the buffer header (page 96). If this is the case, it seems very little to have only one latch per 32 hash buckets. With the number of  hash buckets being twice the number of buffers, Oracle would therefore only allow 1/16 of the memory it uses for the buffer headers to be used for the latches protecting the hash chains - given the importance of concurrency I believe this is very little.

Do you agree with this considerations or did I misunderstand some point?

thank you
kind regards
Martin]]></description>
		<content:encoded><![CDATA[<p>Hello Jonathan,</p>
<p>Just one more word regarding the size of the latch structure. I noticed that on page 66 you write there are between 100 and 200 bytes of infrastructure and instrumentation (in addition to the memory location used for the state and session information). If this really is the entire size of a latch, it would mean that a mutex would only use between 4 and 8 bytes of memory (assuming the factor 25 you mention)?<br />
Also this would mean that the size of the latch structure is similar to the size of  the buffer header (page 96). If this is the case, it seems very little to have only one latch per 32 hash buckets. With the number of  hash buckets being twice the number of buffers, Oracle would therefore only allow 1/16 of the memory it uses for the buffer headers to be used for the latches protecting the hash chains &#8211; given the importance of concurrency I believe this is very little.</p>
<p>Do you agree with this considerations or did I misunderstand some point?</p>
<p>thank you<br />
kind regards<br />
Martin</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/oracle-core/oc-4-locks-and-latches/#comment-53116</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Tue, 22 Jan 2013 12:14:23 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?page_id=7139#comment-53116</guid>
		<description><![CDATA[Wojciech,

The lock mode can anything from level 0 to level 6 (see http://jonathanlewis.wordpress.com/2010/06/21/locks/ ), and there are rules about when it is legal for different sessions to lock the same object in different modes. 

For example, if you are locking a table in mode 3 (row-exclusive, probably updating a few rows) I cannot lock the same table in mode 6 (exclusive) until you have committed or rolled back. In the book example I would get to the head of the waiters queue, and have to wait for you (and any others updating the table) to get off the owners queue before I could join the owners queue.]]></description>
		<content:encoded><![CDATA[<p>Wojciech,</p>
<p>The lock mode can anything from level 0 to level 6 (see <a href="http://jonathanlewis.wordpress.com/2010/06/21/locks/" rel="nofollow">http://jonathanlewis.wordpress.com/2010/06/21/locks/</a> ), and there are rules about when it is legal for different sessions to lock the same object in different modes. </p>
<p>For example, if you are locking a table in mode 3 (row-exclusive, probably updating a few rows) I cannot lock the same table in mode 6 (exclusive) until you have committed or rolled back. In the book example I would get to the head of the waiters queue, and have to wait for you (and any others updating the table) to get off the owners queue before I could join the owners queue.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wojciech</title>
		<link>http://jonathanlewis.wordpress.com/oracle-core/oc-4-locks-and-latches/#comment-53073</link>
		<dc:creator><![CDATA[Wojciech]]></dc:creator>
		<pubDate>Sun, 20 Jan 2013 14:16:44 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?page_id=7139#comment-53073</guid>
		<description><![CDATA[Jonathan,

at the bottom of page 79 you say:
&quot;... only then can you attach yourself to the owners queue - provided the lock mode you want is compatible with the modes held by everyone currently on the owners queue&quot;

Could you elaborate on what exactly &quot;lock compatibility&quot; means?]]></description>
		<content:encoded><![CDATA[<p>Jonathan,</p>
<p>at the bottom of page 79 you say:<br />
&#8220;&#8230; only then can you attach yourself to the owners queue &#8211; provided the lock mode you want is compatible with the modes held by everyone currently on the owners queue&#8221;</p>
<p>Could you elaborate on what exactly &#8220;lock compatibility&#8221; means?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/oracle-core/oc-4-locks-and-latches/#comment-52985</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Fri, 18 Jan 2013 09:37:59 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?page_id=7139#comment-52985</guid>
		<description><![CDATA[Martin,

My brain produced a technical glitch there - for some reason I was thinking only of a mutex being held exclusive. Since only one process can hold exclusive there&#039;s enough space in the mutex itself to identify the SID of the holder.]]></description>
		<content:encoded><![CDATA[<p>Martin,</p>
<p>My brain produced a technical glitch there &#8211; for some reason I was thinking only of a mutex being held exclusive. Since only one process can hold exclusive there&#8217;s enough space in the mutex itself to identify the SID of the holder.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Maletinsky</title>
		<link>http://jonathanlewis.wordpress.com/oracle-core/oc-4-locks-and-latches/#comment-52972</link>
		<dc:creator><![CDATA[Martin Maletinsky]]></dc:creator>
		<pubDate>Thu, 17 Jan 2013 22:07:59 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?page_id=7139#comment-52972</guid>
		<description><![CDATA[Hello Jonathan,

Thanks a lot for your answers and for the time you take to share your knowledge about Oracle. I have a follow-up question regarding your response (ii). What do you mean by &quot;...a held mutex implicitly identifies the holder&quot;? In the book you write (p. 91) &quot;the session knows which mutexes it is holding, but the mutex doesn&#039;t know which sessions are holding it&quot;. Is that what you refer to when writing that the mutex implicitly identifies the holder?

thank you
kind regards
Martin]]></description>
		<content:encoded><![CDATA[<p>Hello Jonathan,</p>
<p>Thanks a lot for your answers and for the time you take to share your knowledge about Oracle. I have a follow-up question regarding your response (ii). What do you mean by &#8220;&#8230;a held mutex implicitly identifies the holder&#8221;? In the book you write (p. 91) &#8220;the session knows which mutexes it is holding, but the mutex doesn&#8217;t know which sessions are holding it&#8221;. Is that what you refer to when writing that the mutex implicitly identifies the holder?</p>
<p>thank you<br />
kind regards<br />
Martin</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/oracle-core/oc-4-locks-and-latches/#comment-52760</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Sat, 12 Jan 2013 10:13:13 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?page_id=7139#comment-52760</guid>
		<description><![CDATA[Martin,

i) I think what you&#039;re asking (rhetorically) and answering is the question: &quot;why invent mutexes,, why not simply put a latch on every single item?&quot;, and then arguing the case that the size of the memory structure would be the most significant reason for creating a new mechanism - and I agree; in fact I thought I&#039;d made that point somewhere in the book, but perhaps I hadn&#039;t. The thought behind the length of the code-path is that the bulk of the code exists to populate the parts of the latch structure that aren&#039;t the &quot;latch&quot; itself.  I&#039;ll have to check what Tom says about the &quot;7 times&quot; - the size of the latch structure has varied dramatically over versions, and I&#039;d have put the size difference closer to a factor of 25.

ii) I think a signiicant part of the code path is about instrumentation (and, in fact, somewhere in 10g or 11g, Oracle took out some of the code to count the number of sleep cycles a latch had been through); but there are also parts of the code that populate the structures with details of who is using the latch and from where in their code path.  This secondary code can be removed for mutexes because a held mutex implicitly idenfies the holder, and the state object for the holder holds the information for why and where it is being held.]]></description>
		<content:encoded><![CDATA[<p>Martin,</p>
<p>i) I think what you&#8217;re asking (rhetorically) and answering is the question: &#8220;why invent mutexes,, why not simply put a latch on every single item?&#8221;, and then arguing the case that the size of the memory structure would be the most significant reason for creating a new mechanism &#8211; and I agree; in fact I thought I&#8217;d made that point somewhere in the book, but perhaps I hadn&#8217;t. The thought behind the length of the code-path is that the bulk of the code exists to populate the parts of the latch structure that aren&#8217;t the &#8220;latch&#8221; itself.  I&#8217;ll have to check what Tom says about the &#8220;7 times&#8221; &#8211; the size of the latch structure has varied dramatically over versions, and I&#8217;d have put the size difference closer to a factor of 25.</p>
<p>ii) I think a signiicant part of the code path is about instrumentation (and, in fact, somewhere in 10g or 11g, Oracle took out some of the code to count the number of sleep cycles a latch had been through); but there are also parts of the code that populate the structures with details of who is using the latch and from where in their code path.  This secondary code can be removed for mutexes because a held mutex implicitly idenfies the holder, and the state object for the holder holds the information for why and where it is being held.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/oracle-core/oc-4-locks-and-latches/#comment-52759</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Sat, 12 Jan 2013 09:12:59 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?page_id=7139#comment-52759</guid>
		<description><![CDATA[Martin,
Thanks for your questions, I appreciate the trouble you&#039;ve taken to work through the book so thoroughly - even though the resulting questions do force me to take some time to re-think some of my comments (and possibly correct some errors).

i) I think there are probably many questions of this type where the answer is, in part at least, simply &quot;history&quot;. Unless my memory is wrong, the enqueue stuff appeared in version 6, but the major coding effort for sharing cursors - hence the shared pool etc. - appeared in version 7. Given the difference in timing it&#039;s easy to imagine a different group working on the various different problems with the sharedd pool and coming up with the generic strategy for allocating memory and simply applying it to the KGL pins and locks; there&#039;s also the possibility that someone looked at the enqueue strategy and saw that it made the DBA responsible for defining the number of KGL pins and KGL locks (particularly) at database startup time and saw this as a difficult problem.

ii) I have no good ideas about this one. I could guess three possibilities (a) the question of scale is completely different, (b) don&#039;t change code that isn&#039;t causing a threat (c) you can&#039;t do everything at once.  In a similar vein, I have wondered if there are any plans to change the &quot;cache buffers (LRU) chains&quot; latches  to mutexes]]></description>
		<content:encoded><![CDATA[<p>Martin,<br />
Thanks for your questions, I appreciate the trouble you&#8217;ve taken to work through the book so thoroughly &#8211; even though the resulting questions do force me to take some time to re-think some of my comments (and possibly correct some errors).</p>
<p>i) I think there are probably many questions of this type where the answer is, in part at least, simply &#8220;history&#8221;. Unless my memory is wrong, the enqueue stuff appeared in version 6, but the major coding effort for sharing cursors &#8211; hence the shared pool etc. &#8211; appeared in version 7. Given the difference in timing it&#8217;s easy to imagine a different group working on the various different problems with the sharedd pool and coming up with the generic strategy for allocating memory and simply applying it to the KGL pins and locks; there&#8217;s also the possibility that someone looked at the enqueue strategy and saw that it made the DBA responsible for defining the number of KGL pins and KGL locks (particularly) at database startup time and saw this as a difficult problem.</p>
<p>ii) I have no good ideas about this one. I could guess three possibilities (a) the question of scale is completely different, (b) don&#8217;t change code that isn&#8217;t causing a threat (c) you can&#8217;t do everything at once.  In a similar vein, I have wondered if there are any plans to change the &#8220;cache buffers (LRU) chains&#8221; latches  to mutexes</p>
]]></content:encoded>
	</item>
</channel>
</rss>
