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

Released memory retained by ExchangeSource #11097

Merged
merged 1 commit into from
Feb 22, 2022

Conversation

arhimondr
Copy link
Contributor

Description

Avoid retaining memory used by ExchangeSource more than necessary

Is this change a fix, improvement, new feature, refactoring, or other?

Improvement

Is this a change to the core query engine, a connector, client library, or the SPI interfaces? (be specific)

Core engine

How would you describe this change to a non-technical end user or system administrator?

Non user visible improvement

Related issues, pull requests, and links

Documentation

(x) No documentation is needed.
( ) Sufficient documentation is included in this PR.
( ) Documentation PR is available with #prnumber.
( ) Documentation issue #issuenumber is filed, and can be handled later.

Release notes

(x) No release notes entries required.
( ) Release notes entries required with the following suggested text:

Comment on lines +496 to +499
// If the data source has been closed in a meantime reset memory usage back to 0
if (closed) {
systemMemoryContext.setBytes(0);
}
Copy link
Member

Choose a reason for hiding this comment

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

Why is this check needed? systemMemoryContext.setBytes(0); will always be executed in the finally block of close(), right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but pollPage and close can be called concurrently. It is possible that close will set the memory reservation to 0 while the pollPage will reset it back to a non zero value

@losipiuk
Copy link
Member

Typo in commit message "Released" -> "Release"

// It is modified (assigned to null) when the ExchangeOperator is closed.
// It doesn't have to be declared as volatile as the nullification of this variable doesn't have to be immediately visible to other threads.
// However since close can be called at any moment this variable has to be accessed in a safe way (avoiding "check-then-use").
private ExchangeSource exchangeSource;
Copy link
Member

Choose a reason for hiding this comment

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

There two separate issues here. One improving GC and another is ensuring memory pool accounting is fine. It would be nice to have separated commits for them.

@arhimondr arhimondr force-pushed the nullify-exchange-source branch from b7d7dda to d023e5b Compare February 21, 2022 22:56
@losipiuk
Copy link
Member

CI: #11140

@losipiuk
Copy link
Member

CI: #4936

@losipiuk losipiuk merged commit ae713b7 into trinodb:master Feb 22, 2022
@github-actions github-actions bot added this to the 372 milestone Feb 22, 2022
@arhimondr arhimondr deleted the nullify-exchange-source branch February 22, 2022 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants