concurrent_links.gni 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # Copyright 2016 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. # This file should only be imported from files that define toolchains.
  5. # There's no way to enforce this exactly, but all toolchains are processed
  6. # in the context of the default_toolchain, so we can at least check for that.
  7. assert(current_toolchain == default_toolchain)
  8. import("//build/config/android/config.gni")
  9. import("//build/config/apple/symbols.gni")
  10. import("//build/config/chromeos/ui_mode.gni")
  11. import("//build/config/compiler/compiler.gni")
  12. import("//build/config/coverage/coverage.gni")
  13. import("//build/config/sanitizers/sanitizers.gni")
  14. import("//build/toolchain/toolchain.gni")
  15. declare_args() {
  16. # Limit the number of concurrent links; we often want to run fewer
  17. # links at once than we do compiles, because linking is memory-intensive.
  18. # The default to use varies by platform and by the amount of memory
  19. # available, so we call out to a script to get the right value.
  20. concurrent_links = -1
  21. }
  22. if (concurrent_links == -1) {
  23. if (use_thin_lto) {
  24. _args = [ "--reserve_mem_gb=10" ]
  25. if (use_goma_thin_lto) {
  26. _args += [ "--thin-lto=goma" ]
  27. } else {
  28. _args += [ "--thin-lto=local" ]
  29. }
  30. if (is_win) {
  31. # Based on measurements of linking chrome.dll and chrome_child.dll, plus
  32. # a little padding to account for future growth.
  33. _args += [ "--mem_per_link_gb=45" ]
  34. } else {
  35. _args += [ "--mem_per_link_gb=16" ]
  36. }
  37. } else if ((use_clang_coverage &&
  38. # When coverage_instrumentation_input_file is not empty it means
  39. # we're only instrumenting changed files and not using a lot of
  40. # memory. Likewise, when it's empty we're building everything with
  41. # coverage, which requires more memory.
  42. coverage_instrumentation_input_file == "") ||
  43. use_sanitizer_coverage || use_fuzzing_engine) {
  44. # Full sanitizer coverage instrumentation increases linker memory consumption
  45. # significantly.
  46. _args = [ "--mem_per_link_gb=16" ]
  47. } else if (is_win && symbol_level == 1 && !is_debug && is_component_build) {
  48. _args = [ "--mem_per_link_gb=3" ]
  49. } else if (is_win) {
  50. _args = [ "--mem_per_link_gb=6" ]
  51. } else if (is_mac) {
  52. if (enable_dsyms) {
  53. _args = [ "--mem_per_link_gb=12" ]
  54. } else {
  55. _args = [ "--mem_per_link_gb=4" ]
  56. }
  57. } else if (is_android && !is_component_build && symbol_level == 2) {
  58. # Full debug symbols require large memory for link.
  59. _args = [ "--mem_per_link_gb=25" ]
  60. } else if (is_android && !is_debug && !using_sanitizer && symbol_level < 2) {
  61. if (symbol_level == 1) {
  62. _args = [ "--mem_per_link_gb=6" ]
  63. } else {
  64. _args = [ "--mem_per_link_gb=4" ]
  65. }
  66. } else if ((is_linux || is_chromeos_lacros) && symbol_level == 0) {
  67. # Memory consumption on link without debug symbols is low on linux.
  68. _args = [ "--mem_per_link_gb=3" ]
  69. } else if (current_os == "zos") {
  70. _args = [ "--mem_per_link_gb=1" ]
  71. } else if (is_fuchsia) {
  72. # TODO(crbug.com/1347159): This was defaulting to 8GB. The number of
  73. # linker instances to run in parallel is calculated by diviging
  74. # the available memory by this value. On a 32GB machine with
  75. # roughly 29GB of available memory, this would cause three instances
  76. # to run. This started running out of memory and thrashing. This change
  77. # addresses that issue to get the SDk rollers running again but
  78. # could be optimized (maybe to 12GB or for different configs like
  79. # component build).
  80. _args = [ "--mem_per_link_gb=16" ]
  81. } else {
  82. _args = []
  83. }
  84. # For Android builds, we also need to be wary of:
  85. # * ProGuard / R8
  86. # * Android Lint
  87. # These both have a peak usage of < 2GB, but that is still large enough for
  88. # them to need to use a pool since they both typically happen at the
  89. # same time as linking.
  90. if (is_android) {
  91. _args += [ "--secondary_mem_per_link=2" ]
  92. }
  93. # TODO(crbug.com/617429) Pass more build configuration info to the script
  94. # so that we can compute better values.
  95. _command_dict = exec_script("get_concurrent_links.py", _args, "scope")
  96. concurrent_links = _command_dict.primary_pool_size
  97. concurrent_links_logs = _command_dict.explanation
  98. if (_command_dict.secondary_pool_size >= concurrent_links) {
  99. # Have R8 / Lint share the link pool unless we would safely get more
  100. # concurrency out of using a separate one.
  101. # On low-RAM machines, this allows an apk's native library to link at the
  102. # same time as its java is optimized with R8.
  103. java_cmd_pool_size = _command_dict.secondary_pool_size
  104. }
  105. } else {
  106. assert(!use_thin_lto, "can't explicitly set concurrent_links with thinlto")
  107. concurrent_links_logs =
  108. [ "concurrent_links set by GN arg (value=$concurrent_links)" ]
  109. }