Skip to content

Commit

Permalink
Merge pull request ceph#40149 from tchaikov/wip-cmake-job-pool
Browse files Browse the repository at this point in the history
cmake: use ninja job pool

Reviewed-by: Patrick Donnelly <pdonnell@redhat.com>
  • Loading branch information
tchaikov authored Apr 14, 2021
2 parents 061affa + 897fd99 commit e09f8d7
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

include(GNUInstallDirs)
include(CephChecks)
if(CMAKE_GENERATOR MATCHES Ninja)
include(LimitJobs)
endif()

set(CEPH_MAN_DIR "share/man" CACHE STRING "Install location for man pages (relative to prefix).")

Expand Down
47 changes: 47 additions & 0 deletions cmake/modules/LimitJobs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
set(MAX_COMPILE_MEM 2500 CACHE INTERNAL "maximum memory used by each compiling job (in MiB)")
set(MAX_LINK_MEM 3300 CACHE INTERNAL "maximum memory used by each linking job (in MiB)")

cmake_host_system_information(RESULT _num_cores QUERY NUMBER_OF_LOGICAL_CORES)
cmake_host_system_information(RESULT _total_mem QUERY TOTAL_PHYSICAL_MEMORY)

math(EXPR _avg_compile_jobs "${_total_mem} / ${MAX_COMPILE_MEM}")
if(_avg_compile_jobs EQUAL 0)
set(_avg_compile_jobs 1)
endif()
if(_num_cores LESS _avg_compile_jobs)
set(_avg_compile_jobs ${_num_cores})
endif()
set(NINJA_MAX_COMPILE_JOBS "${_avg_compile_jobs}" CACHE STRING
"The maximum number of concurrent compilation jobs, for Ninja build system." FORCE)
mark_as_advanced(NINJA_MAX_COMPILE_JOBS)
if(NINJA_MAX_COMPILE_JOBS)
math(EXPR _heavy_compile_jobs "${_avg_compile_jobs} / 2")
if(_heavy_compile_jobs EQUAL 0)
set(_heavy_compile_jobs 1)
endif()
set_property(GLOBAL APPEND PROPERTY JOB_POOLS
avg_compile_job_pool=${NINJA_MAX_COMPILE_JOBS}
heavy_compile_job_pool=${_heavy_compile_jobs})
set(CMAKE_JOB_POOL_COMPILE avg_compile_job_pool)
endif()

math(EXPR _avg_link_jobs "${_total_mem} / ${MAX_LINK_MEM}")
if(_avg_link_jobs EQUAL 0)
set(_avg_link_jobs 1)
endif()
if(_num_cores LESS _avg_link_jobs)
set(_avg_link_jobs ${_num_cores})
endif()
set(NINJA_MAX_LINK_JOBS "${_avg_link_jobs}" CACHE STRING
"The maximum number of concurrent link jobs, for Ninja build system." FORCE)
mark_as_advanced(NINJA_MAX_LINK_JOBS)
if(NINJA_MAX_LINK_JOBS)
math(EXPR _heavy_link_jobs "${_avg_link_jobs} / 2")
if(_heavy_link_jobs EQUAL 0)
set(_heavy_link_jobs 1)
endif()
set_property(GLOBAL APPEND PROPERTY JOB_POOLS
avg_link_job_pool=${NINJA_MAX_LINK_JOBS}
heavy_link_job_pool=${_heavy_link_jobs})
set(CMAKE_JOB_POOL_LINK avg_link_job_pool)
endif()
2 changes: 2 additions & 0 deletions src/crimson/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ add_library(crimson STATIC
${crimson_net_srcs})
target_compile_options(crimson PUBLIC
"-ftemplate-backtrace-limit=0")
set_target_properties(crimson PROPERTIES
JOB_POOL_COMPILE heavy_compile_job_pool)
target_link_libraries(crimson
PUBLIC
crimson-common
Expand Down
2 changes: 2 additions & 0 deletions src/crimson/os/seastore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ add_library(crimson-seastore STATIC
)
target_link_libraries(crimson-seastore
crimson)
set_target_properties(crimson-seastore PROPERTIES
JOB_POOL_COMPILE heavy_compile_job_pool)
3 changes: 3 additions & 0 deletions src/test/librbd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ add_executable(unittest_librbd
${unittest_librbd_srcs}
$<TARGET_OBJECTS:common_texttable_obj>)
target_compile_definitions(unittest_librbd PRIVATE "TEST_LIBRBD_INTERNALS")
set_target_properties(unittest_librbd PROPERTIES
JOB_POOL_COMPILE heavy_compile_job_pool
JOB_POOL_LINK heavy_link_job_pool)
add_dependencies(unittest_librbd
cls_journal
cls_lock
Expand Down
3 changes: 3 additions & 0 deletions src/tools/ceph-dencoder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ set(dencoder_srcs
../../include/utime.cc
$<TARGET_OBJECTS:common_texttable_obj>)
add_executable(ceph-dencoder ${dencoder_srcs})
set_target_properties(ceph-dencoder PROPERTIES
JOB_POOL_COMPILE heavy_compile_job_pool
JOB_POOL_LINK heavy_link_job_pool)

set(denc_plugin_dir ${CEPH_INSTALL_PKGLIBDIR}/denc)
add_custom_target(ceph-dencoder-modules)
Expand Down

0 comments on commit e09f8d7

Please sign in to comment.