Commit 84f796c9 authored by Pavlo Kushnir's avatar Pavlo Kushnir Committed by Sara Golemon

Add an option to disable guard pages for fiber stacks

Summary: guard pages may make debugging more painful. For example, in some cases they increased "perf" initialization time.

Reviewed By: @alikhtarov

Differential Revision: D2247188
parent 65fd92b6
......@@ -486,6 +486,7 @@ FiberManager::FiberManager(
std::unique_ptr<LoopController> loopController__,
Options options) :
loopController_(std::move(loopController__)),
stackAllocator_(options.useGuardPages),
options_(preprocessOptions(std::move(options))),
exceptionCallback_([](std::exception_ptr eptr, std::string context) {
try {
......
......@@ -84,6 +84,11 @@ class FiberManager : public ::folly::Executor {
*/
size_t maxFibersPoolSize{1000};
/**
* Protect limited amount of fiber stacks with guard pages.
*/
bool useGuardPages{true};
constexpr Options() {}
};
......
......@@ -194,11 +194,14 @@ class StackCacheEntry {
std::unique_ptr<StackCache> stackCache_;
};
GuardPageAllocator::GuardPageAllocator() = default;
GuardPageAllocator::GuardPageAllocator(bool useGuardPages)
: useGuardPages_(useGuardPages) {
}
GuardPageAllocator::~GuardPageAllocator() = default;
unsigned char* GuardPageAllocator::allocate(size_t size) {
if (!stackCache_) {
if (useGuardPages_ && !stackCache_) {
stackCache_ = CacheManager::instance().getStackCache(size);
}
......
......@@ -29,7 +29,11 @@ class StackCacheEntry;
*/
class GuardPageAllocator {
public:
GuardPageAllocator();
/**
* @param useGuardPages if true, protect limited amount of stacks with guard
* pages, otherwise acts as std::allocator.
*/
explicit GuardPageAllocator(bool useGuardPages);
~GuardPageAllocator();
/**
......@@ -45,6 +49,7 @@ class GuardPageAllocator {
private:
std::unique_ptr<StackCacheEntry> stackCache_;
std::allocator<unsigned char> fallbackAllocator_;
bool useGuardPages_{true};
};
}} // folly::fibers
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