-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
release-23.2: sql: fix leak in memory accounting around TxnFingerprintIDCache #121950
Merged
yuzefovich
merged 1 commit into
release-23.2
from
blathers/backport-release-23.2-121875
Apr 10, 2024
Merged
release-23.2: sql: fix leak in memory accounting around TxnFingerprintIDCache #121950
yuzefovich
merged 1 commit into
release-23.2
from
blathers/backport-release-23.2-121875
Apr 10, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit is partial revert of 88ebd70. Until that change, we attempted to perform memory accounting for txn fingeprint IDs stored in the cache for each session, but we never initialized the bytes monitor, so it didn't actually count towards the root SQL memory budget. In that change, we derived an account from the "session" monitor to fix that. However, this exposed another problem with how accounting was done: namely, on `Cache.Add` call we always grow the account and on `Cache.OnEvicted` we shrink the account. The problem is that if the txn fingerprint ID already exists in the cache, we still call `Cache.Add` (growing the account) but we will never shrink it because we didn't add a new entry. As a result, until the session is closed, we'll keep on accumulating the leak. The fix in this commit is simple - just remove any attempt for memory accounting for this txn fingerprint ID cache. Effectively, this brings us back to the state of how we were before the change mentioned above (no accounting done) without the overhead of creating redundant BytesMonitor / BoundAccount objects (since they served no real purpose). Not having any accounting done for this cache seems acceptable given that the cache stores up to 100 txns (by default), and each txn results in about 56B of usage, so we'll have about 5KiB of unaccounted for (per session) memory usage. We have much larger omissions elsewhere, so for now I left a TODO to add memory accounting in the future. Release note (bug fix): CockroachDB could previously "leak" reported memory usage (as accounted by the internal memory accounting system, the limit for which is configured via --max-sql-memory flag) on long-running sessions that issue many (hundreds of thousands or more) transactions. This, in turn, could result in "root: memory budget exceeded" errors for other queries. The bug is present in versions 23.1.17 and 23.2.3 and is now fixed.
blathers-crl
bot
force-pushed
the
blathers/backport-release-23.2-121875
branch
from
April 8, 2024 18:05
7adc311
to
cce8d30
Compare
blathers-crl
bot
added
blathers-backport
This is a backport that Blathers created automatically.
O-robot
Originated from a bot.
labels
Apr 8, 2024
Thanks for opening a backport. Please check the backport criteria before merging:
If your backport adds new functionality, please ensure that the following additional criteria are satisfied:
Also, please add a brief release justification to the body of your PR to justify this |
blathers-crl
bot
added
the
backport
Label PR's that are backports to older release branches
label
Apr 8, 2024
yuzefovich
changed the title
release-23.2: release-23.2.4-rc: sql: fix leak in memory accounting around TxnFingerprintIDCache
release-23.2: sql: fix leak in memory accounting around TxnFingerprintIDCache
Apr 8, 2024
mgartner
approved these changes
Apr 10, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
backport
Label PR's that are backports to older release branches
blathers-backport
This is a backport that Blathers created automatically.
O-robot
Originated from a bot.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport 1/1 commits from #121875 on behalf of @yuzefovich.
/cc @cockroachdb/release
Backport 1/1 commits from #121847.
/cc @cockroachdb/release
This commit is partial revert of 88ebd70. Until that change, we attempted to perform memory accounting for txn fingeprint IDs stored in the cache for each session, but we never initialized the bytes monitor, so it didn't actually count towards the root SQL memory budget. In that change, we derived an account from the "session" monitor to fix that.
However, this exposed another problem with how accounting was done: namely, on
Cache.Add
call we always grow the account and onCache.OnEvicted
we shrink the account. The problem is that if the txn fingerprint ID already exists in the cache, we still callCache.Add
(growing the account) but we will never shrink it because we didn't add a new entry. As a result, until the session is closed, we'll keep on accumulating the leak.The fix in this commit is simple - just remove any attempt for memory accounting for this txn fingerprint ID cache. Effectively, this brings us back to the state of how we were before the change mentioned above (no accounting done) without the overhead of creating redundant BytesMonitor / BoundAccount objects (since they served no real purpose). Not having any accounting done for this cache seems acceptable given that the cache stores up to 100 txns (by default), and each txn results in about 56B of usage, so we'll have about 5KiB of unaccounted for (per session) memory usage. We have much larger omissions elsewhere, so for now I left a TODO to add memory accounting in the future.
Addresses: #121844.
Epic: None
Release note (bug fix): CockroachDB could previously "leak" reported memory usage (as accounted by the internal memory accounting system, the limit for which is configured via --max-sql-memory flag) on long-running sessions that issue many (hundreds of thousands or more) transactions. This, in turn, could result in "root: memory budget exceeded" errors for other queries. The bug is present in versions 23.1.17 and 23.2.3 and is now fixed.
Release justification: bug fix to a recent regression.