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-2.1: storage: clear *cmd references in cmdQ buffers before re-use #42961

Merged

Conversation

nvanbenschoten
Copy link
Member

This PR contains two commits that attempt to avoid indefinitely retaining references to large graphs of *cmd objects in the CommandQueue and preventing them from being GCed.

storage: don't let cmdQ buffers grow without bound

This commit places a limit on the size of the overlaps buffer than the CommandQueue uses to avoid repeat allocations in getOverlaps. It's risky to allow this buffer to grow without bounds and never be reclaimed.

storage: clear *cmd references in cmdQ buffers before re-use

This commit ensures that the *cmd references in the overlaps buffer that the CommandQueue uses to avoid repeat allocations are cleared after use. This prevents the buffer from accidentally holding references to *cmd objects and preventing them from being GCed.

This commit places a limit on the size of the overlaps buffer than the
CommandQueue uses to avoid repeat allocations in getOverlaps. It's risky
to allow this buffer to grow without bounds and never be reclaimed.

Release note (bug fix): The CommandQueue no longer holds on to buffers
if they grow to large. This prevents unbounded growth of memory that
may never be reclaimed.
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 1 files at r1, 1 of 1 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @nvanbenschoten)


pkg/storage/command_queue.go, line 440 at r2 (raw file):

		if restart {
			// Clear all *cmd references in overlaps, per the getOverlaps contract.
			for i := range overlaps {

nit: the shadowing of i here is a tad confusing.

This commit ensures that the *cmd references in the overlaps buffer that
the CommandQueue uses to avoid repeat allocations are cleared after use.
This prevents the buffer from accidentally holding references to *cmd
objects and preventing them from being GCed.

Release note (bug fix): The CommandQueue makes sure to clear references
to objects in its buffers to allow those objects to be reclaimed by the
garbage collector.
@nvanbenschoten nvanbenschoten force-pushed the nvanbenschoten/cmdQLeak branch from c94f572 to 315781d Compare December 4, 2019 22:01
Copy link
Member Author

@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.

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


pkg/storage/command_queue.go, line 440 at r2 (raw file):

Previously, ajwerner wrote…

nit: the shadowing of i here is a tad confusing.

Agreed. Done.

@nvanbenschoten nvanbenschoten merged commit 9ad9eb5 into cockroachdb:release-2.1 Dec 4, 2019
@nvanbenschoten nvanbenschoten deleted the nvanbenschoten/cmdQLeak branch December 4, 2019 23:17
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.

3 participants