From 887e92661872ec96aee7a689b91105a305ace73f Mon Sep 17 00:00:00 2001 From: Alessandro Vetere Date: Mon, 29 Jun 2026 19:51:28 +0200 Subject: [PATCH] MDEV-40210 Redundant CAS in async_flush_lsn::try_clear_if_at_most() 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. --- storage/innobase/buf/buf0flu.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/storage/innobase/buf/buf0flu.cc b/storage/innobase/buf/buf0flu.cc index f0ef7a43fc506..ca383f1720bea 100644 --- a/storage/innobase/buf/buf0flu.cc +++ b/storage/innobase/buf/buf0flu.cc @@ -93,6 +93,8 @@ class async_flush_lsn void try_clear_if_at_most(lsn_t threshold) noexcept { lsn_t snapshot= m_lsn.load(); + if (!snapshot) + return; /* already cleared: avoid a redundant atomic CAS */ if (threshold >= snapshot) m_lsn.compare_exchange_strong(snapshot, 0); }