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

util/log: ensure that secondary loggers do not leak memory #41231

Merged
merged 1 commit into from
Oct 1, 2019

Conversation

knz
Copy link
Contributor

@knz knz commented Oct 1, 2019

Fixes #41230.

Note: the primary cause of this issue is removed by #40993 but that PR is blocked until 19.2 is out. I'm cherry-picking the subset of those changes sufficient to solve issue #41230, here.

Prior to this patch, logging via a secondary logger would allocate a
buffer, then add it to the buffer free list of the secondary logger.

This was causing a memory leak because only the free list from the
main logger is used to allocate buffers (even in secondary loggers),
so all the now-unused buffers from secondary logs would remain unused
and accumulate, locked from Go's GC attention because they are
referenced somewhere.

Release justification: bug fix

Release note (bug fix): A memory leak was fixed that affected
secondary logging (SQL audit logs, statement execution, and RocksDB
logging).

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@petermattis petermattis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

I wonder if this change should make getBuffer and putBuffer globals, instead of methods on loggerT. That would ensure you didn't miss any wrong uses. Those methods could still use the logging global, or you could move freeList{,Mu} out of loggingT as well.

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @nvanbenschoten and @petermattis)

@nvanbenschoten
Copy link
Member

or you could move freeList{,Mu} out of loggingT as well

this is my preferred solution. Is there a reason not to do this?

@knz
Copy link
Contributor Author

knz commented Oct 1, 2019

this is my preferred solution. Is there a reason not to do this?

Because it's redundant work with #40993. WDYT?

@knz
Copy link
Contributor Author

knz commented Oct 1, 2019

oh well I'll change it anyway it's not so much work

Prior to this patch, logging via a secondary logger would allocate a
buffer, then add it to the buffer free list of the secondary logger.

This was causing a memory leak because only the free list from the
main logger is used to allocate buffers (even in secondary loggers),
so all the now-unused buffers from secondary logs would remain unused
and accumulate, locked from Go's GC attention because they are
referenced somewhere.

Release justification: bug fix

Release note (bug fix): A memory leak was fixed that affected
secondary logging (SQL audit logs, statement execution, and RocksDB
logging).
@knz
Copy link
Contributor Author

knz commented Oct 1, 2019

you could move freeList{,Mu} out of loggingT as well

done

@knz
Copy link
Contributor Author

knz commented Oct 1, 2019

bors r=petermattis,nvanbenschoten

craig bot pushed a commit that referenced this pull request Oct 1, 2019
41220: sql: move histogram decoding into the stats cache r=RaduBerinde a=RaduBerinde

Currently the stats cache exposes the encoded histogram data, and the
opt catalog decodes it. The problem is that opt catalog objects are
not shared across connections so this is inefficient (especially in
memory usage).

This change moves the decoding into the stats cache. The opt catalog
objects now simply point to the data computed by the cache.

There are still inefficiencies to improve on in the future: the opt
catalog can hold on to multiple versions of tables, so we will keep
many versions of histograms "alive".

Informs #41206.
Informs #40922.

Release justification: fix for new functionality.

Release note: None

41231: util/log: ensure that secondary loggers do not leak memory r=petermattis,nvanbenschoten a=knz

Fixes #41230.

Note: the primary cause of this issue is removed by #40993 but that PR is blocked until 19.2 is out. I'm cherry-picking the subset of those changes sufficient to solve issue #41230, here.

Prior to this patch, logging via a secondary logger would allocate a
buffer, then add it to the buffer free list of the secondary logger.

This was causing a memory leak because only the free list from the
main logger is used to allocate buffers (even in secondary loggers),
so all the now-unused buffers from secondary logs would remain unused
and accumulate, locked from Go's GC attention because they are
referenced somewhere.

Release justification: bug fix

Release note (bug fix): A memory leak was fixed that affected
secondary logging (SQL audit logs, statement execution, and RocksDB
logging).

Co-authored-by: Radu Berinde <radu@cockroachlabs.com>
Co-authored-by: Raphael 'kena' Poss <knz@thaumogen.net>
Copy link
Member

@nvanbenschoten nvanbenschoten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @nvanbenschoten)

@craig
Copy link
Contributor

craig bot commented Oct 1, 2019

Build succeeded

@craig craig bot merged commit ab74a33 into cockroachdb:master Oct 1, 2019
craig bot pushed a commit that referenced this pull request Oct 17, 2019
40993: util/log: refactor and bug fixes r=knz a=knz

Fixes #40983.
Fixes #40973.
Fixes #40974.
Fixes #41231.

I might also want to add code to clean up #40972, #40982 and #40990 provided I receive some guidance from @tbg or someone familiar with the log package.


41654: parser: fix telemetry link for materialized views r=jordanlewis a=jordanlewis

This commit fixes the error message that you get if you try to create a
materialized view to point at the right GitHub issue.

Release note: None

Co-authored-by: Raphael 'kena' Poss <knz@thaumogen.net>
Co-authored-by: Jordan Lewis <jordanthelewis@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

log: log buffers are not released into the free list
4 participants