From 8232c2cd35be2479278d9081c81b909dc14a37e6 Mon Sep 17 00:00:00 2001 From: Stepan Palamarchuk Date: Fri, 8 May 2015 16:44:31 -0700 Subject: [PATCH] Increase fibers stack size if we're running with ASAN 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 | 28 +++++++++++++++----- folly/experimental/fibers/FiberManager.h | 9 +------ 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/folly/experimental/fibers/FiberManager-inl.h b/folly/experimental/fibers/FiberManager-inl.h index 793cf1fa..512d59eb 100644 --- a/folly/experimental/fibers/FiberManager-inl.h +++ b/folly/experimental/fibers/FiberManager-inl.h @@ -17,18 +17,34 @@ #include -#include -#include -#include -#include +#include #include #include -#include #include +#include #include +#include +#include +#include +#include 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__, 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); diff --git a/folly/experimental/fibers/FiberManager.h b/folly/experimental/fibers/FiberManager.h index 8ce9fc34..468a06da 100644 --- a/folly/experimental/fibers/FiberManager.h +++ b/folly/experimental/fibers/FiberManager.h @@ -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. -- 2.34.1