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

[CORE] Update AllocationListener usage after successfully releasing memory #7396

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

wForget
Copy link
Member

@wForget wForget commented Sep 30, 2024

What changes were proposed in this pull request?

We should update AllocationListener usage after successfully releasing memory to avoid exceeding the usage limit.

How was this patch tested?

code refactor

@github-actions github-actions bot added the VELOX label Sep 30, 2024
Copy link

Thanks for opening a pull request!

Could you open an issue for this pull request on Github Issues?

https://github.com/apache/incubator-gluten/issues

Then could you also rename commit message and pull request title in the following format?

[GLUTEN-${ISSUES_ID}][COMPONENT]feat/fix: ${detailed message}

See also:

@wForget
Copy link
Member Author

wForget commented Sep 30, 2024

@zhztheplayer This is just a minor improvement I found while reading the relevant codes. Could you please take a quick look?

Comment on lines 52 to 62
int64_t diff = newSize - size;
updateUsage(diff);
if (diff > 0) {
updateUsage(diff);
}
bool succeed = delegated_->reallocate(p, size, newSize, out);
if (!succeed) {
if (succeed && diff < 0) {
updateUsage(diff);
} else if (!succeed && diff > 0) {
updateUsage(-diff);
}
return succeed;
Copy link
Member

Choose a reason for hiding this comment

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

Can we use two different code branches for diff > 0 and diff < 0 ? E.g.,

Suggested change
int64_t diff = newSize - size;
updateUsage(diff);
if (diff > 0) {
updateUsage(diff);
}
bool succeed = delegated_->reallocate(p, size, newSize, out);
if (!succeed) {
if (succeed && diff < 0) {
updateUsage(diff);
} else if (!succeed && diff > 0) {
updateUsage(-diff);
}
return succeed;
int64_t diff = newSize - size;
if (diff >= 0) {
updateUsage(diff);
bool succeeded = delegated_->reallocate(p, size, newSize, out);
if (!succeeded) {
updateUsage(-diff);
}
return succeeded;
}
// Code path for diff < 0.
bool succeeded = delegated_->reallocate(p, size, newSize, out);
if (succeeded) {
updateUsage(diff);
}
return succeed;

Copy link
Member

@zhztheplayer zhztheplayer left a comment

Choose a reason for hiding this comment

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

Just one minor comment. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants