PS-10595 [9.7]: Reduce rw_lock_list_mutex contention during buffer pool initialization#6039
Open
polchawa-percona wants to merge 1 commit into
Open
Conversation
1601e18 to
f961ae5
Compare
a2d2575 to
56d04e9
Compare
…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() only splices a caller-prepared list onto rw_lock_list in O(1) under a single rw_lock_list_mutex section. [*] buf_block_init() uses rw_lock_init_only_inst(); buf_chunk_init() builds the chunk's rw-lock list and registers it in bulk, exactly once per chunk creation. buf_pool_register_chunk() only inserts into the chunk map, since buf_pool_resize() re-invokes it on carried-over chunks and must not re-register (double-register) their locks in rw_lock_list. 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.
56d04e9 to
d36f785
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.