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

MDEV-37244: Avoid page lookup after read #4213

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 4 commits into
base: 11.4
Choose a base branch
from
Draft

MDEV-37244: Avoid page lookup after read #4213

wants to merge 4 commits into from

Conversation

dr-m
Copy link
Contributor

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

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

Description

When the desired page is not in the buffer pool, we would invoke buf_read_page() and look up the page in buf_pool.page_hash. It is more efficient to let buf_read_page() to return a buffer-fixed block (or nullptr in case of a failure).

Release Notes

InnoDB performance was slightly improved in workloads that involve loading data into the buffer pool.

How can this PR be tested?

I observed a few per cent improvement in a Sysbench oltp_read_only benchmark where the active working set did not fit in the buffer pool. I also observed reduced resource usage, as reported by time(1).

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 that depends on some earlier refactoring d6aed21 and f27e9c8.

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 18, 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 3 commits July 21, 2025 09:47
The Microsoft Windows implementations of SRWLOCK and WaitOnAddress()
include some spin loop logic before entering the operating system kernel.
Let us avoid duplicating some of that spin loop logic.

Thanks to Vladislav Vaintroub for this fix.
While waiting for for I/O completion, let us skip spin loops.
Even on fast storage, reading a page into the buffer pool takes
so long that a spin loop would only end up wasting CPU time.

block_lock::s_lock_nospin(): A no-spin variant of acquiring a shared
buffer page latch. Regular s_lock() always involveis a spin loop.

ssux_lock_impl::rd_lock_spin(), ssux_lock_impl::rd_lock_nospin():
Split from rd_wait().

ssux_lock_impl::rd_lock(): Invoke either rd_lock_nospin() or
rd_lock_try() and rd_lock_spin().

buf_page_get_low(): After acquiring a page latch on an io-fixed block,
try to optimize operations on the page latch.
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 buffer-fixed, by acquiring 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 11.4-MDEV-37244 branch from a027160 to e29ad99 Compare July 21, 2025 07:35
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