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.1: sql: fix a couple of memory leaks around memory monitors #120242
Merged
yuzefovich
merged 3 commits into
release-23.1
from
blathers/backport-release-23.1-119799
Mar 13, 2024
Merged
release-23.1: sql: fix a couple of memory leaks around memory monitors #120242
yuzefovich
merged 3 commits into
release-23.1
from
blathers/backport-release-23.1-119799
Mar 13, 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 cleans up the txn fingerprint ID cache in the following manner: - it properly performs the memory accounting for each id. Previously, we didn't connect the account to actual monitor (it was uninitialized) and we only grew by 1 byte (which is significant underestimate). We now remove unused monitor and create an account bound to the session monitor. - we now only store the id in the "key" part of the cache entry (previously we stored it also in "value" which was redundant). The main motivation for this change was reducing the memory leak that is (hopefully) fixed in the following commit. Release note: None
This commit - hopefully - fixes a memory leak that we observed around memory monitors when many new connections are established. The leak became possible to occur when we linked parent-child monitors together in b6d04fd. In particular, in that commit we introduced a way for a parent to track all of its children that haven't been stopped. Whenever a connection is stopped (i.e. the connExecutor exits), we stop its memory monitors, including `session root` monitor. Stopping that monitor should remove it from the list of children of `sql` monitor. However, we observed that for some reason the `session root` monitors are kept alive. In [this](#119799 (comment)) comment I outlined a hypothesis that it's due to a problem with Go GC marking in the presence of cyclical references. This commit removes some of those references which - hopefully - should allow Go GC to clean up old connections' monitors. In particular, whenever a monitor is stopped we now: - lose the reference to the head of the list of children as well as break the references between children themselves. In an ideal world, all children monitors should've been stopped already, so this change would be a noop, but as seen by the fix in the previous commit we forget to stop some monitors occassionally, so this change would make the code more bullet-proof. - set its `reserved` budget to `noReserved`, losing a possible reference to another monitor. This change makes sense on its own too. Release note (bug fix): A slow memory leak that can accumulate when opening many new connections has been fixed. The bug is present in 22.2.9+ and 23.1+ versions.
blathers-crl
bot
force-pushed
the
blathers/backport-release-23.1-119799
branch
from
March 11, 2024 20:06
bbd68b1
to
b3fbd0c
Compare
blathers-crl
bot
added
blathers-backport
This is a backport that Blathers created automatically.
O-robot
Originated from a bot.
labels
Mar 11, 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
Mar 11, 2024
Previously, `index-backfiller-merger-mon` memory monitor that is connected to the long-living backfiller monitor was never closed. As a result, these index-backfiller monitors would accumulate in its parent leading to a slow memory leak. Release note: None
yuzefovich
force-pushed
the
blathers/backport-release-23.1-119799
branch
from
March 12, 2024 16:48
b3fbd0c
to
97f36b9
Compare
yuzefovich
approved these changes
Mar 13, 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 3/3 commits from #119799 on behalf of @yuzefovich.
/cc @cockroachdb/release
See individual commits for details.
Epic: None
Release note (bug fix): A slow memory leak that can accumulate when opening many new connections has been fixed. The bug is present in 22.2.9+ and 23.1+ versions.
Release justification: bug fix.