Skip to content

MDEV-40210 Redundant CAS in async_flush_lsn::try_clear_if_at_most()#5300

Open
iMineLink wants to merge 1 commit into
11.8from
MDEV-40210
Open

MDEV-40210 Redundant CAS in async_flush_lsn::try_clear_if_at_most()#5300
iMineLink wants to merge 1 commit into
11.8from
MDEV-40210

Conversation

@iMineLink

Copy link
Copy Markdown
Contributor

MDEV-39600 added try_clear_if_at_most() to clear buf_flush_async_lsn with an atomic CAS that preserves a concurrent bump(). If the snapshot is already 0, compare_exchange_strong(0, 0) is a no-op, so return early on a zero snapshot and avoid the atomic read-modify-write. The page cleaner calls this on every pass, so in the common steady state (no async flush queued) it drops needless exclusive access to the m_lsn cache line. A zero value is already the cleared state and a concurrent bump() is preserved either way, so the result is identical.

@iMineLink iMineLink requested review from Copilot and dr-m June 29, 2026 17:54
@CLAassistant

Copy link
Copy Markdown

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an optimization in storage/innobase/buf/buf0flu.cc within the async_flush_lsn::try_clear_if_at_most function. It adds a check to return early if the snapshot is already zero, thereby avoiding a redundant atomic compare-and-swap (CAS) operation. There are no review comments, and we have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes InnoDB’s page-cleaner hot path by avoiding a redundant atomic read-modify-write when the async flush LSN is already in the cleared state (0), preserving the same concurrency semantics while reducing cache-line contention.

Changes:

  • Add an early return in async_flush_lsn::try_clear_if_at_most() when the snapshotted LSN is 0 to skip a no-op CAS.
  • Reduce unnecessary exclusive access to the m_lsn cache line during steady-state page-cleaner passes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dr-m dr-m left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a trivial fixup to #5078. An added conditional branch should incur a much smaller worst-case overhead than an atomic compare-and-swap.

MDEV-39600 added try_clear_if_at_most() to clear buf_flush_async_lsn with
an atomic CAS that preserves a concurrent bump(). If the snapshot is
already 0, compare_exchange_strong(0, 0) is a no-op, so return early on a
zero snapshot and avoid the atomic read-modify-write. The page cleaner
calls this on every pass, so in the common steady state (no async flush
queued) it drops needless exclusive access to the m_lsn cache line. A zero
value is already the cleared state and a concurrent bump() is preserved
either way, so the result is identical.
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.

4 participants