disable stack madvise optimization on non-Linux platforms
authorNathan Bronson <ngbronson@fb.com>
Thu, 4 Jun 2015 23:15:43 +0000 (16:15 -0700)
committerNoam Lerner <noamler@fb.com>
Fri, 5 Jun 2015 02:33:52 +0000 (19:33 -0700)
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

folly/detail/MemoryIdler.cpp

index 3d64f19db09a5eb6b79a7283a4e4faea6c2da6b2..07f6b05abe3dcf41763d13ac335aa8950cc1f883 100644 (file)
@@ -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;