From 2c23cbaf946f302248d37283965674311a4e3e6d Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 9 Oct 2023 17:35:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7jemalloc=E5=88=B05.3=E7=89=88?= =?UTF-8?q?=E6=9C=AC,=E7=9B=B8=E6=AF=945.2.1=E5=86=85=E5=AD=98=E7=A8=B3?= =?UTF-8?q?=E5=AE=9A=E8=AE=B8=E5=A4=9A,=E5=8E=BB=E9=99=A4--without-export?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E5=8F=82=E6=95=B0,=20=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E7=B1=BB=E4=BC=BCglibc=E4=B8=AD=E5=88=86=E9=85=8D=E5=86=85?= =?UTF-8?q?=E5=AD=98=E5=8D=B4=E5=9C=A8jemalloc=E4=B8=AD=E9=87=8A=E6=94=BE?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E5=B4=A9=E6=BA=83=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 13 ++++++++++++- cmake/Jemalloc.cmake | 23 ++++++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cb85679b..39c6c517 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,7 @@ option(ENABLE_FAAC "Enable FAAC" OFF) option(ENABLE_FFMPEG "Enable FFmpeg" OFF) option(ENABLE_HLS "Enable HLS" ON) option(ENABLE_JEMALLOC_STATIC "Enable static linking to the jemalloc library" OFF) +option(ENABLE_JEMALLOC_DUMP "Enable jemalloc to dump malloc statistics" OFF) option(ENABLE_MEM_DEBUG "Enable Memory Debug" OFF) option(ENABLE_MP4 "Enable MP4" ON) option(ENABLE_HLS_FMP4 "Enable HLS-FMP4" ON) @@ -335,7 +336,11 @@ if(ENABLE_JEMALLOC_STATIC) if(NOT EXISTS ${DEP_ROOT_DIR}) file(MAKE_DIRECTORY ${DEP_ROOT_DIR}) endif() - + if (ENABLE_JEMALLOC_DUMP) + set(ENABLE_JEMALLOC_STAT ON) + else () + set(ENABLE_JEMALLOC_STAT OFF) + endif () include(Jemalloc) include_directories(SYSTEM ${DEP_ROOT_DIR}/${JEMALLOC_NAME}/include/jemalloc) link_directories(${DEP_ROOT_DIR}/${JEMALLOC_NAME}/lib) @@ -349,6 +354,12 @@ if(JEMALLOC_FOUND) message(STATUS "found library: ${JEMALLOC_LIBRARIES}") include_directories(${JEMALLOC_INCLUDE_DIR}) update_cached_list(MK_LINK_LIBRARIES ${JEMALLOC_LIBRARIES}) + add_definitions(-DUSE_JEMALLOC) + message(STATUS "jemalloc will be used to avoid memory fragmentation") + if (ENABLE_JEMALLOC_DUMP) + add_definitions(-DENABLE_JEMALLOC_DUMP) + message(STATUS "jemalloc will save memory usage statistics when the program exits") + endif () endif() # 查找 openssl 是否安装 diff --git a/cmake/Jemalloc.cmake b/cmake/Jemalloc.cmake index 94d46b64..38847e58 100644 --- a/cmake/Jemalloc.cmake +++ b/cmake/Jemalloc.cmake @@ -1,21 +1,34 @@ # Download and build Jemalloc -set(JEMALLOC_VERSION 5.2.1) +set(JEMALLOC_VERSION 5.3.0) set(JEMALLOC_NAME jemalloc-${JEMALLOC_VERSION}) set(JEMALLOC_TAR_PATH ${DEP_ROOT_DIR}/${JEMALLOC_NAME}.tar.bz2) list(APPEND jemalloc_CONFIG_ARGS --disable-initial-exec-tls) -list(APPEND jemalloc_CONFIG_ARGS --without-export) +#list(APPEND jemalloc_CONFIG_ARGS --without-export) +if (ENABLE_JEMALLOC_STAT) + list(APPEND jemalloc_CONFIG_ARGS --enable-stats) + message(STATUS "Jemalloc stats enabled") +else () list(APPEND jemalloc_CONFIG_ARGS --disable-stats) + message(STATUS "Jemalloc stats disabled") +endif () list(APPEND jemalloc_CONFIG_ARGS --disable-libdl) #list(APPEND jemalloc_CONFIG_ARGS --disable-cxx) #list(APPEND jemalloc_CONFIG_ARGS --with-jemalloc-prefix=je_) #list(APPEND jemalloc_CONFIG_ARGS --enable-debug) if(NOT EXISTS ${JEMALLOC_TAR_PATH}) - message(STATUS "Downloading ${JEMALLOC_NAME}...") - file(DOWNLOAD https://github.com/jemalloc/jemalloc/releases/download/${JEMALLOC_VERSION}/${JEMALLOC_NAME}.tar.bz2 - ${JEMALLOC_TAR_PATH}) + set(JEMALLOC_URL https://github.com/jemalloc/jemalloc/releases/download/${JEMALLOC_VERSION}/${JEMALLOC_NAME}.tar.bz2) + message(STATUS "Downloading ${JEMALLOC_NAME} from ${JEMALLOC_URL}") + file(DOWNLOAD ${JEMALLOC_URL} ${JEMALLOC_TAR_PATH} SHOW_PROGRESS STATUS JEMALLOC_DOWNLOAD_STATUS LOG JEMALLOC_DOWNLOAD_LOG) + list(GET JEMALLOC_DOWNLOAD_STATUS 0 JEMALLOC_DOWNLOAD_STATUS_CODE) + if(NOT JEMALLOC_DOWNLOAD_STATUS_CODE EQUAL 0) + file(REMOVE ${JEMALLOC_TAR_PATH}) + message(STATUS "${JEMALLOC_DOWNLOAD_LOG}") + message(FATAL_ERROR "${JEMALLOC_NAME} download failed! error is ${JEMALLOC_DOWNLOAD_STATUS}") + return() + endif () endif() SET( DIR_CONTAINING_JEMALLOC ${DEP_ROOT_DIR}/${JEMALLOC_NAME} )