7.4.2 Hierarchical Locking

The idea behind hierarchical locking is to have a coarse-grained lock that is held only long enough to work out which fine-grained lock to acquire. Figure [*] shows how our hash-table search might be adapted to do hierarchical locking, but also shows the great weakness of this approach: we have paid the overhead of acquiring a second lock, but we only hold it for a short time. In this case, the simpler data-locking approach would be simpler and likely perform better.

Figure: Hierarchical-Locking Hash Table Search
\begin{figure}{ \scriptsize
\begin{verbatim}1 struct hash_table
2 {
3 long ...
...spin_unlock(&bp->bucket_lock);
38 return 0;
39 }\end{verbatim}
}\end{figure}

Quick Quiz 7.14: In what situation would hierarchical locking work well? End Quick Quiz



Paul E. McKenney 2011-12-16