PS-10595 [9.7]: Reduce rw_lock_list contention during buffer pool initialization#6039
Open
polchawa-percona wants to merge 1 commit into
Open
Conversation
…tialization https://perconadev.atlassian.net/browse/PS-10595 This is a contribution from Alexey Bychko <abychko@gmail.com>, with a modification on top of the original patch: instead of inserting each chunk's rw-locks into the global rw_lock_list one by one while holding rw_lock_list_mutex, the per-chunk list is prepared outside the mutex and then concatenated onto rw_lock_list in O(1) under the mutex. During buffer pool initialization every buffer block rw-lock (block->lock and, in debug builds, block->debug_latch) was registered in the global rw_lock_list under rw_lock_list_mutex, one lock at a time. With large buffer pools and parallel initialization this serializes heavily on that single mutex. Initialize block rw-locks without registering them in rw_lock_list, then register a whole chunk's locks at once: [+] rw_lock_init_only() initializes an rw_lock_t exactly like rw_lock_create_func() but does not add it to rw_lock_list. A PFS-aware wrapper pfs_rw_lock_init_only_func() and the rw_lock_init_only_inst() macro preserve placement-new, pfs_psi and (debug) latch id handling. [+] ut_list_concatenate() / UT_LIST_CONCATENATE() splice one UT_LIST onto another in O(1). [+] rw_lock_list_register_bulk() builds nothing under the lock: the caller prepares the per-chunk list outside rw_lock_list_mutex, and this function only splices it onto rw_lock_list in O(1) under a single mutex section. [*] buf_block_init() now uses rw_lock_init_only_inst(); buf_pool_register_chunk() collects the chunk's block rw-locks into a local list and registers them in bulk. rw_lock_create_func() keeps its existing signature and behavior, so all other callers and diagnostics based on rw_lock_list are unaffected; the complete rw_lock_list is available once initialization finishes.
41bfb5c to
1601e18
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://perconadev.atlassian.net/browse/PS-10595
This is a contribution from Alexey Bychko abychko@gmail.com, with a
modification on top of the original patch: instead of inserting each chunk's
rw-locks into the global rw_lock_list one by one while holding
rw_lock_list_mutex, the per-chunk list is prepared outside the mutex and then
concatenated onto rw_lock_list in O(1) under the mutex.
During buffer pool initialization every buffer block rw-lock (block->lock
and, in debug builds, block->debug_latch) was registered in the global
rw_lock_list under rw_lock_list_mutex, one lock at a time. With large
buffer pools and parallel initialization this serializes heavily on that
single mutex.
Initialize block rw-locks without registering them in rw_lock_list, then
register a whole chunk's locks at once:
[+] rw_lock_init_only() initializes an rw_lock_t exactly like
rw_lock_create_func() but does not add it to rw_lock_list. A PFS-aware
wrapper pfs_rw_lock_init_only_func() and the rw_lock_init_only_inst()
macro preserve placement-new, pfs_psi and (debug) latch id handling.
[+] ut_list_concatenate() / UT_LIST_CONCATENATE() splice one UT_LIST onto
another in O(1).
[+] rw_lock_list_register_bulk() builds nothing under the lock: the caller
prepares the per-chunk list outside rw_lock_list_mutex, and this function
only splices it onto rw_lock_list in O(1) under a single mutex section.
[*] buf_block_init() now uses rw_lock_init_only_inst(); buf_pool_register_chunk()
collects the chunk's block rw-locks into a local list and registers them
in bulk.
rw_lock_create_func() keeps its existing signature and behavior, so all
other callers and diagnostics based on rw_lock_list are unaffected; the
complete rw_lock_list is available once initialization finishes.