Add an option to disable guard pages for fiber stacks
authorPavlo Kushnir <pavlo@fb.com>
Thu, 16 Jul 2015 04:06:29 +0000 (21:06 -0700)
committerSara Golemon <sgolemon@fb.com>
Mon, 20 Jul 2015 19:26:30 +0000 (12:26 -0700)
Summary: guard pages may make debugging more painful. For example, in some cases they increased "perf" initialization time.

Reviewed By: @alikhtarov

Differential Revision: D2247188

folly/experimental/fibers/FiberManager-inl.h
folly/experimental/fibers/FiberManager.h
folly/experimental/fibers/GuardPageAllocator.cpp
folly/experimental/fibers/GuardPageAllocator.h

index dcf54634321b6c6913bfa65fc996bc013f304d13..5b57c8552f22e4a688955e846019aed53a0de096 100644 (file)
@@ -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 {
index bb7b500bb6dd0d33c6bc06e473b48af5978db794..a29c6c2f56069fcaa6a1393cc3d1cf7553b0fe4a 100644 (file)
@@ -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() {}
   };
 
index 2d69a6427bdf963aa638108ab225dd7e01c6d0f4..858968e47731d741315a90b2e06c9ad4984d5d1a 100644 (file)
@@ -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);
   }
 
index 38dfa0a528b485fe0fc1d5ce03ea56175ccd77a3..e1c41fd37b49f489e4d2f90198e497a69f0b0f52 100644 (file)
@@ -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