Type:
Bug
Priority:
Major
Resolution:
Fixed
Affects Version/s:
10.5
The changes that were introduced in MDEV-15053 are sometimes causing severe performance loss when there is contention on buf_pool.page_hash . At the root we have the invocation of rw_lock_lock_word_decr(lock, 1, 0)) in rw_lock_s_lock_low() . That function is looping:
UNIV_INLINE
bool
rw_lock_lock_word_decr(
/*===================*/
rw_lock_t* lock, /*!< in/out: rw-lock */
int32_t amount, /*!< in: amount to decrement */
int32_t threshold) /*!< in: threshold of judgement */
{
int32_t lock_copy = lock->lock_word;
while (lock_copy > threshold) {
if (lock->lock_word.compare_exchange_strong(
lock_copy,
lock_copy - amount,
std::memory_order_acquire,
std::memory_order_relaxed)) {
return ( true );
}
( void ) LF_BACKOFF();
}
return ( false );
}
Note: the LF_BACKOFF() was added in an attempt to reduce the problem.
It feels strange that we are first loading lock_copy and then insisting that we will get an exact match on that lock_copy value. It seems that this could cause unnecessary contention between non-conflicting S-latch requests. The following naïve patch should alleviate that:
diff --git a/storage/innobase/include/sync0rw.ic b/storage/innobase/include/sync0rw.ic
index 18a6c69ece4..cec796c8892 100644
--- a/storage/innobase/include/sync0rw.ic
+++ b/storage/innobase/include/sync0rw.ic
@@ -209,20 +209,18 @@ rw_lock_lock_word_decr(
int32_t amount, /*!< in: amount to decrement */
int32_t threshold) /*!< in: threshold of judgement */
{
- int32_t lock_copy = lock->lock_word;
-
- while (lock_copy > threshold) {
- if (lock->lock_word.compare_exchange_strong(
- lock_copy,
- lock_copy - amount,
- std::memory_order_acquire,
- std::memory_order_relaxed)) {
+ for (;;)
+ {
+ int32_t lock_copy= lock->lock_word;
- return(true);
- }
- (void) LF_BACKOFF();
- }
- return(false);
+ if (lock_copy <= threshold)
+ return false;
+ if (lock->lock_word.compare_exchange_strong(lock_copy, lock_copy - amount,
+ std::memory_order_acquire,
+ std::memory_order_relaxed))
+ return true;
+ (void) LF_BACKOFF();
+ }
}
/******************************************************************//**
For even better results, we might want to rewrite the S-latch acquisition, as in the following incomplete patch . At least rw_lock_x_unlock_func() would have to be adjusted as well:
diff --git a/storage/innobase/include/sync0rw.ic b/storage/innobase/include/sync0rw.ic
index 18a6c69ece4..32ad6497a35 100644
--- a/storage/innobase/include/sync0rw.ic
+++ b/storage/innobase/include/sync0rw.ic
@@ -239,8 +239,9 @@ rw_lock_s_lock_low(
const char* file_name, /*!< in: file name where lock requested */
unsigned line) /*!< in: line where requested */
{
- if (!rw_lock_lock_word_decr(lock, 1, 0)) {
+ if (lock->lock_word.fetch_sub(1, std::memory_order_acquire) <= 0) {
/* Locking did not succeed */
+ lock->lock_word.fetch_add(1, std::memory_order_release);
return(FALSE);
}
Also, somewhat related to this, we might want to replace the rw_lock_s_lock(l) call in buf_pool_t::page_hash_lock() with a non-inlined function call, because that code is extremely unlikely to be executed, only when the buffer pool is being resized.
{"report":{"fcp":949.3000001907349,"ttfb":323.3999996185303,"pageVisibility":"visible","entityId":88139,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"7bfebbbe-a942-4872-bd59-05a54ef6064a","navigationType":0,"readyForUser":1045.5999994277954,"redirectCount":0,"resourceLoadedEnd":1379.6999998092651,"resourceLoadedStart":329.19999980926514,"resourceTiming":[{"duration":111.30000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":329.19999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":329.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":440.5,"responseStart":0,"secureConnectionStart":0},{"duration":111.30000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":329.5999994277954,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":329.5999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":440.8999996185303,"responseStart":0,"secureConnectionStart":0},{"duration":154.89999961853027,"initiatorType":"script","name":"https://jira.mariadb.org/s/e9b27a47da5fb0f74a35acd57e9847fb-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":329.80000019073486,"connectEnd":329.80000019073486,"connectStart":329.80000019073486,"domainLookupEnd":329.80000019073486,"domainLookupStart":329.80000019073486,"fetchStart":329.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":329.80000019073486,"responseEnd":484.69999980926514,"responseStart":484.69999980926514,"secureConnectionStart":329.80000019073486},{"duration":222.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/c32eb0da7ad9831253f8397e6cc26afd-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":329.8999996185303,"connectEnd":329.8999996185303,"connectStart":329.8999996185303,"domainLookupEnd":329.8999996185303,"domainLookupStart":329.8999996185303,"fetchStart":329.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":329.8999996185303,"responseEnd":552.6999998092651,"responseStart":552.6999998092651,"secureConnectionStart":329.8999996185303},{"duration":225.9000005722046,"initiatorType":"script","name":"https://jira.mariadb.org/s/bc0bcb146314416123c992714ee00ff7-CDN/lu2bv2/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":330.0999994277954,"connectEnd":330.0999994277954,"connectStart":330.0999994277954,"domainLookupEnd":330.0999994277954,"domainLookupStart":330.0999994277954,"fetchStart":330.0999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":330.0999994277954,"responseEnd":556,"responseStart":556,"secureConnectionStart":330.0999994277954},{"duration":226.10000038146973,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":330.3999996185303,"connectEnd":330.3999996185303,"connectStart":330.3999996185303,"domainLookupEnd":330.3999996185303,"domainLookupStart":330.3999996185303,"fetchStart":330.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":330.3999996185303,"responseEnd":556.5,"responseStart":556.5,"secureConnectionStart":330.3999996185303},{"duration":226.20000076293945,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":330.5999994277954,"connectEnd":330.5999994277954,"connectStart":330.5999994277954,"domainLookupEnd":330.5999994277954,"domainLookupStart":330.5999994277954,"fetchStart":330.5999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":330.5999994277954,"responseEnd":556.8000001907349,"responseStart":556.8000001907349,"secureConnectionStart":330.5999994277954},{"duration":301.1000003814697,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bv2/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":330.69999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":330.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":631.8000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":226.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":330.8999996185303,"connectEnd":330.8999996185303,"connectStart":330.8999996185303,"domainLookupEnd":330.8999996185303,"domainLookupStart":330.8999996185303,"fetchStart":330.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":330.8999996185303,"responseEnd":557.1999998092651,"responseStart":557.1999998092651,"secureConnectionStart":330.8999996185303},{"duration":300.8999996185303,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bv2/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":331,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":331,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":631.8999996185303,"responseStart":0,"secureConnectionStart":0},{"duration":226.60000038146973,"initiatorType":"script","name":"https://jira.mariadb.org/s/719848dd97ebe0663199f49a3936487a-CDN/lu2bv2/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":331.19999980926514,"connectEnd":331.19999980926514,"connectStart":331.19999980926514,"domainLookupEnd":331.19999980926514,"domainLookupStart":331.19999980926514,"fetchStart":331.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":331.19999980926514,"responseEnd":557.8000001907349,"responseStart":557.8000001907349,"secureConnectionStart":331.19999980926514},{"duration":438.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":332.3999996185303,"connectEnd":332.3999996185303,"connectStart":332.3999996185303,"domainLookupEnd":332.3999996185303,"domainLookupStart":332.3999996185303,"fetchStart":332.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":332.3999996185303,"responseEnd":771.1999998092651,"responseStart":771.1999998092651,"secureConnectionStart":332.3999996185303},{"duration":1020.5999994277954,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":337,"connectEnd":337,"connectStart":337,"domainLookupEnd":337,"domainLookupStart":337,"fetchStart":337,"redirectEnd":0,"redirectStart":0,"requestStart":337,"responseEnd":1357.5999994277954,"responseStart":1357.5999994277954,"secureConnectionStart":337},{"duration":157.5,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":658.0999994277954,"connectEnd":658.0999994277954,"connectStart":658.0999994277954,"domainLookupEnd":658.0999994277954,"domainLookupStart":658.0999994277954,"fetchStart":658.0999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":658.0999994277954,"responseEnd":815.5999994277954,"responseStart":815.5999994277954,"secureConnectionStart":658.0999994277954},{"duration":467.69999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2bv2/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/css/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":902.8000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":902.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1370.5,"responseStart":0,"secureConnectionStart":0},{"duration":464.29999923706055,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-project.issue.navigator,-jira.view.issue,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":903.8000001907349,"connectEnd":903.8000001907349,"connectStart":903.8000001907349,"domainLookupEnd":903.8000001907349,"domainLookupStart":903.8000001907349,"fetchStart":903.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":903.8000001907349,"responseEnd":1368.0999994277954,"responseStart":1368.0999994277954,"secureConnectionStart":903.8000001907349},{"duration":484.19999980926514,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":942.8000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":942.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1427,"responseStart":0,"secureConnectionStart":0},{"duration":475.3999996185303,"initiatorType":"script","name":"https://jira.mariadb.org/s/53a43b6764f587426c7bb9a150184c00-CDN/lu2bv2/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/js/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":904.3000001907349,"connectEnd":904.3000001907349,"connectStart":904.3000001907349,"domainLookupEnd":904.3000001907349,"domainLookupStart":904.3000001907349,"fetchStart":904.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":904.3000001907349,"responseEnd":1379.6999998092651,"responseStart":1379.6999998092651,"secureConnectionStart":904.3000001907349}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":138,"responseStart":323,"responseEnd":328,"domLoading":326,"domInteractive":1383,"domContentLoadedEventStart":1383,"domContentLoadedEventEnd":1426,"domComplete":2128,"loadEventStart":2128,"loadEventEnd":2130,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1359.3999996185303},{"name":"bigPipe.sidebar-id.end","time":1360.1999998092651},{"name":"bigPipe.activity-panel-pipe-id.start","time":1360.3999996185303},{"name":"bigPipe.activity-panel-pipe-id.end","time":1362.6999998092651},{"name":"activityTabFullyLoaded","time":1434.1999998092651}],"measures":[],"correlationId":"6d01616810dc8f","effectiveType":"4g","downlink":9.2,"rtt":0,"serverDuration":111,"dbReadsTimeInMs":18,"dbConnsTimeInMs":27,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}