[profiler] Require an ack of the previous sampling signal before sending another.
authorAlex Rønne Petersen <alexrp@xamarin.com>
Tue, 20 Jun 2017 01:13:20 +0000 (03:13 +0200)
committerAlex Rønne Petersen <alexrp@xamarin.com>
Tue, 20 Jun 2017 03:39:14 +0000 (05:39 +0200)
commitccd373f42986ac5346b305b02beb153c7f311234
treeabc1baa513fcd84255f01cdfa9ea92f4f8f687cf
parentbdfa3ef2cafa954f76a405ce3dc9d6ce39f46d42
[profiler] Require an ack of the previous sampling signal before sending another.

This avoids situations where we could end up filling the signal queue
completely, leading to the undocumented EAGAIN return value from pthread_kill,
which breaks ~everything in the STW/GC code because it thinks an error return
value from pthread_kill means the thread has exited.

The actual reason why this happened is that when a thread is suspended, we mask
all signals except the restart signal for that thread. This means that a
program with a large number of threads or where GC collections could take
longer than usual would end up with tens of thousands of sampling signals
queued up, eventually reaching the limit of the user-level signal queue (see
`ulimit -i` and `RLIMIT_SIGPENDING`).

We only do this on systems where we use real time signals. Non-RT signals do
not have this problem as the kernel will throttle them.
mono/mini/mini-posix.c
mono/utils/mono-threads.c
mono/utils/mono-threads.h