Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3121)

Unified Diff: build/toolchain/get_concurrent_links.py

Issue 2259503002: build: Refactor get_concurrent_links.py (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: refactor script Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: build/toolchain/get_concurrent_links.py
diff --git a/build/toolchain/get_concurrent_links.py b/build/toolchain/get_concurrent_links.py
index 4a66dd398f5f9a186d2b899490978d964caff2be..bea7789db1687048c91573c38e3279fab82c15b2 100644
--- a/build/toolchain/get_concurrent_links.py
+++ b/build/toolchain/get_concurrent_links.py
@@ -11,12 +11,7 @@ import re
import subprocess
import sys
-def _GetDefaultConcurrentLinks(is_lto):
- # Inherit the legacy environment variable for people that have set it in GYP.
- pool_size = int(os.getenv('GYP_LINK_CONCURRENCY', 0))
- if pool_size:
- return pool_size
-
+def _GetTotalMemoryInBytes():
if sys.platform in ('win32', 'cygwin'):
import ctypes
@@ -35,12 +30,7 @@ def _GetDefaultConcurrentLinks(is_lto):
stat = MEMORYSTATUSEX(dwLength=ctypes.sizeof(MEMORYSTATUSEX))
ctypes.windll.kernel32.GlobalMemoryStatusEx(ctypes.byref(stat))
-
- # VS 2015 uses 20% more working set than VS 2013 and can consume all RAM
- # on a 64 GB machine.
- mem_limit = max(1, stat.ullTotalPhys / (5 * (2 ** 30))) # total / 5GB
- hard_cap = max(1, int(os.getenv('GYP_LINK_CONCURRENCY_MAX', 2**32)))
- return min(mem_limit, hard_cap)
+ return stat.ullTotalPhys
elif sys.platform.startswith('linux'):
if os.path.exists("/proc/meminfo"):
with open("/proc/meminfo") as meminfo:
@@ -49,35 +39,38 @@ def _GetDefaultConcurrentLinks(is_lto):
match = memtotal_re.match(line)
if not match:
continue
- mem_total_gb = float(match.group(1)) / (2 ** 20)
- # Allow 8Gb per link on Linux because Gold is quite memory hungry
- mem_per_link_gb = 8
- if is_lto:
- mem_total_gb -= 10 # Reserve
- # For LTO builds the RAM requirements are even higher
- mem_per_link_gb = 24
- return int(max(1, mem_total_gb / mem_per_link_gb))
- return 1
+ return float(match.group(1)) * 2**10
elif sys.platform == 'darwin':
try:
avail_bytes = int(subprocess.check_output(['sysctl', '-n', 'hw.memsize']))
- # A static library debug build of Chromium's unit_tests takes ~2.7GB, so
- # 4GB per ld process allows for some more bloat.
- return max(1, avail_bytes / (4 * (2 ** 30))) # total / 4GB
except Exception:
- return 1
- else:
- # TODO(scottmg): Implement this for other platforms.
- return 1
+ return 0
+ # TODO(scottmg): Implement this for other platforms.
+ return 0
+
+
+def _GetDefaultConcurrentLinks(mem_per_link_gb, reserve_mem_gb):
+ # Inherit the legacy environment variable for people that have set it in GYP.
+ pool_size = int(os.getenv('GYP_LINK_CONCURRENCY', 0))
+ if pool_size:
+ return pool_size
+
+ mem_total_bytes = _GetTotalMemoryInBytes()
+ mem_total_bytes -= reserve_mem_gb * 2**30
brucedawson 2016/08/22 19:31:32 You probably need to check for this going negative
boliu 2016/08/22 20:49:03 Done.
+ num_concurrent_links = int(max(1, mem_total_bytes / mem_per_link_gb / 2**30))
+ hard_cap = max(1, int(os.getenv('GYP_LINK_CONCURRENCY_MAX', 2**32)))
+ return min(num_concurrent_links, hard_cap)
+
def main():
parser = optparse.OptionParser()
- parser.add_option('--lto', action="store_true", default=False,
- help='This is an LTO build with higher memory requirements')
+ parser.add_option('--mem_per_link_gb', action="store", type="int", default=8)
+ parser.add_option('--reserve_mem_gb', action="store", type="int", default=0)
parser.disable_interspersed_args()
options, args = parser.parse_args()
- print _GetDefaultConcurrentLinks(is_lto=options.lto)
+ print _GetDefaultConcurrentLinks(options.mem_per_link_gb,
+ options.reserve_mem_gb)
return 0
if __name__ == '__main__':
« build/toolchain/concurrent_links.gni ('K') | « build/toolchain/concurrent_links.gni ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698