From owner-freebsd-current@freebsd.org Thu Nov 5 07:47:02 2015 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5B6FEA26E52 for ; Thu, 5 Nov 2015 07:47:02 +0000 (UTC) (envelope-from hps@selasky.org) Received: from mail.turbocat.net (heidi.turbocat.net [88.198.202.214]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 22F1114CE for ; Thu, 5 Nov 2015 07:47:01 +0000 (UTC) (envelope-from hps@selasky.org) Received: from laptop015.home.selasky.org (unknown [62.141.129.119]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.turbocat.net (Postfix) with ESMTPSA id 6B0C01FE023; Thu, 5 Nov 2015 08:46:53 +0100 (CET) Subject: Re: [PATCH] microoptimize by trying to avoid locking a locked mutex To: Mateusz Guzik , freebsd-current@freebsd.org References: <20151104233218.GA27709@dft-labs.eu> From: Hans Petter Selasky Message-ID: <563B09D5.6050000@selasky.org> Date: Thu, 5 Nov 2015 08:48:37 +0100 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <20151104233218.GA27709@dft-labs.eu> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Nov 2015 07:47:02 -0000 Hi, Did you test this patch works like expected with non x86 platforms? --HPS On 11/05/15 00:32, Mateusz Guzik wrote: > mtx_lock will unconditionally try to grab the lock and if that fails, > will call __mtx_lock_sleep which will immediately try to do the same > atomic op again. > > So, the obvious microoptimization is to check the state in > __mtx_lock_sleep and avoid the operation if the lock is not free. > > This gives me ~40% speedup in a microbenchmark of 40 find processes > traversing tmpfs and contending on mount mtx (only used as an easy > benchmark, I have WIP patches to get rid of it). > > Second part of the patch is optional and just checks the state of the > lock prior to doing any atomic operations, but it gives a very modest > speed up when applied on top of the __mtx_lock_sleep change. As such, > I'm not going to defend this part.