这是indexloc提供的服务,不要输入任何密码
Skip to content

MDEV-36190: Optimize transaction_lock_guard use #4188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: 11.4
Choose a base branch
from
Draft

Conversation

dr-m
Copy link
Contributor

@dr-m dr-m commented Jul 11, 2025

  • The Jira issue number for this PR is: MDEV-36190

Description

This also includes #4172 so that it could be more convenient to test both at the same time.

buf_pool_t::page_guess(): Avoid a memory transaction, because we would be checking several conditions inside it.

buf_pool_t::page_hash_table::lock_and_append(): A new function, used in two places. Attempt to use a simple memory transaction for inserting the first bucket of a chain. For any more complex case, fall back to normal latching.

buf_pool_t::page_hash_table::append(): Define non-inline.

buf_pool_t::page_hash_table::replace(), buf_pool_t::page_hash_table::remove(): Move the inline definition to the compilation unit of the only caller, to declutter the header.

buf_page_create_low(): Invoke buf_page_t::set_state() before inserting into the buf_pool.page_hash. It is safe to do this, because we are holding buf_pool.mutex.

Release Notes

On some Intel Xeon CPUs, performance was improved slightly.

How can this PR be tested?

Various performance test workloads on various CPU implementations that support hardware memory transactions. For x86-64, that would be Intel® Xeon® models.

Basing the PR against the correct MariaDB version

  • This is a new feature or a refactoring, and the PR is based against the main branch.
  • This is a bug fix, and the PR is based against the earliest maintained branch in which the bug can be reproduced.

This is a performance bug fix. The change to buf_page_init_for_read() depends on f27e9c8, and 11.4 is the oldest maintained branch that includes that change.

PR quality check

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

@dr-m dr-m self-assigned this Jul 11, 2025
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

dr-m added 2 commits July 15, 2025 15:24
Recent performance tests suggest that spin loops on
index_lock and block_lock are hurting performance,
especially in cases when progress is blocked by an I/O wait.
The simplest case would be that the waited-for block is
io-fixed (being read into the buffer pool or written back to
data files). A more complex case is that a thread that is
waiting for I/O on another block or on the log file is holding
a conflicting latch on an index tree or a buffer page.

Disabling the spin loops altogether for index_lock and block_lock
seems to yield overall the best result.

Note: For latches that are not being held while waiting for any I/O,
such as trx_t::mutex, spin loops may still be helpful. In fact,
we tried disabling all spin loops altogether, and got worse performance.

ssux_lock_impl<false>::rd_lock(): Jump straight to rd_wait()
without one step of spinning.

ssux_lock_impl<false>::rd_wait(): Invoke rd_lock_try() before
entering the wait.
buf_read_page(): Return a pointer to a buffer-fixed, non-read-fixed page,
or nullptr in case of an error.

buf_inc_get(): Wrapper for buf_inc_get(ha_handler_stats*),
to read the thread-local variable mariadb_stats before updating it.

IORequest::read_complete(): Assert that the page is both read-fixed
and buffer-fixed. Sample recv_sys.recovery_on only once.
Buffer-unfix the page when the asynchronous read completes.

buf_page_t::read_complete(): Assert that the page is both
read-fixed and buffer-fixed.

buf_page_t::read_wait(): Wait for a read-fixed and buffer-fixed page
to be only read-fixed. Return the state and optionally page identifier
when holding a shared latch.

buf_page_init_for_read(): Return a pointer to a buffer-fixed block
descriptor pointer, bitwise-ORed with 1 in case the block already
exists in the buffer pool.

buf_read_ahead_update(), buf_read_ahead_update_sql(): Common code
for updating some statistics counters.

buf_read_page_low(): Replace the parameter sync with err, which will
return an error code to a synchronous caller. Add a parameter for
thread-local mariadb_stats.
Return the pointer to the block, or the special values nullptr
(read failure) or -1 or -2 for asynchronous reads.
Increment the statistics when a synchronous read was requested.
In a synchronous read, if the page has already been allocated in
the buffer pool but it is read-fixed, wait for the read to complete.

buf_page_get_zip(): Get a buffer-fixed page from buf_read_page(),
and unfix() it. Our caller is relying solely on a page latch.

buf_read_page_background(): Update the statistics if supplied.
@dr-m dr-m force-pushed the MDEV-36190 branch 2 times, most recently from 9e954c4 to 77e452f Compare July 15, 2025 14:19
buf_pool_t::page_guess(): Avoid a memory transaction, because
we would be checking several conditions inside it.

buf_pool_t::page_hash_table::lock_and_append(): A new function,
used in two places. Attempt to use a simple memory transaction
for inserting the first bucket of a chain. For any more complex
case, fall back to normal latching.

buf_pool_t::page_hash_table::append(): Define non-inline.

buf_pool_t::page_hash_table::replace(),
buf_pool_t::page_hash_table::remove(): Move the inline definition
to the compilation unit of the only caller, to declutter the header.

buf_page_create_low(): Invoke buf_page_t::set_state() before inserting
into the buf_pool.page_hash. It is safe to do this, because we are
holding buf_pool.mutex.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants