X-Recipient: archive-cygwin@delorie.com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:subject:references:to:from:message-id:date
	:mime-version:in-reply-to:content-type
	:content-transfer-encoding; q=dns; s=default; b=xRyVFR9NJrt7+Jz6
	0EbQf/0r/am+j5wLcLVDN4/2jGtks8IbYaNUvir1QP7loGUqpjywMr3MjziqEhPA
	QfOYtP7WPOTCGHCkZGDUfzJOb7XmhS31eiVn0oOEV+2lTlxLHTbRBeEK5AGsCwoW
	F2EECUyXIfgvnOxkTk2Ns9VL1wA=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:subject:references:to:from:message-id:date
	:mime-version:in-reply-to:content-type
	:content-transfer-encoding; s=default; bh=0a0rR+VhT7n4+yUsJ7JOF3
	TQ2+I=; b=Fnz5qQXi/Fk3H+qwa+w6X4uYZMIPssf0NvQfpL3HpLiLYczbF2Jbqt
	w1OcED2xog70Qm5hXaCnJj8BNNXKC/bf2v3UDYhK0g/lmGa/7YAzz+Be4+KdodfS
	wyMb1JSSN2N0rV3INicj2FSyj/sxogwcJIhEmN/T18LTs3FDLlMSE=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-0.0 required=5.0 tests=AWL,BAYES_50,KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2
X-HELO: m0.truegem.net
Subject: Re: Cygwin multithreading performance
References: <CABPLASTtRK4mNxh0M_AnZgjJQ15kWPx+L=U=VCU3Wwi7jV_57A@mail.gmail.com> <564E3017.90205@maxrnd.com> <CABPLASTLrH_udLuu2F-m5P6dkENW1Z4YHEudp4NG0-FGLJgPMg@mail.gmail.com> <5650379B.4030405@maxrnd.com> <20151121105301.GE2755@calimero.vinschen.de> <5652C402.7040006@maxrnd.com> <24780-1448274431-7444@sneakemail.com> <5653B52B.5000804@maxrnd.com> <20151126093427.GJ2755@calimero.vinschen.de>
To: cygwin@cygwin.com
From: Mark Geisert <mark@maxrnd.com>
Message-ID: <5656DDEF.9070603@maxrnd.com>
Date: Thu, 26 Nov 2015 02:24:47 -0800
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0 SeaMonkey/2.39
MIME-Version: 1.0
In-Reply-To: <20151126093427.GJ2755@calimero.vinschen.de>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Corinna Vinschen wrote:
> On Nov 23 16:54, Mark Geisert wrote:
>> John Hein wrote:
>>> Mark Geisert wrote at 23:45 -0800 on Nov 22, 2015:
>>>   > Corinna Vinschen wrote:
>>>   > > On Nov 21 01:21, Mark Geisert wrote:
>>>   > [...] so I wonder if there's
>>>   > >> some unintentional serialization going on somewhere, but I don't know yet
>>>   > >> how I could verify that theory.
>>>   > >
>>>   > > If I'm allowed to make an educated guess, the big serializer in Cygwin
>>>   > > are probably the calls to malloc, calloc, realloc, free.  We desperately
>>>   > > need a new malloc implementation better suited to multi-threading.
[...]
>>>
>>> Someone recently mentioned on this list they were working on porting
>>> jemalloc.  That would be a good choice.
>>
>> Indeed; thanks for the reminder.  Somehow I hadn't followed that thread.
>
> Indeed^2.  Did you look into the locking any further to see if there's
> more than one culprit?  I guess we've a rather long way to a "lock-less
> kernel"...

It took me a while to figure out what I wanted to see in the strace 
logs.  I ended up adding a small patch to pthread_mutex::lock() to 
record a timestamp on entry, and also log that in the pthread_printf() 
near the end of the method.  With that I'm able to see how long a thread 
has to wait for a lock before actually acquiring it.  That will allow me 
to unravel the sequence of locking and unlocking and give stats for all 
threads and/or locks.  That could be generally useful to evaluate 
different memory allocators or different locking strategies using the 
same allocator.

But that is just groundwork to identifying which locks are suffering the 
most contention.  To identify them at source level I think I'll also 
need to record the caller's RIP when they are being locked.

In the raw strace data I'm looking at for the OP's testcase, I can see a 
lot of cases where a thread wants a lock but is delayed for milliseconds 
before getting ahold of it.  I can't say ATM whether it's just one or a 
few locks suffering this way, or more.  Work continues :).

..mark

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

