A key to good performance is the efficient matching of locks to shared data. If too much shared data is controlled by a single lock, the likelihood of lock contention increases. Lock contention occurs when more than one thread wishes to access the same shared data object. By improving the lock granularity, which is accomplished by reducing the amount of shared data associated with a particular lock, the amount of lock contention can be reduced. This improvement can become significant as the number of CPUs in the system increases.
Care must be taken when improving lock granularity. At times related data structures must be controlled by a single lock. In addition, the frequency of contention must be determined to ensure that the cost of acquiring multiple locks does not overcome the benefit of the improved granularity.