From: Pavlo Kushnir Date: Thu, 16 Jul 2015 04:06:29 +0000 (-0700) Subject: Add an option to disable guard pages for fiber stacks X-Git-Tag: v0.51.0~9 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=84f796c9b693f4e96fb035551848b6ce0859704d;p=folly.git 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 --- diff --git a/folly/experimental/fibers/FiberManager-inl.h b/folly/experimental/fibers/FiberManager-inl.h index dcf54634..5b57c855 100644 --- a/folly/experimental/fibers/FiberManager-inl.h +++ b/folly/experimental/fibers/FiberManager-inl.h @@ -486,6 +486,7 @@ FiberManager::FiberManager( std::unique_ptr loopController__, Options options) : loopController_(std::move(loopController__)), + stackAllocator_(options.useGuardPages), options_(preprocessOptions(std::move(options))), exceptionCallback_([](std::exception_ptr eptr, std::string context) { try { diff --git a/folly/experimental/fibers/FiberManager.h b/folly/experimental/fibers/FiberManager.h index bb7b500b..a29c6c2f 100644 --- a/folly/experimental/fibers/FiberManager.h +++ b/folly/experimental/fibers/FiberManager.h @@ -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() {} }; diff --git a/folly/experimental/fibers/GuardPageAllocator.cpp b/folly/experimental/fibers/GuardPageAllocator.cpp index 2d69a642..858968e4 100644 --- a/folly/experimental/fibers/GuardPageAllocator.cpp +++ b/folly/experimental/fibers/GuardPageAllocator.cpp @@ -194,11 +194,14 @@ class StackCacheEntry { std::unique_ptr 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); } diff --git a/folly/experimental/fibers/GuardPageAllocator.h b/folly/experimental/fibers/GuardPageAllocator.h index 38dfa0a5..e1c41fd3 100644 --- a/folly/experimental/fibers/GuardPageAllocator.h +++ b/folly/experimental/fibers/GuardPageAllocator.h @@ -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 stackCache_; std::allocator fallbackAllocator_; + bool useGuardPages_{true}; }; }} // folly::fibers