USE_JEMALLOC in the OSS build if we have jemalloc
authorWez Furlong <wez@fb.com>
Wed, 7 Dec 2016 20:53:52 +0000 (12:53 -0800)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Wed, 7 Dec 2016 21:08:30 +0000 (13:08 -0800)
Summary:
Nothing defines USE_JEMALLOC in the OSS build today and that causes
some portability problems.

Specifically, the homebrew recipe will make libjemalloc available and our
configure script will detect it and add it to the library flags.

Our subsequent check for `malloc_usable_size` then finds this function in
libjemalloc.

When later attempting to build wangle against the homebrew folly we get
compilation failures because the prototype for `malloc_usable_size` is only
available in the jemalloc headers and nothing in the saved configuration for
folly is set up for this to be pulled in as it it guarded by `USE_JEMALLOC`.

This attempts to resolve the situation by forcing on `USE_JEMALLOC` when
we detect the library in configure.

This is made a little more complicated because we cannot set `USE_JEMALLOC`
in the OSS build; it gets rewritten to have a `FOLLY_` prefix.  Since we
have code outside of folly that requires that this symbol be `USE_JEMALLOC`,
I've changed the conditional to check for both flavors of the symbol, with
and without the prefix.

Reviewed By: yfeldblum

Differential Revision: D4289176

fbshipit-source-id: 756bc815c3ef1fac454e603feb72155d98c5aadd

folly/configure.ac
folly/portability/Malloc.cpp
folly/portability/Malloc.h

index 3f4968e02c5d0e421dcbba9366447a1337cdf230..90771eabb4e8f53a3a360e8821d1302fcc04ea6e 100644 (file)
@@ -161,7 +161,15 @@ AC_CHECK_LIB([double-conversion],[ceil],[],[AC_MSG_ERROR(
 AC_CHECK_LIB([event], [event_set], [], [AC_MSG_ERROR([Unable to find libevent])])
 FB_CHECK_PKG_CONFIG([EVENT], [libevent])
 
-AC_CHECK_LIB([jemalloc], [xallocx])
+AC_ARG_WITH([jemalloc], [
+  --with-jemalloc     Whether to make folly jemalloc aware
+],[
+  AC_CHECK_LIB([jemalloc], [xallocx],[
+    AC_DEFINE([USE_JEMALLOC], [1], [Enable jemalloc])
+  ],[
+    AC_MSG_ERROR([--with-jemalloc requested, but jemalloc not found])
+  ])
+])
 
 # Checks for typedefs, structures, and compiler characteristics.
 AC_HEADER_STDBOOL
index 9baecb38e226fddbac7227fe3fbf4bd7ef0f71e2..d9bdf989ae37519a4da64476e58be4fabf3a1892 100755 (executable)
@@ -16,7 +16,7 @@
 
 #include <folly/portability/Malloc.h>
 
-#ifndef USE_JEMALLOC
+#if !defined(USE_JEMALLOC) && !defined(FOLLY_USE_JEMALLOC)
 #if defined(__APPLE__) && !defined(FOLLY_HAVE_MALLOC_USABLE_SIZE)
 #include <malloc/malloc.h>
 
index 32c1ab3334ec7157f2402b906b40ee3a5f1f3bd6..cbf54e24991a6611f7a90e8a57b4263120e18fa6 100755 (executable)
 
 #pragma once
 
+#include <folly/portability/Config.h>
 #include <stdlib.h>
 
-#ifdef USE_JEMALLOC
+#if defined(USE_JEMALLOC) || defined(FOLLY_USE_JEMALLOC)
 // JEMalloc provides it's own implementation of
 // malloc_usable_size, and that's what we should be using.
 #include <jemalloc/jemalloc.h>
@@ -27,8 +28,6 @@
 #include <malloc.h>
 #endif
 
-#include <folly/portability/Config.h>
-
 #if defined(__APPLE__) && !defined(FOLLY_HAVE_MALLOC_USABLE_SIZE)
 // MacOS doesn't have malloc_usable_size()
 extern "C" size_t malloc_usable_size(void* ptr);