Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallel builds of clang causing paging. #268

Closed
dtarditi opened this issue Apr 12, 2017 · 1 comment
Closed

Parallel builds of clang causing paging. #268

dtarditi opened this issue Apr 12, 2017 · 1 comment
Labels
work item This labels issues that are not exactly bugs but are about improvements.

Comments

@dtarditi
Copy link
Member

dtarditi commented Apr 12, 2017

I've confirmed that the parallel builds for automated tests are causing test machines to page (issue #267). I have tracked the problem to the amount of build parallelism being used in the MSBuild (Visual Studio solution) for clang generated by CMake.

CMake generates MSBuild files that set the /MP flag for the Microsoft Visual C++ compiler. When the C++ compiler is applied to a long list of files, it will launch as many compiler processes as there are CPU cores on your machine. For example,

cl A.c B.c, C.c D.c

causes the Microsoft Visual C++ compiler to launch 4 processes (one per file), if your machine as least 4 processors available (see this blog article). You can limit this in msbuild by setting the CL_MPCount property using the /p option. For example,

msbuild /p:CL_MPCount=nnn

where nnn is the maximum number of processes to launch.

When you use the /m:nnn option to msbuild, it launches as many build processes as are specified by nnn. If you use omit nnn and use only /m, it launches as many build processes as there are CPU cores on your machine. In our automated scripts, we were setting nnn to be 1/4 the number of CPU cores. The end result is that at times a quadratic number of compiler processes were being launched. If p is the number of processors, p^2/4 compilations were being launched. It is known that you can accidentally mis-use build parallelism with Visual Studio when using cmake: see the comments section for this Kitware CMake blog post.

The clang build does other things besides invoke the C++ compiler. It invokes tools like tblgen and builds libraries. There is lots of parallelism available in a clang/LLVM build, and the build system is better situated to recognize it and take advantage of it than invocations of the compiler driver. At the same time, the generated build system is invoking the C++ compiler with long lists of file arguments, so ratcheting individual build nodes down to no parallelism seems like a bad idea.

We need to make a trade-off: it seems better to set the build system parallelism to be high, and limit the individual compiler node parallelism to a constant. Modern OSes are very good at time-slicing CPU time across processes. They are not so good at time-slicing physical memory across processes. When there is more demand for physical memory than is actually available, this leads to virtual memory thrashing. Our goal is to create high CPU utilization while limiting memory usage to physical memory.

I've found that limiting the number of parallel C compiler processes spawned by the C++ compiler driver to 4 to 6 and setting the build system parallelism to the number of cores seems to achieve this. This is given 1 GB physical memory/core (166 MByte to 256 MBytes of memory/C++ compiler process). For 6 processes, you can do this by adding the following options to MSBuild:

msbuild /p:CL_CPUCount=6 /m

If you have less memory / core, you'll need to reduce the amount of build parallelism accordingly. I would suggest reducing the number of parallel C compiler launches.

@dtarditi dtarditi added the work item This labels issues that are not exactly bugs but are about improvements. label Apr 14, 2017
@dtarditi
Copy link
Member Author

This work is complete. The wiki has been updated to have the information in this issue and the md documentation has been updated too.

dopelsunce pushed a commit to dopelsunce/checkedc-clang that referenced this issue Sep 28, 2020
…edc#268)

We recently added compiler support for declaring bounds-safe interfaces that have interop types and bounds expressions.  Add tests of runtime bounds checking involving parameters declared this way.   The variables are declared in unchecked scopes and used in checked scopes.   Add tests for these combinations:

- checked array interop types.  This implies bounds that are the count of the first dimension of the array.
- array_ptr interop types with bounds expressions.
- nt_array_ptr interop types with bounds expressions.

We already had a test of nt_array_ptr with no bounds expression, which implies bounds of count(0).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
work item This labels issues that are not exactly bugs but are about improvements.
Projects
None yet
Development

No branches or pull requests

1 participant