Spinlock thrashing with libthr

John Baldwin jhb at freebsd.org
Mon Apr 17 13:08:25 UTC 2006


On Friday 14 April 2006 07:17 pm, Kris Kennaway wrote:
> On Fri, Apr 14, 2006 at 06:43:18PM -0400, Kris Kennaway wrote:
> > I ran a modified version of the thr1 stress test on a quad amd64,
> > which spawns 256 threads (using libthr), each of which loops doing
> > getpid() 10000 times.  The system spends essentially 100% of the time
> > in the kernel.  Profiling with hwpmc shows that the system is spending
> > about 60% time in _mtx_lock_spin().
>
> Turns out this is because of contention for the PROC_LOCK, which means
> lots of processes sleeping.  Using getuid() instead (which doesn't
> acquire locks) does not show contention.  Thanks to rwatson for
> figuring it out.

Or drop COMPAT_43 from your kernel config so getpid() doesn't try to
read the parent process' pid.  Still, I might be able to make this better
by redoing the adaptive spinning to happen before we grab the turnstile
lock (there are some other reasons this would be beneficial, such as
simplifying the rwlock adaptive code for example).

-- 
John Baldwin <jhb at FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve"  =  http://www.FreeBSD.org


More information about the freebsd-current mailing list