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

Add error messages when malloc allocator hits capacity limit #8075

Conversation

bikramSingh91
Copy link
Contributor

@bikramSingh91 bikramSingh91 commented Dec 15, 2023

Adds useful error messages when capacity limit is hit while
using MallocAllocator
Added a log line in the memory pool leak checking codepath
that would help attribute leaks to its respective query in
non-debug builds.

Test Plan:
Added unit tests

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 15, 2023
Copy link

netlify bot commented Dec 15, 2023

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit 35a7736
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/65833ae173dc4900084b3465

Copy link
Contributor

@xiaoxmeng xiaoxmeng left a comment

Choose a reason for hiding this comment

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

@bikramSingh91 thanks for the change!

velox/common/memory/MallocAllocator.cpp Show resolved Hide resolved
velox/common/memory/MallocAllocator.cpp Outdated Show resolved Hide resolved
velox/common/memory/MallocAllocator.cpp Outdated Show resolved Hide resolved
"total allocation of {} pages, the memory allocator capacity is {}",
mix.totalPages,
numPages,
succinctBytes(capacity_));
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want add a log with VELOX_MEM_LOG_EVERY_MS?
Also we could consider to add a static utility in MemoryAllocator::logAllocationError(const std::string& errMsg); It seems that have bee used in more than one places? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A few thoughts come to mind:

  1. It's possible to incorporate VELOX_MEM_LOG_EVERY_MS into setAllocatorFailureMessage, which could potentially eliminate the need for an additional function call.

  2. However, on second thought there are situations where logging every time is necessary, so this approach may not result in significant cleanup.
    (example

    VELOX_MEM_LOG(WARNING) << errorMsg;
    )

  3. Finally, adding VELOX_MEM_LOG_EVERY_MS inside a function would mean that it gets invoked everytime we log an error, so the 1000th iteration can be for any of those error messages and we might miss some (not sure if forcing an inline function can offset this).

what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it might be better not to log inside setAllocatorFailureMessage

@bikramSingh91 bikramSingh91 force-pushed the mallocAllocatorErrorMsgs branch from 808e9ef to c5fa308 Compare December 19, 2023 17:49
@facebook-github-bot
Copy link
Contributor

@bikramSingh91 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@xiaoxmeng xiaoxmeng left a comment

Choose a reason for hiding this comment

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

@bikramSingh91 thanks for the update!

"total allocation of {} pages, the memory allocator capacity is {}",
mix.totalPages,
numPages,
succinctBytes(capacity_));
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it might be better not to log inside setAllocatorFailureMessage

velox/common/memory/MallocAllocator.cpp Show resolved Hide resolved
velox/common/memory/MallocAllocator.cpp Show resolved Hide resolved
VELOX_MEM_LOG_EVERY_MS(WARNING, 1000)
<< "Failed to allocateBytes " << succinctBytes(bytes)
<< ": Exceeded memory allocator capacity limit of "
<< succinctBytes(capacity_);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to set allocation error message here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added and also added corresponding unit tests

velox/common/memory/MallocAllocator.cpp Outdated Show resolved Hide resolved
@bikramSingh91 bikramSingh91 force-pushed the mallocAllocatorErrorMsgs branch from c5fa308 to 6bfc987 Compare December 19, 2023 22:45
@facebook-github-bot
Copy link
Contributor

@bikramSingh91 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@xiaoxmeng xiaoxmeng left a comment

Choose a reason for hiding this comment

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

@bikramSingh91 LGTM. Thanks!

velox/common/memory/MallocAllocator.cpp Outdated Show resolved Hide resolved
velox/common/memory/MallocAllocator.cpp Outdated Show resolved Hide resolved
@@ -408,11 +408,13 @@ MemoryPoolImpl::~MemoryPoolImpl() {

if (isLeaf()) {
if (usedReservationBytes_ > 0) {
LOG(ERROR) << "Bad memory usage track state : " << toString();
Copy link
Contributor

Choose a reason for hiding this comment

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

How about?

Used memory leak: 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used this instead to make it consistent with the reserved memory leak message:

Memory leak (Used memory):

RECORD_METRIC_VALUE(
kMetricMemoryPoolUsageLeakBytes, usedReservationBytes_);
}

if (minReservationBytes_ > 0) {
LOG(ERROR) << "Bad memory usage track state : " << toString();
Copy link
Contributor

Choose a reason for hiding this comment

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

Memory reservation leak: 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used this instead to make it consistent with the used memory leak message:

Memory leak (Reserved memory):

@bikramSingh91 bikramSingh91 force-pushed the mallocAllocatorErrorMsgs branch from 6bfc987 to ecf95ca Compare December 20, 2023 18:26
@facebook-github-bot
Copy link
Contributor

@bikramSingh91 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Adds useful error messages when capacity limit is hit while
using MallocAllocator
Added a log line in the memory pool leak checking codepath
that would help attribute leaks to its respective query in
non-debug builds.

Test Plan:
Added unit tests
@bikramSingh91 bikramSingh91 force-pushed the mallocAllocatorErrorMsgs branch from ecf95ca to 35a7736 Compare December 20, 2023 19:05
@facebook-github-bot
Copy link
Contributor

@bikramSingh91 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@bikramSingh91 merged this pull request in 4ab8c0d.

Copy link

Conbench analyzed the 1 benchmark run on commit 4ab8c0d7.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants