tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

concurrent_links.gni (5805B)


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