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