Skip to content

Commit 326e32a

Browse files
rmacnak-googleCommit Queue
authored andcommitted
[build] Limit the number of concurrent dart/gen_snapshot actions.
Ninja may be run with a large --jobs value to run more C/C++ compilation actions in parallel on remote workers. The dart and gen_snapshot actions during the build should in this case remain limited to the number of cores on the machine to avoid a coincident memory usage that is too high. When running in the Dart tree with RBE, limit this by changing the RBE exec_strategy away from racing. Otherwise, use a pool to limit the concurrency of this action type. TEST=build.py --no-rbe -j1000 Bug: flutter/flutter#164591 Change-Id: Ia5e5615d0067b34d49871f26ead074cb891baf70 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/423562 Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent 715f756 commit 326e32a

File tree

5 files changed

+25
-36
lines changed

5 files changed

+25
-36
lines changed

build/dart/BUILD.gn

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
# for details. All rights reserved. Use of this source code is governed by a
3+
# BSD-style license that can be found in the LICENSE file.
4+
5+
if (current_toolchain == default_toolchain) {
6+
pool("dart_action_pool") {
7+
depth = exec_script("num_cpus.py", [], "value")
8+
}
9+
}

build/dart/dart_action.gni

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ template("_compiled_action") {
9898
"--exec_strategy=" + rbe_expensive_exec_strategy,
9999
"--",
100100
]
101+
} else if (!defined(invoker.pool)) {
102+
pool = "$_dart_root/build/dart:dart_action_pool($default_toolchain)"
101103
}
102104

103105
args += [ rebase_path(host_executable, root_build_dir) ] + invoker.args
@@ -148,6 +150,8 @@ template("_prebuilt_tool_action") {
148150
"--exec_strategy=" + rbe_expensive_exec_strategy,
149151
"--",
150152
]
153+
} else if (!defined(invoker.pool)) {
154+
pool = "$_dart_root/build/dart:dart_action_pool($default_toolchain)"
151155
}
152156

153157
args += [ rebase_path(invoker.binary, root_build_dir) ] + vm_args

build/dart/num_cpus.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env python3
2+
# Copyright 2025 The Dart Authors. All rights reserved.
3+
# Use of this source code is governed by a BSD-style license that can be
4+
# found in the LICENSE file.
5+
6+
import multiprocessing
7+
8+
print(multiprocessing.cpu_count())

build/toolchain/rbe.gni

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ declare_args() {
1919
# Set to the docker image to use in the RBE.
2020
rbe_image = "docker://gcr.io/cloud-marketplace/google/debian11@sha256:69e2789c9f3d28c6a0f13b25062c240ee7772be1f5e6d41bb4680b63eae6b304"
2121

22-
# Do expensive RBE compilations both locally and remotely, whatever is faster.
23-
rbe_expensive_exec_strategy = "racing"
22+
# Do expensive RBE actions remotely, falling back to local on failure/timeout.
23+
# The "racing" strategy can cause a memory exhaustion problem if too many
24+
# actions run locally at the same time.
25+
rbe_expensive_exec_strategy = "remote_local_fallback"
2426

2527
rbe_exec_root = rebase_path("//", root_build_dir)
2628

runtime/vm/os_thread_linux.cc

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "vm/os_thread.h"
1010

1111
#include <errno.h>
12-
#include <fcntl.h>
1312
#include <stdio.h>
1413
#include <sys/resource.h>
1514
#include <sys/syscall.h>
@@ -115,39 +114,6 @@ int OSThread::TryStart(const char* name,
115114

116115
pthread_t tid;
117116
result = pthread_create(&tid, &attr, ThreadStart, data);
118-
if (result != 0) {
119-
fprintf(stderr, "pthread_create failed\n");
120-
const char* const kPaths[] = {
121-
"/proc/self/limits",
122-
"/proc/sys/kernel/threads-max",
123-
"/proc/sys/kernel/pid_max",
124-
"/sys/fs/cgroup/user.slice/memory.current",
125-
"/sys/fs/cgroup/user.slice/memory.max",
126-
"/sys/fs/cgroup/user.slice/memory.peak",
127-
"/sys/fs/cgroup/user.slice/pids.current",
128-
"/sys/fs/cgroup/user.slice/pids.max",
129-
"/sys/fs/cgroup/user.slice/pids.peak",
130-
};
131-
for (uintptr_t i = 0; i < ARRAY_SIZE(kPaths); i++) {
132-
const char* path = kPaths[i];
133-
134-
int fd = open(path, O_RDONLY | O_CLOEXEC);
135-
if (fd < 0) {
136-
fprintf(stderr, "%s: Failed to open\n", path);
137-
continue;
138-
}
139-
const intptr_t kBufferSize = 2048;
140-
char buffer[kBufferSize];
141-
memset(buffer, 0, kBufferSize);
142-
ssize_t red = read(fd, buffer, kBufferSize - 1);
143-
close(fd);
144-
if (red < 0) {
145-
fprintf(stderr, "%s: Failed to read\n", path);
146-
continue;
147-
}
148-
fprintf(stderr, "%s: %s\n", path, buffer);
149-
}
150-
}
151117
RETURN_ON_PTHREAD_FAILURE(result);
152118

153119
result = pthread_attr_destroy(&attr);

0 commit comments

Comments
 (0)