Skip to content
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
merged 3 commits into from Mar 13, 2024

Conversation

blathers-crl[bot]
Copy link

@blathers-crl blathers-crl bot commented Mar 11, 2024

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.

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 blathers-crl bot requested a review from a team as a code owner March 11, 2024 20:06
@blathers-crl blathers-crl bot requested review from mgartner and removed request for a team March 11, 2024 20:06
@blathers-crl blathers-crl bot force-pushed the blathers/backport-release-23.1-119799 branch from bbd68b1 to b3fbd0c Compare March 11, 2024 20:06
@blathers-crl blathers-crl bot added blathers-backport This is a backport that Blathers created automatically. O-robot Originated from a bot. labels Mar 11, 2024
Copy link
Author

blathers-crl bot commented Mar 11, 2024

Thanks for opening a backport.

Please check the backport criteria before merging:

  • Backports should only be created for serious
    issues
    or test-only changes.
  • Backports should not break backwards-compatibility.
  • Backports should change as little code as possible.
  • Backports should not change on-disk formats or node communication protocols.
  • Backports should not add new functionality (except as defined
    here).
  • Backports must not add, edit, or otherwise modify cluster versions; or add version gates.
  • All backports must be reviewed by the owning areas TL and one additional
    TL. For more information as to how that review should be conducted, please consult the backport
    policy
    .
If your backport adds new functionality, please ensure that the following additional criteria are satisfied:
  • There is a high priority need for the functionality that cannot wait until the next release and is difficult to address in another way.
  • The new functionality is additive-only and only runs for clusters which have specifically “opted in” to it (e.g. by a cluster setting).
  • New code is protected by a conditional check that is trivial to verify and ensures that it only runs for opt-in clusters. State changes must be further protected such that nodes running old binaries will not be negatively impacted by the new state (with a mixed version test added).
  • The PM and TL on the team that owns the changed code have signed off that the change obeys the above rules.
  • Your backport must be accompanied by a post to the appropriate Slack
    channel (#db-backports-point-releases or #db-backports-XX-X-release) for awareness and discussion.

Also, please add a brief release justification to the body of your PR to justify this
backport.

@blathers-crl blathers-crl bot added the backport Label PR's that are backports to older release branches label Mar 11, 2024
@cockroach-teamcity
Copy link
Member

This change is Reviewable

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 yuzefovich force-pushed the blathers/backport-release-23.1-119799 branch from b3fbd0c to 97f36b9 Compare March 12, 2024 16:48
@yuzefovich yuzefovich merged commit e203c6a into release-23.1 Mar 13, 2024
5 of 6 checks passed
@yuzefovich yuzefovich deleted the blathers/backport-release-23.1-119799 branch March 13, 2024 16:25
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants