Commit 20d52e14 authored by Jon Maltiel Swenson's avatar Jon Maltiel Swenson Committed by Facebook Github Bot

Handle EINVAL errno in MemoryIdler::unmapUnusedStack()

Summary:
If `MemoryIdler` is used with threads that are backed by huge pages, the
`madvise(..., MADV_DONTNEED)` calls will fail with an `EINVAL`. Prior to this
diff, this would lead to an assertion failure. Now, if `EINVAL` is returned, we
warn the user, as `MemoryIdler` may not be able to function as expected.

Reviewed By: yfeldblum

Differential Revision: D8669399

fbshipit-source-id: f97ea7549deffdbf283b3516b9e8feafe18a036c
parent aeeb73ac
......@@ -183,10 +183,14 @@ void MemoryIdler::unmapUnusedStack(size_t retain) {
if (madvise((void*)tls_stackLimit, len, MADV_DONTNEED) != 0) {
// It is likely that the stack vma hasn't been fully grown. In this
// case madvise will apply dontneed to the present vmas, then return
// errno of ENOMEM. We can also get an EAGAIN, theoretically.
// EINVAL means either an invalid alignment or length, or that some
// of the pages are locked or shared. Neither should occur.
assert(errno == EAGAIN || errno == ENOMEM);
// errno of ENOMEM.
// If thread stack pages are backed by locked or huge pages, madvise will
// fail with EINVAL. (EINVAL may also be returned if the address or length
// are bad.) Warn in debug mode, since MemoryIdler may not function as
// expected.
// We can also get an EAGAIN, theoretically.
PLOG_IF(WARNING, kIsDebug && errno == EINVAL) << "madvise failed";
assert(errno == EAGAIN || errno == ENOMEM || errno == EINVAL);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment