-
Notifications
You must be signed in to change notification settings - Fork 425
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
base: main
Are you sure you want to change the base?
Conversation
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?
See also: |
@zhztheplayer This is just a minor improvement I found while reading the relevant codes. Could you please take a quick look? |
cpp/core/memory/MemoryAllocator.cc
Outdated
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; |
There was a problem hiding this comment.
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.,
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, changed
There was a problem hiding this 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!
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