Skip to content

PS-10595 [8.4]: Reduce rw_lock_list_mutex contention during buffer pool initialization#6037

Open
polchawa-percona wants to merge 1 commit into
percona:8.4from
polchawa-percona:PS-10595-8.4-rwlock-bulk-register
Open

PS-10595 [8.4]: Reduce rw_lock_list_mutex contention during buffer pool initialization#6037
polchawa-percona wants to merge 1 commit into
percona:8.4from
polchawa-percona:PS-10595-8.4-rwlock-bulk-register

Conversation

@polchawa-percona

@polchawa-percona polchawa-percona commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

This is an alternative solution to: #6033

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.

@polchawa-percona polchawa-percona changed the title PS-10595 (8.4) Reduce rw_lock_list contention during buffer pool initialization PS-10595 [8.4]: Reduce rw_lock_list contention during buffer pool initialization Jun 25, 2026
@polchawa-percona polchawa-percona self-assigned this Jun 25, 2026
@polchawa-percona polchawa-percona force-pushed the PS-10595-8.4-rwlock-bulk-register branch from 7ffb0fb to 5c6139b Compare June 25, 2026 10:35
@polchawa-percona polchawa-percona force-pushed the PS-10595-8.4-rwlock-bulk-register branch from 5c6139b to acb8246 Compare June 26, 2026 10:16
@polchawa-percona polchawa-percona force-pushed the PS-10595-8.4-rwlock-bulk-register branch 4 times, most recently from e985b4e to e857e1a Compare June 29, 2026 15:04
@polchawa-percona polchawa-percona changed the title PS-10595 [8.4]: Reduce rw_lock_list contention during buffer pool initialization PS-10595 [8.4]: Reduce rw_lock_list_mutex contention during buffer pool initialization Jun 29, 2026
…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.
@polchawa-percona polchawa-percona force-pushed the PS-10595-8.4-rwlock-bulk-register branch from e857e1a to 3462a86 Compare June 29, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants