Increase fibers stack size if we're running with ASAN
authorStepan Palamarchuk <stepan@fb.com>
Fri, 8 May 2015 23:44:31 +0000 (16:44 -0700)
committerPraveen Kumar Ramakrishnan <praveenr@fb.com>
Tue, 12 May 2015 00:02:50 +0000 (17:02 -0700)
Summary:
In most cases user is not aware of ASAN and fiber stack problem, thus if the stackSize is specified we're not detecting ASAN and probably will crash.
And thus it doesn't seem like a good idea to make it a user responsibility to detect ASAN.

Test Plan: tests

Reviewed By: andrii@fb.com

Subscribers: alikhtarov, folly-diffs@, yfeldblum, chalfant

FB internal diff: D2058741

Tasks: 7016680

Signature: t1:2058741:1431131082:9a41eb40d756c9c7af0632f7ecd55c17d10bb189

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

index 793cf1fab534ad6dd78fa7583d1a386b675d330c..512d59eb7f2b365ad35d1cfe2c0b23f350c03d76 100644 (file)
 
 #include <cassert>
 
-#include <folly/Memory.h>
-#include <folly/Optional.h>
-#include <folly/Portability.h>
-#include <folly/ScopeGuard.h>
+#include <folly/CPortability.h>
 #include <folly/experimental/fibers/Baton.h>
 #include <folly/experimental/fibers/Fiber.h>
-#include <folly/experimental/fibers/Promise.h>
 #include <folly/experimental/fibers/LoopController.h>
+#include <folly/experimental/fibers/Promise.h>
 #include <folly/futures/Try.h>
+#include <folly/Memory.h>
+#include <folly/Optional.h>
+#include <folly/Portability.h>
+#include <folly/ScopeGuard.h>
 
 namespace folly { namespace fibers {
 
+namespace {
+
+inline FiberManager::Options preprocessOptions(FiberManager::Options opts) {
+#ifdef FOLLY_SANITIZE_ADDRESS
+  /* ASAN needs a lot of extra stack space.
+     16x is a conservative estimate, 8x also worked with tests
+     where it mattered.  Note that overallocating here does not necessarily
+     increase RSS, since unused memory is pretty much free. */
+  opts.stackSize *= 16;
+#endif
+  return opts;
+}
+
+}  // anonymous
+
 inline void FiberManager::ensureLoopScheduled() {
   if (isLoopScheduled_) {
     return;
@@ -441,7 +457,7 @@ FiberManager::FiberManager(
   std::unique_ptr<LoopController> loopController__,
   Options options)  :
     loopController_(std::move(loopController__)),
-    options_(std::move(options)),
+    options_(preprocessOptions(std::move(options))),
     exceptionCallback_([](std::exception_ptr eptr, std::string context) {
         try {
           std::rethrow_exception(eptr);
index 8ce9fc3422ae66a75d9af4d3232831c9721488a8..468a06da8b955475461019e5a1a52ad732201fdd 100644 (file)
@@ -61,15 +61,8 @@ class LocalType {
 class FiberManager : public ::folly::Executor {
  public:
   struct Options {
-#ifdef FOLLY_SANITIZE_ADDRESS
-    /* ASAN needs a lot of extra stack space.
-       16x is a conservative estimate, 8x also worked with tests
-       where it mattered.  Note that overallocating here does not necessarily
-       increase RSS, since unused memory is pretty much free. */
-    static constexpr size_t kDefaultStackSize{16 * 16 * 1024};
-#else
     static constexpr size_t kDefaultStackSize{16 * 1024};
-#endif
+
     /**
      * Maximum stack size for fibers which will be used for executing all the
      * tasks.