mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From al...@apache.org
Subject [04/12] mesos git commit: Added jemalloc release tarball and build rules.
Date Wed, 18 Apr 2018 04:21:57 GMT
Added jemalloc release tarball and build rules.

Review: https://reviews.apache.org/r/63366/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/cae2d20c
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/cae2d20c
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/cae2d20c

Branch: refs/heads/master
Commit: cae2d20c28af742d1b92f5882009cfd0f62dc9d6
Parents: 705bf1d
Author: Benno Evers <bevers@mesosphere.com>
Authored: Tue Apr 17 18:31:31 2018 +0200
Committer: Alexander Rukletsov <alexr@apache.org>
Committed: Wed Apr 18 06:20:29 2018 +0200

----------------------------------------------------------------------
 3rdparty/CMakeLists.txt          |  25 +++++++++++
 3rdparty/Makefile.am             |  20 +++++++++
 3rdparty/cmake/Versions.cmake    |   2 +
 3rdparty/jemalloc-5.0.1.tar.gz   | Bin 0 -> 608494 bytes
 3rdparty/versions.am             |   1 +
 CHANGELOG                        |   4 ++
 cmake/CompilationConfigure.cmake |  14 ++++++
 configure.ac                     |  78 +++++++++++++++++++++++++++++++++-
 src/Makefile.am                  |  17 ++++++++
 src/master/CMakeLists.txt        |   3 ++
 src/slave/CMakeLists.txt         |   4 ++
 11 files changed, 167 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/cae2d20c/3rdparty/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt
index 488e906..4eba87f 100644
--- a/3rdparty/CMakeLists.txt
+++ b/3rdparty/CMakeLists.txt
@@ -30,6 +30,7 @@ set(ELFIO_URL           ${FETCH_URL}/elfio-${ELFIO_VERSION}.tar.gz)
 set(GLOG_URL            ${FETCH_URL}/glog-${GLOG_VERSION}.tar.gz)
 set(GOOGLETEST_URL      ${FETCH_URL}/googletest-release-${GOOGLETEST_VERSION}.tar.gz)
 set(HTTP_PARSER_URL     ${FETCH_URL}/http-parser-${HTTP_PARSER_VERSION}.tar.gz)
+set(JEMALLOC_URL        ${FETCH_URL}/jemalloc-${JEMALLOC_VERSION}.tar.gz)
 set(PICOJSON_URL        ${FETCH_URL}/picojson-${PICOJSON_VERSION}.tar.gz)
 set(PROTOBUF_URL        ${FETCH_URL}/protobuf-${PROTOBUF_VERSION}.tar.gz)
 set(LEVELDB_URL         ${FETCH_URL}/leveldb-${LEVELDB_VERSION}.tar.gz)
@@ -973,6 +974,30 @@ ExternalProject_Add(
   URL_HASH          ${PROTOBUF_HASH})
 
 
+# Jemalloc: General-purpose malloc implementation.
+# http://jemalloc.net
+##################################################
+EXTERNAL(jemalloc ${JEMALLOC_VERSION} ${CMAKE_CURRENT_BINARY_DIR})
+add_library(jemalloc STATIC IMPORTED GLOBAL)
+add_dependencies(jemalloc ${JEMALLOC_TARGET})
+
+set_target_properties(
+  jemalloc PROPERTIES
+  IMPORTED_LOCATION ${JEMALLOC_ROOT}-build/lib/libjemalloc_pic${CMAKE_STATIC_LIBRARY_SUFFIX})
+
+set(
+  JEMALLOC_CONFIGURE_COMMAND
+  ${JEMALLOC_ROOT}/configure --enable-stats --enable-prof --with-malloc-conf=prof:true,prof_active:false)
+
+ExternalProject_Add(
+  ${JEMALLOC_TARGET}
+  PREFIX            ${JEMALLOC_CMAKE_ROOT}
+  CONFIGURE_COMMAND ${JEMALLOC_CONFIGURE_COMMAND}
+  INSTALL_COMMAND   ${CMAKE_NOOP}
+  URL               ${JEMALLOC_URL}
+  URL_HASH          ${JEMALLOC_HASH})
+
+
 # Apache ZooKeeper: C Client Library to ZooKeeper.
 # https://zookeeper.apache.org/
 ##################################################

http://git-wip-us.apache.org/repos/asf/mesos/blob/cae2d20c/3rdparty/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/Makefile.am b/3rdparty/Makefile.am
index 10b29c9..8d9fa85 100644
--- a/3rdparty/Makefile.am
+++ b/3rdparty/Makefile.am
@@ -59,6 +59,7 @@ GPERFTOOLS = gperftools-$(GPERFTOOLS_VERSION)
 GRPC = grpc-$(GRPC_VERSION)
 GTEST = $(GOOGLETEST)/googletest
 HTTP_PARSER = http-parser-$(HTTP_PARSER_VERSION)
+JEMALLOC = jemalloc-$(JEMALLOC_VERSION)
 LEVELDB = leveldb-$(LEVELDB_VERSION)
 LIBEV = libev-$(LIBEV_VERSION)
 NVML = nvml-$(NVML_VERSION)
@@ -79,6 +80,7 @@ EXTRA_DIST =			\
   $(GPERFTOOLS).tar.gz		\
   $(GRPC).tar.gz		\
   $(HTTP_PARSER).tar.gz		\
+  $(JEMALLOC).tar.gz		\
   $(LEVELDB).tar.gz		\
   $(LIBEV).tar.gz		\
   $(NVML).tar.gz		\
@@ -117,6 +119,7 @@ CLEAN_EXTRACTED =		\
   $(GPERFTOOLS)			\
   $(GRPC)			\
   $(HTTP_PARSER)		\
+  $(JEMALLOC)			\
   $(LEVELDB)			\
   $(LIBEV)			\
   $(NVML)			\
@@ -249,6 +252,23 @@ $(HTTP_PARSER)-build-stamp: libry_http_parser.la
 	touch $@
 endif
 
+
+if WITH_BUNDLED_JEMALLOC
+JEMALLOC_CONFIGURE_ARGS = \
+    --enable-stats --enable-prof --with-malloc-conf="prof:true,prof_active:false"
+
+LIB_JEMALLOC = $(JEMALLOC)/libjemalloc.la
+
+$(LIB_JEMALLOC): $(JEMALLOC)-build-stamp
+
+$(JEMALLOC)-build-stamp: $(JEMALLOC)-stamp
+	cd $(JEMALLOC) && ./configure $(JEMALLOC_CONFIGURE_ARGS) $(CONFIGURE_ARGS)
+	cd $(JEMALLOC) && $(MAKE) $(AM_MAKEFLAGS)
+	touch $@
+
+ALL_LOCAL += $(LIB_JEMALLOC)
+endif
+
 if WITH_BUNDLED_LIBEV
 $(LIBEV)/libev.la: $(LIBEV)-build-stamp
 $(LIBEV)-build-stamp: $(LIBEV)-stamp

http://git-wip-us.apache.org/repos/asf/mesos/blob/cae2d20c/3rdparty/cmake/Versions.cmake
----------------------------------------------------------------------
diff --git a/3rdparty/cmake/Versions.cmake b/3rdparty/cmake/Versions.cmake
index 605cbde..33577cc 100644
--- a/3rdparty/cmake/Versions.cmake
+++ b/3rdparty/cmake/Versions.cmake
@@ -12,6 +12,8 @@ set(GOOGLETEST_VERSION      "1.8.0")
 set(GOOGLETEST_HASH         "SHA256=58A6F4277CA2BC8565222B3BBD58A177609E9C488E8A72649359BA51450DB7D8")
 set(HTTP_PARSER_VERSION     "2.6.2")
 set(HTTP_PARSER_HASH        "SHA256=80FFFC3B64EF6968CECDD4B299A96986007DFF4BD12AE6C58CBCB506959B90AD")
+set(JEMALLOC_VERSION        "5.0.1")
+set(JEMALLOC_HASH           "SHA256=18BD8A2135EA8CC4C9EFBE0378D9F7BE9C40E0804F34D941BF028D61F845198D")
 set(LEVELDB_VERSION         "1.19")
 set(LEVELDB_HASH            "SHA256=7D7A14AE825E66AABEB156C1C3FAE9F9A76D640EF6B40EDE74CC73DA937E5202")
 set(LIBAPR_VERSION          "1.5.2")

http://git-wip-us.apache.org/repos/asf/mesos/blob/cae2d20c/3rdparty/jemalloc-5.0.1.tar.gz
----------------------------------------------------------------------
diff --git a/3rdparty/jemalloc-5.0.1.tar.gz b/3rdparty/jemalloc-5.0.1.tar.gz
new file mode 100644
index 0000000..204e704
Binary files /dev/null and b/3rdparty/jemalloc-5.0.1.tar.gz differ

http://git-wip-us.apache.org/repos/asf/mesos/blob/cae2d20c/3rdparty/versions.am
----------------------------------------------------------------------
diff --git a/3rdparty/versions.am b/3rdparty/versions.am
index 63d879b..ada998d 100644
--- a/3rdparty/versions.am
+++ b/3rdparty/versions.am
@@ -28,6 +28,7 @@ GOOGLETEST_VERSION = 1.8.0
 GPERFTOOLS_VERSION = 2.5
 GRPC_VERSION = 1.10.0
 HTTP_PARSER_VERSION = 2.6.2
+JEMALLOC_VERSION = 5.0.1
 LEVELDB_VERSION = 1.19
 LIBEV_VERSION = 4.22
 NVML_VERSION = 352.79

http://git-wip-us.apache.org/repos/asf/mesos/blob/cae2d20c/CHANGELOG
----------------------------------------------------------------------
diff --git a/CHANGELOG b/CHANGELOG
index d3809b2..09fff1d 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -5,6 +5,10 @@ This release contains the following new features:
   * [MESOS-8534] - **Experimental** A nested container is now allowed
     to join a separate CNI network than its parent container.
 
+  * [MESOS-7944] - **Experimental** On Linux, Mesos can now be
+    configured to use the jemalloc allocator by default via the
+    `--enable-jemalloc-allocator` configuration option.
+
 
 Release Notes - Mesos - Version 1.5.1 (WIP)
 -------------------------------------------

http://git-wip-us.apache.org/repos/asf/mesos/blob/cae2d20c/cmake/CompilationConfigure.cmake
----------------------------------------------------------------------
diff --git a/cmake/CompilationConfigure.cmake b/cmake/CompilationConfigure.cmake
index 08d154e..173089a 100644
--- a/cmake/CompilationConfigure.cmake
+++ b/cmake/CompilationConfigure.cmake
@@ -353,6 +353,20 @@ endif()
 ######################
 string(COMPARE EQUAL ${CMAKE_SYSTEM_NAME} "Linux" LINUX)
 
+if (LINUX)
+  # We currenty only support using the bundled jemalloc on linux.
+  # While building it and linking against is actually not a problem
+  # on other platforms, to make it actually *useful* we need some
+  # additional platform-specific code in the mesos binaries that re-routes
+  # all existing malloc/free calls through jemalloc.
+  # On linux, that is not necessary because the default malloc implementation
+  # explicitly supports replacement via symbol interposition.
+  option(
+    ENABLE_JEMALLOC_ALLOCATOR
+    "Use jemalloc as memory allocator for the master and agent binaries."
+    FALSE)
+endif ()
+
 # FREEBSD CONFIGURATION.
 ######################
 string(COMPARE EQUAL ${CMAKE_SYSTEM_NAME} "FreeBSD" FREEBSD)

http://git-wip-us.apache.org/repos/asf/mesos/blob/cae2d20c/configure.ac
----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index 4c4085c..6e91ecf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -214,6 +214,13 @@ AC_ARG_ENABLE([java],
                              [do not build Java bindings]),
               [], [enable_java=yes])
 
+# TODO(bevers): Eventually make this enabled by default.
+AC_ARG_ENABLE([jemalloc-allocator],
+               AS_HELP_STRING([--enable-jemalloc-allocator],
+                              [Use jemalloc as the default memory allocator for the
+                               mesos-master and mesos-agent binaries.]),
+               [], [enable_jemalloc_allocator=no])
+
 # TODO(benh): Eventually make this enabled by default.
 AC_ARG_ENABLE([last_in_first_out_fixed_size_semaphore],
               AS_HELP_STRING([--enable-last-in-first-out-fixed-size-semaphore],
@@ -375,6 +382,13 @@ AC_ARG_WITH([http-parser],
                            location prefixed by the given path]),
             [without_bundled_http_parser=yes], [])
 
+AC_ARG_WITH([jemalloc],
+            AS_HELP_STRING([--with-jemalloc@<:@=DIR@:>@],
+                          [excludes building and using the bundled jemalloc
+                          package in lieu of an installed version at a
+                          location prefixed by the given path.]),
+            [without_bundled_jemalloc=yes], [])
+
 AC_ARG_WITH([leveldb],
             AS_HELP_STRING([--with-leveldb@<:@=DIR@:>@],
                            [excludes building and using the bundled LevelDB
@@ -504,6 +518,10 @@ AS_IF([test "x$enable_lock_free_event_queue" = "xyes"],
 AS_IF([test "x$enable_lock_free_run_queue" = "xyes"],
       [AC_DEFINE([LOCK_FREE_RUN_QUEUE])])
 
+# Check if we should link the mesos binaries against jemalloc.
+AM_CONDITIONAL([ENABLE_JEMALLOC_ALLOCATOR],
+         [test x"$enable_jemalloc_allocator" = "xyes"])
+
 # Check to see if we should harden or not.
 AM_CONDITIONAL([ENABLE_HARDENING], [test x"$enable_hardening" = "xyes"])
 
@@ -697,7 +715,7 @@ AM_CONDITIONAL([ENABLE_STATIC_LIBPROCESS], [true])
 
 AC_MSG_NOTICE([Setting up build environment for ${target_cpu} ${target_os}])
 # Determine the current OS (TODO(benh): Does autotools do this for us?).
-case "${target_os}" in
+case "${host_os}" in
   linux*)
     OS_NAME=linux
     LIBS="$LIBS -lrt"
@@ -1081,6 +1099,64 @@ AM_CONDITIONAL([WITH_BUNDLED_HTTP_PARSER],
                [test "x$with_bundled_http_parser" = "xyes"])
 
 
+# NB: Since malloc() and free() are declared in stdlib.h, and the
+# jemalloc-specific api is detected at runtime, we dont need any
+# jemalloc headers or modify CPPFLAGS here.
+if test "x$enable_jemalloc_allocator" = "xyes"; then
+  if test "x$OS_NAME" != "xlinux"; then
+    # Building and linking against jemalloc is actually not a problem
+    # on OSX even now, but to make it actually *useful* we would have
+    # have to re-route all existing malloc/free calls through jemalloc.
+    # The recommended way of doing that on Mac seems to be call
+    # `malloc_default_zone()` and to overwrite the hooks in the
+    # returned `malloc_zone_t`.
+    AC_MSG_ERROR([
+--------------------------------------------------------------------
+You have requested the default memory allocator to be replaced by
+jemalloc, but your operating system was detected to be $OS_NAME.
+
+This feature is currently only supported on linux.
+--------------------------------------------------------------------
+    ])
+  fi
+
+  if test -n "`echo $with_jemalloc`"; then
+    WITH_JEMALLOC="${with_jemalloc}"
+  fi
+
+  # Check if the user asked us to use a preinstalled jemalloc, or if
+  # they asked us to ignore all bundled libraries while compiling and
+  # linking.
+  if test "x$without_bundled_jemalloc" = "xyes" || \
+     test "x$enable_bundled" != "xyes"; then
+
+    # Avoid AC_SEARCH_LIBS here because it would implicitly add jemalloc
+    # to LIBS, but we dont want to link it against libmesos, only the
+    # individual binaries
+    AC_CHECK_LIB([jemalloc], [malloc_stats_print], [found_jemalloc=yes])
+    if test "x$found_jemalloc" = "xyes"; then
+      with_bundled_jemalloc=no
+    else
+      AC_MSG_ERROR([cannot find jemalloc
+-------------------------------------------------------------------
+You have requested the use of a non-bundled jemalloc but no suitable
+library could be found.
+
+You may want specify the location of jemalloc by providing a prefix
+path via --with-jemalloc=DIR, or check that the path you provided is
+correct if you're already doing this.
+-------------------------------------------------------------------
+  ])
+    fi
+  else
+    with_bundled_jemalloc=yes
+  fi
+fi
+
+AC_SUBST(WITH_JEMALLOC)
+AM_CONDITIONAL([WITH_BUNDLED_JEMALLOC],
+         [test "x$with_bundled_jemalloc" = "xyes"])
+
 # TODO(benh): Consider using AS_IF instead of just shell 'if'
 # statements for better autoconf style (the AS_IF macros also make
 # sure variable dependencies are handled appropriately).

http://git-wip-us.apache.org/repos/asf/mesos/blob/cae2d20c/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 07eb138..9d610bb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -33,6 +33,7 @@ GMOCK = $(GOOGLETEST)/googlemock
 GOOGLETEST = 3rdparty/googletest-release-$(GOOGLETEST_VERSION)
 GRPC = 3rdparty/grpc-$(GRPC_VERSION)
 GTEST = $(GOOGLETEST)/googletest
+JEMALLOC = 3rdparty/jemalloc-$(JEMALLOC_VERSION)
 LEVELDB = 3rdparty/leveldb-$(LEVELDB_VERSION)
 LIBPROCESS = 3rdparty/libprocess
 NVML = 3rdparty/nvml-$(NVML_VERSION)
@@ -183,6 +184,17 @@ GRPC_CPP_PLUGIN = @GRPC_CXX_PLUGIN@
 endif
 endif
 
+if WITH_BUNDLED_JEMALLOC
+# TODO(bennoe): We could call `jemalloc-conf --libs` to get the required
+# libs without hardcoding `-ldl`, but then a version bump could introduce
+# additional dependencies without us being aware of it.
+LIB_JEMALLOC = ../$(JEMALLOC)/lib/libjemalloc_pic.a -ldl
+else
+LIB_JEMALLOC = $(if $(WITH_JEMALLOC),\
+    -L$(WITH_JEMALLOC)/lib -ljemalloc -ldl,\
+    -ljemalloc -ldl)
+endif
+
 if WITH_BUNDLED_LEVELDB
 MESOS_CPPFLAGS += -I../$(LEVELDB)/include
 
@@ -1681,6 +1693,11 @@ mesos_local_SOURCES = local/main.cpp
 mesos_local_CPPFLAGS = $(MESOS_CPPFLAGS)
 mesos_local_LDADD = libmesos.la $(LDADD)
 
+if ENABLE_JEMALLOC_ALLOCATOR
+mesos_agent_LDADD += $(LIB_JEMALLOC)
+mesos_master_LDADD  += $(LIB_JEMALLOC)
+endif
+
 pkglibexec_PROGRAMS += mesos-fetcher
 mesos_fetcher_SOURCES = launcher/fetcher.cpp
 mesos_fetcher_CPPFLAGS = $(MESOS_CPPFLAGS)

http://git-wip-us.apache.org/repos/asf/mesos/blob/cae2d20c/src/master/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/master/CMakeLists.txt b/src/master/CMakeLists.txt
index b8953bd..f4b15b5 100644
--- a/src/master/CMakeLists.txt
+++ b/src/master/CMakeLists.txt
@@ -18,3 +18,6 @@
 ########################
 add_executable(mesos-master main.cpp)
 target_link_libraries(mesos-master PRIVATE mesos)
+if (ENABLE_JEMALLOC_ALLOCATOR)
+  target_link_libraries(mesos-master PRIVATE jemalloc)
+endif ()

http://git-wip-us.apache.org/repos/asf/mesos/blob/cae2d20c/src/slave/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/slave/CMakeLists.txt b/src/slave/CMakeLists.txt
index 943e8f5..e5fe32a 100644
--- a/src/slave/CMakeLists.txt
+++ b/src/slave/CMakeLists.txt
@@ -24,6 +24,10 @@ add_subdirectory(resource_estimators)
 add_executable(mesos-agent main.cpp)
 target_link_libraries(mesos-agent PRIVATE mesos)
 
+if (ENABLE_JEMALLOC_ALLOCATOR)
+  target_link_libraries(mesos-agent PRIVATE jemalloc)
+endif ()
+
 # Add binary dependencies
 add_dependencies(
   mesos-agent


Mime
View raw message