Rate This Document
Findability
Accuracy
Completeness
Readability

Principles

In the case of high throughput, rw_lock_s_lock_func contention is caused by Buf_fetch_normal::get in MySQL. The key calling path is buf_page_get_gen->Buf_fetch::single_page->Buf_fetch_normal::get. Buf_fetch_normal::get obtains the pointer to the data block of the target data page in the buffer pool. That is, obtain buf_block_t* by querying space_id and page_no to read and write the page content. The mapping is maintained by a hash table called page_hash and protected by hash_table_locks. The contention on rw_lock_s_lock_func is caused by adding read locks using hash_table_locks.

Sharding lock objects that are frequently accessed is a common tuning method. In the MySQL source code, sharding has been applied to tune hash_table_locks. The number of shards is controlled by srv_n_page_hash_locks and hardcoded to 16.

Figure 1 Comparison of hash_table_locks before and after tuning