This was a rather surprising find while profiling.
mtr_t::mtr_t allocates memory through construction of one of its members
This allocations accounts for 0.68% of CPU time (constructor itself for 0.77% of CPU time), this happens to be the largest contributor to the "operator new" on oltp_update_index benchmark with bufferpool larger than size of the data ( without doublewrite)
This might be due to the m_freed_ranges that MDEV-8139 added, or this is an older regression.
In any case, we may want to introduce a separate object for read-only operations, and possibly we could avoid creating a mtr_t at all when an operation is only reading a small number of pages and could take care of releasing the page latches manually. For read-only operations, mtr_t::m_log and mtr_t::m_freed_ranges are totally unnecessary.
For 10.6, I have been thinking of replacing both mtr_t::m_log and mtr_t::m_memo with something like a std::unordered_map that maps buf_block_t* to log record snippets.
Marko Mäkelä
added a comment - This might be due to the m_freed_ranges that MDEV-8139 added, or this is an older regression.
In any case, we may want to introduce a separate object for read-only operations, and possibly we could avoid creating a mtr_t at all when an operation is only reading a small number of pages and could take care of releasing the page latches manually. For read-only operations, mtr_t::m_log and mtr_t::m_freed_ranges are totally unnecessary.
For 10.6, I have been thinking of replacing both mtr_t::m_log and mtr_t::m_memo with something like a std::unordered_map that maps buf_block_t* to log record snippets.
I think that the simplest fix is to add pointer indirection for m_freed_ranges, add an initializer expression = nullptr and allocate the object on demand. It should be very rare that a mini-transaction is freeing data pages.
We can probably assume (and assert) that when the object is allocated, it will always be nonempty.
Can a mini-transaction ever allocate a page that it has just freed? I do not see any debug assertion or handling of that. Could a debug assertion be added to mtr_t::init() that the page was not marked as freed?
Also, while fixing this, m_freed_ranges could be renamed to m_freed_pages, which is (almost) what the comment of mtr_t::add_freed_offset() is referring to.
Marko Mäkelä
added a comment - I think that the simplest fix is to add pointer indirection for m_freed_ranges , add an initializer expression = nullptr and allocate the object on demand. It should be very rare that a mini-transaction is freeing data pages.
We can probably assume (and assert) that when the object is allocated, it will always be nonempty.
Can a mini-transaction ever allocate a page that it has just freed? I do not see any debug assertion or handling of that. Could a debug assertion be added to mtr_t::init() that the page was not marked as freed?
Also, while fixing this, m_freed_ranges could be renamed to m_freed_pages , which is (almost) what the comment of mtr_t::add_freed_offset() is referring to.
Eugene Kosov (Inactive)
added a comment - Standard doesn't forbid allocating in default ctor. And Microsoft STL does so https://github.com/microsoft/STL/blob/master/stl/inc/xtree#L886 What a 'nice' implementation detail
IMO, we should stick to std::unique_ptr<std::set>
I think that we can simply use pointer indirection, and only call delete in mtr_t::commit(). In that way, we can use memory leaks to our advantage in debugging. A missing call to mtr_t::commit() could then lead to an ASAN failure. If we used std::unique_ptr, such omissions would not lead to ASAN-reported leaks, but instead to difficult-to-find server hangs (when the page latches for the mini-transaction are never released).
Marko Mäkelä
added a comment - I think that we can simply use pointer indirection, and only call delete in mtr_t::commit() . In that way, we can use memory leaks to our advantage in debugging. A missing call to mtr_t::commit() could then lead to an ASAN failure. If we used std::unique_ptr , such omissions would not lead to ASAN-reported leaks, but instead to difficult-to-find server hangs (when the page latches for the mini-transaction are never released).
origin/bb-10.5-thiru 0a3c6585257f988e1fbf01a2d51284043a5ab7a6 2020-06-19T15:57:36+05:30
containing the code of MDEV-22931 behaved well during the RQG test battery for broad
range functional coverage.
Matthias Leich
added a comment - origin/bb-10.5-thiru 0a3c6585257f988e1fbf01a2d51284043a5ab7a6 2020-06-19T15:57:36+05:30
containing the code of MDEV-22931 behaved well during the RQG test battery for broad
range functional coverage.
People
Thirunarayanan Balathandayuthapani
Vladislav Vaintroub
Votes:
0Vote for this issue
Watchers:
4Start watching this issue
Dates
Created:
Updated:
Resolved:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":1624.6000001430511,"ttfb":422.10000014305115,"pageVisibility":"visible","entityId":88482,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"18ae3030-1587-4e3a-8da6-9c463aa67c1c","navigationType":0,"readyForUser":1695,"redirectCount":0,"resourceLoadedEnd":1334.4000000953674,"resourceLoadedStart":434.10000014305115,"resourceTiming":[{"duration":160.19999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":434.10000014305115,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":434.10000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":594.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":160.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/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&whisper-enabled=true","startTime":434.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":434.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":595,"responseStart":0,"secureConnectionStart":0},{"duration":656.2000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":434.7999999523163,"connectEnd":434.7999999523163,"connectStart":434.7999999523163,"domainLookupEnd":434.7999999523163,"domainLookupStart":434.7999999523163,"fetchStart":434.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":628,"responseEnd":1091,"responseStart":687.5,"secureConnectionStart":434.7999999523163},{"duration":897.7999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/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&whisper-enabled=true","startTime":435.7000000476837,"connectEnd":435.7000000476837,"connectStart":435.7000000476837,"domainLookupEnd":435.7000000476837,"domainLookupStart":435.7000000476837,"fetchStart":435.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":626,"responseEnd":1333.5,"responseStart":641.7999999523163,"secureConnectionStart":435.7000000476837},{"duration":280.89999985694885,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":435.90000009536743,"connectEnd":435.90000009536743,"connectStart":435.90000009536743,"domainLookupEnd":435.90000009536743,"domainLookupStart":435.90000009536743,"fetchStart":435.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":637.2999999523163,"responseEnd":716.7999999523163,"responseStart":701.2000000476837,"secureConnectionStart":435.90000009536743},{"duration":284.90000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":436,"connectEnd":436,"connectStart":436,"domainLookupEnd":436,"domainLookupStart":436,"fetchStart":436,"redirectEnd":0,"redirectStart":0,"requestStart":641.1000001430511,"responseEnd":720.9000000953674,"responseStart":718.7999999523163,"secureConnectionStart":436},{"duration":281.2999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":436.2000000476837,"connectEnd":436.2000000476837,"connectStart":436.2000000476837,"domainLookupEnd":436.2000000476837,"domainLookupStart":436.2000000476837,"fetchStart":436.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":637.7999999523163,"responseEnd":717.5,"responseStart":707.6000001430511,"secureConnectionStart":436.2000000476837},{"duration":161.89999985694885,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":436.40000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":436.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":598.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":284.7000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":436.5,"connectEnd":436.5,"connectStart":436.5,"domainLookupEnd":436.5,"domainLookupStart":436.5,"fetchStart":436.5,"redirectEnd":0,"redirectStart":0,"requestStart":641.4000000953674,"responseEnd":721.2000000476837,"responseStart":719.2999999523163,"secureConnectionStart":436.5},{"duration":163.79999995231628,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/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":436.7000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":436.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":600.5,"responseStart":0,"secureConnectionStart":0},{"duration":286.2000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/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":437,"connectEnd":437,"connectStart":437,"domainLookupEnd":437,"domainLookupStart":437,"fetchStart":437,"redirectEnd":0,"redirectStart":0,"requestStart":641.5,"responseEnd":723.2000000476837,"responseStart":721.5,"secureConnectionStart":437},{"duration":894.2000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":438.90000009536743,"connectEnd":438.90000009536743,"connectStart":438.90000009536743,"domainLookupEnd":438.90000009536743,"domainLookupStart":438.90000009536743,"fetchStart":438.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":1131.1000001430511,"responseEnd":1333.1000001430511,"responseStart":1326.6000001430511,"secureConnectionStart":438.90000009536743},{"duration":895.4000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":439,"connectEnd":439,"connectStart":439,"domainLookupEnd":439,"domainLookupStart":439,"fetchStart":439,"redirectEnd":0,"redirectStart":0,"requestStart":1131.4000000953674,"responseEnd":1334.4000000953674,"responseStart":1328.7999999523163,"secureConnectionStart":439},{"duration":314.80000019073486,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1249.2999999523163,"connectEnd":1249.2999999523163,"connectStart":1249.2999999523163,"domainLookupEnd":1249.2999999523163,"domainLookupStart":1249.2999999523163,"fetchStart":1249.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":1528.1000001430511,"responseEnd":1564.1000001430511,"responseStart":1562.7999999523163,"secureConnectionStart":1249.2999999523163}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":256,"responseStart":422,"responseEnd":436,"domLoading":425,"domInteractive":1774,"domContentLoadedEventStart":1774,"domContentLoadedEventEnd":1825,"domComplete":2402,"loadEventStart":2402,"loadEventEnd":2402,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1733.7000000476837},{"name":"bigPipe.sidebar-id.end","time":1734.4000000953674},{"name":"bigPipe.activity-panel-pipe-id.start","time":1734.6000001430511},{"name":"bigPipe.activity-panel-pipe-id.end","time":1736.7999999523163},{"name":"activityTabFullyLoaded","time":1850.4000000953674}],"measures":[],"correlationId":"15c8989f8ce916","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":100,"dbReadsTimeInMs":14,"dbConnsTimeInMs":23,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
This might be due to the m_freed_ranges that
MDEV-8139added, or this is an older regression.In any case, we may want to introduce a separate object for read-only operations, and possibly we could avoid creating a mtr_t at all when an operation is only reading a small number of pages and could take care of releasing the page latches manually. For read-only operations, mtr_t::m_log and mtr_t::m_freed_ranges are totally unnecessary.
For 10.6, I have been thinking of replacing both mtr_t::m_log and mtr_t::m_memo with something like a std::unordered_map that maps buf_block_t* to log record snippets.