Skip to content

PS-10595 [8.4]: Lazy initialization for buffer pool block latches#6033

Open
polchawa-percona wants to merge 3 commits into
percona:8.4from
polchawa-percona:PS-11120-8.4-lazy-latch-init
Open

PS-10595 [8.4]: Lazy initialization for buffer pool block latches#6033
polchawa-percona wants to merge 3 commits into
percona:8.4from
polchawa-percona:PS-11120-8.4-lazy-latch-init

Conversation

@polchawa-percona

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

Copy link
Copy Markdown
Contributor

Buffer pool initialization speedup

  1. Refactor buf_block_init into buf_block_init_light(), performing only lightweight setup without creating latches.
  2. Introduce lazy, latch initialization for buffer blocks via buf_block_initialize_latches().
  3. Call lazy latch initialization when a block is taken from the free list the first time.
  4. Adjust buf_pool teardown to free mutexes/rwlocks only for blocks that had latches initialized.

The patch is based on contribution from Alexey Bychko: adf7b21

Modifications:

  • sysvar to enable this optionally,
  • the lazy initialization is enough to be done when taking from the free list,
  • sharding is removed (was broken),
  • replaced CAS with regular store to non-atomic variable:
    • no concurrent accesses to that logic for the same block,
    • note, that otherwise: they wouldn't be thread-safe (a thread could have been scheduled out just before creating the mutex but after the CAS succeeded),
    • accesses are protected by free_list_mutex or it is a startup phase

@polchawa-percona polchawa-percona force-pushed the PS-11120-8.4-lazy-latch-init branch from b79f2ab to 0a7cb18 Compare June 24, 2026 12:14
[*] Refactor buf_block_init into buf_block_init_light(), performing only lightweight control block setup without creating latches.
[*] Introduce lazy, thread-safe latch initialization for buffer blocks via buf_block_ensure_latches_initialized(), guarded by an atomic latches_initialized flag.
[*] Call lazy latch initialization when a block is taken from the free list and when initializing pages for read/creation, ensuring latches are created only on first real use.
[*] Replace the global buf_chunk_map_reg with a sharded buf_pool_chunk_map, protected by per-shard mutexes to reduce contention during parallel buffer pool creation and resize.
[*] Remove the global std::mutex from buf_pool_create/buf_chunk_init; take per-shard locks inside buf_chunk_init and unregister chunks from the appropriate shard maps during buffer pool teardown and resize.
[*] Adjust buf_block and buf_pool teardown to free mutexes/rwlocks only for blocks that had latches initialized, and to correctly free all sharded chunk maps.
@polchawa-percona polchawa-percona force-pushed the PS-11120-8.4-lazy-latch-init branch from 0a7cb18 to 6877a82 Compare June 24, 2026 12:49
@polchawa-percona polchawa-percona changed the title PS-11120 [8.4]: Lazy initialization for buffer pool block latches PS-10595 [8.4]: Lazy initialization for buffer pool block latches Jun 25, 2026
@polchawa-percona

Copy link
Copy Markdown
Contributor Author

Note - the alternative possible solution is: #6037
I will test both and provide numbers.

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