From: Nathan Bronson Date: Thu, 4 Jun 2015 23:15:43 +0000 (-0700) Subject: disable stack madvise optimization on non-Linux platforms X-Git-Tag: v0.43.0~1 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=2df2c5506a568220d3e4583170c64a84c11ed1b2;p=folly.git disable stack madvise optimization on non-Linux platforms Summary: This diff strengthens the preconditions for attempting to use optimize by madvising away idle stacks, because it seemed to be causing problems on OS X (https://github.com/facebook/proxygen/issues/3). Test Plan: unit tests Reviewed By: ldbrandy@fb.com Subscribers: folly-diffs@, yfeldblum, chalfant FB internal diff: D2129100 Signature: t1:2129100:1433458268:0b6b3696dde6c2bd13b89bc7ec58f0b1898be458 --- diff --git a/folly/detail/MemoryIdler.cpp b/folly/detail/MemoryIdler.cpp index 3d64f19d..07f6b05a 100644 --- a/folly/detail/MemoryIdler.cpp +++ b/folly/detail/MemoryIdler.cpp @@ -80,7 +80,10 @@ void MemoryIdler::flushLocalMallocCaches() { } -#if FOLLY_X64 +// Stack madvise isn't Linux or glibc specific, but the system calls +// and arithmetic (and bug compatibility) are not portable. The set of +// platforms could be increased if it was useful. +#if FOLLY_X64 && defined(_GNU_SOURCE) && defined(__linux__) static const size_t s_pageSize = sysconf(_SC_PAGESIZE); static FOLLY_TLS uintptr_t tls_stackLimit; @@ -88,11 +91,7 @@ static FOLLY_TLS size_t tls_stackSize; static void fetchStackLimits() { pthread_attr_t attr; -#if defined(_GNU_SOURCE) && defined(__linux__) // Linux+GNU extension pthread_getattr_np(pthread_self(), &attr); -#else - pthread_attr_init(&attr); -#endif SCOPE_EXIT { pthread_attr_destroy(&attr); }; void* addr;