[threadpool] Prevent high CPU usage in certain conditions
authorMarek Habersack <grendel@twistedcode.net>
Mon, 14 Sep 2015 11:13:46 +0000 (13:13 +0200)
committerLudovic Henry <ludovic@xamarin.com>
Fri, 18 Sep 2015 17:26:34 +0000 (18:26 +0100)
commit6335b96646e2b816058b3d28840da27fa988d93e
treec21de72a8375f18dd85de2aeaf987724f6b2383a
parent66a191c86525560eec731a3c8329b10b4563831b
[threadpool] Prevent high CPU usage in certain conditions

Threadpool uses poll(2) to watch the file descriptors for activity but
it can sometimes miss that an fd went into error. When that happens the
poll call is interrupted with EAGAIN since the erroneous fd's events have
already been read and there's nothing left in the queue for it. That, in turn,
causes mono to run the loop so quickly that it uses 100% of the CPU. It happens,
for instance, with Xamarin Studio which can utilize two CPU cores to the full while
idling on the opening screen.

This commit makes sure to remove the descriptors with errors from the poll set and
thus preventing the syscall from being interrupted and returning EAGAIN.
mono/metadata/threadpool-ms-io.c