I was experimenting yesterday with building lld on my POWER7 PPC64/Linux machine, and ran into an unfortunate problem. When running the regressions tests under lit, almost all of the tests fail like this:
which seems to indicate a core problem here with dealing with thread-resource exhaustion. For almost all tests, running them individually (or using lit -j 1) works without a problem. We could deal with this by limiting the number of threads lld uses when running regression tests, or limit the number of threads that lit uses when running lld tests (as we currently do with the OpenMP runtime tests), but I'm somewhat concerned that users will run into this program regardless with heavily-parallelized builds.
We could try to catch exceptions that otherwise come from ThreadPoolExecutor's constructor, but do we compile with exceptions enabled?
I was experimenting yesterday with building lld on my POWER7 PPC64/Linux
machine, and ran into an unfortunate problem. When running the regressions
tests under lit, almost all of the tests fail like this:
which seems to indicate a core problem here with dealing with
thread-resource exhaustion. For almost all tests, running them individually
(or using lit -j 1) works without a problem. We could deal with this by
limiting the number of threads lld uses when running regression tests, or
limit the number of threads that lit uses when running lld tests (as we
currently do with the OpenMP runtime tests), but I'm somewhat concerned
that users will run into this program regardless with heavily-parallelized
builds.
We could try to catch exceptions that otherwise come from
ThreadPoolExecutor's constructor, but do we compile with exceptions enabled?
I guess we do not want to enable exceptions to deal with the issue. Are
COFF tests failing, or just ELF tests? If ELF tests for the old LLD are
failing, the best way would be to not use threads in the old LLD. It has
lingering threading issues.
To provide a data point; my default environment has this:
$ ulimit -a | grep proc
max user processes (-u) 1024
This machine has 48 cores, so with lit running 48 tests leaves each test with only about 20 available threads, much less than the 48 each test believes it can use.
This is somewhat non-deterministic, but I just reran things both ways, and here's what I see:
During my last run, these tests fail when running under lit with many parallel tests, but do not fail when run otherwise:
I honestly think that the ulimit of 1024 max threads is too strict for 48 core machine. Processes are independent each other, so it is not strange for them to spawn as many threads as the number of cores. What’s the reason you cannot increase the limit?
I honestly think that the ulimit of 1024 max threads is too strict
for 48 core machine. Processes are independent each other, so it is
not strange for them to spawn as many threads as the number of
cores.
It is an understandable misconfiguration, but not something desirable in production.
What's the reason you cannot increase the limit?
It is a soft limit, and I can. Running 'ulimit -u 3072' and then re-running lit causes these failures to go away. My concern is that a soft process limit of 1024 is a common default (at least on any RedHat-derived Linux distribution) regardless of the number of cores on the machine. And, obviously, parallel makes are still very common.
Regardless, do you think it would be reasonable for lit to adjust the soft process limit by default to avoid these kinds of issues, at least when running our regression tests?
> From: "Rui Ueyama" <ruiu@google.com>
> To: "Hal Finkel" <hfinkel@anl.gov>
> Cc: "LLVM Developers" <llvm-dev@lists.llvm.org>, "Rafael Espindola" < rafael.espindola@gmail.com>
> Sent: Thursday, October 1, 2015 12:55:20 PM
> Subject: Re: lld and thread over-subscription
>
>
> I honestly think that the ulimit of 1024 max threads is too strict
> for 48 core machine. Processes are independent each other, so it is
> not strange for them to spawn as many threads as the number of
> cores.
It is an understandable misconfiguration, but not something desirable in
production.
> What's the reason you cannot increase the limit?
>
It is a soft limit, and I can. Running 'ulimit -u 3072' and then
re-running lit causes these failures to go away. My concern is that a soft
process limit of 1024 is a common default (at least on any RedHat-derived
Linux distribution) regardless of the number of cores on the machine. And,
obviously, parallel makes are still very common.
Regardless, do you think it would be reasonable for lit to adjust the soft
process limit by default to avoid these kinds of issues, at least when
running our regression tests?
Yes, I do. If we can avoid the issue by adjusting the soft limit in lit, I
don't see any reason to not do that.
> From: "Rui Ueyama" < ruiu@google.com >
> To: "Hal Finkel" < hfinkel@anl.gov >
> Cc: "LLVM Developers" < llvm-dev@lists.llvm.org >, "Rafael
> Espindola" < rafael.espindola@gmail.com >
> Sent: Thursday, October 1, 2015 12:55:20 PM
> Subject: Re: lld and thread over-subscription
>
>
> I honestly think that the ulimit of 1024 max threads is too strict
> for 48 core machine. Processes are independent each other, so it is
> not strange for them to spawn as many threads as the number of
> cores.
It is an understandable misconfiguration, but not something desirable
in production.
> What's the reason you cannot increase the limit?
>
It is a soft limit, and I can. Running 'ulimit -u 3072' and then
re-running lit causes these failures to go away. My concern is that
a soft process limit of 1024 is a common default (at least on any
RedHat-derived Linux distribution) regardless of the number of cores
on the machine. And, obviously, parallel makes are still very
common.
Regardless, do you think it would be reasonable for lit to adjust the
soft process limit by default to avoid these kinds of issues, at
least when running our regression tests?
Yes, I do. If we can avoid the issue by adjusting the soft limit in
lit, I don't see any reason to not do that.
I honestly think that the ulimit of 1024 max threads is too strict for 48
core machine. Processes are independent each other, so it is not strange
for them to spawn as many threads as the number of cores. What's the reason
you cannot increase the limit?
Yeah, this is it. We've run into this internally on our linux bots.
Basically, the threading abstractions inside LLD spawn #cores threads for
their thread pool as one of the very first things. So if your build is #cores wide, you end up with #cores ^ 2 threads total.
The simplest solutions is just upping the ulimit. This may be something we
can even do inside lit so users automatically see it.
Beyond that, changes to LLD could ameliorate this; fundamentally though it
has to do with thread pools knowing how many threads they need to spin up.
A nasty solution could be an environment variable like LLD_NUM_THREADS. We
could also have a command line flag, and do something like `%lld` in the
tests like we do for clang like `%clang_cc1`, where some extra stuff is
inserted in the expansion telling lld to use a smaller thread count (for
the tests, --num-threads=1 would be fine I think).
I honestly think that the ulimit of 1024 max threads is too strict
for 48 core machine. Processes are independent each other, so it is
not strange for them to spawn as many threads as the number of
cores. What's the reason you cannot increase the limit?
Yeah, this is it. We've run into this internally on our linux bots.
Basically, the threading abstractions inside LLD spawn #cores
threads for their thread pool as one of the very first things. So if
your build is #cores wide, you end up with #cores ^ 2 threads total.
The simplest solutions is just upping the ulimit. This may be
something we can even do inside lit so users automatically see it.
> From: "Sean Silva" <chisophugis@gmail.com>
> To: "Rui Ueyama" <ruiu@google.com>
> Cc: "Hal Finkel" <hfinkel@anl.gov>, "LLVM Developers" < llvm-dev@lists.llvm.org>
> Sent: Friday, October 2, 2015 9:37:17 PM
> Subject: Re: [llvm-dev] lld and thread over-subscription
>
>
>
>
>
> I honestly think that the ulimit of 1024 max threads is too strict
> for 48 core machine. Processes are independent each other, so it is
> not strange for them to spawn as many threads as the number of
> cores. What's the reason you cannot increase the limit?
>
>
> Yeah, this is it. We've run into this internally on our linux bots.
> Basically, the threading abstractions inside LLD spawn #cores
> threads for their thread pool as one of the very first things. So if
> your build is #cores wide, you end up with #cores ^ 2 threads total.
>
>
> The simplest solutions is just upping the ulimit. This may be
> something we can even do inside lit so users automatically see it.
r249161 should do exactly this.
Thanks. Apologies for the issue, ... when we ran into this internally we
should have done just such a fix to avoid the yak shaving for the next guy.
Not sure why that didn't happen.