From owner-freebsd-arch@FreeBSD.ORG Sat Aug 18 12:33:32 2007 Return-Path: Delivered-To: freebsd-arch@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9105F16A468 for ; Sat, 18 Aug 2007 12:33:32 +0000 (UTC) (envelope-from pjd@garage.freebsd.pl) Received: from mail.garage.freebsd.pl (arm132.internetdsl.tpnet.pl [83.17.198.132]) by mx1.freebsd.org (Postfix) with ESMTP id 6DD3E13C4B3 for ; Sat, 18 Aug 2007 12:33:31 +0000 (UTC) (envelope-from pjd@garage.freebsd.pl) Received: by mail.garage.freebsd.pl (Postfix, from userid 65534) id 55CC145685; Sat, 18 Aug 2007 14:01:57 +0200 (CEST) Received: from localhost (154.81.datacomsa.pl [195.34.81.154]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.garage.freebsd.pl (Postfix) with ESMTP id BF8CC45683 for ; Sat, 18 Aug 2007 14:01:52 +0200 (CEST) Date: Sat, 18 Aug 2007 14:00:56 +0200 From: Pawel Jakub Dawidek To: freebsd-arch@FreeBSD.org Message-ID: <20070818120056.GA6498@garage.freebsd.pl> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="/9DWx/yDrRhgMJTb" Content-Disposition: inline User-Agent: Mutt/1.4.2.3i X-PGP-Key-URL: http://people.freebsd.org/~pjd/pjd.asc X-OS: FreeBSD 7.0-CURRENT i386 X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on mail.garage.freebsd.pl X-Spam-Level: X-Spam-Status: No, score=-2.6 required=3.0 tests=BAYES_00 autolearn=ham version=3.0.4 Cc: Subject: Lockless uidinfo. X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Aug 2007 12:33:32 -0000 --/9DWx/yDrRhgMJTb Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi. The patch below remove per-uidinfo locks: http://people.freebsd.org/~pjd/patches/uidinfo_lockless.patch With the patch uidinfo is handled using atomics only and no locks (except for the global hash lock, which is not really important, as it's not used in the fast paths). I needed to change ui_sbsize from rlim_t (64bit) to long, because we don't have 64bit atomics on all archs, and because sbsize represents size in bytes, it can't go beyond 32bit on 32bit archs (PAE might be a bit of a problem). I changed maxval argument in chgproccnt() from int to rlim_t, as this is what is passed to the function. In simple ping-pong test on unix domain socket, uidinfo lock was highly contented: max total wait_total count avg wait_avg cnt_hold cnt_= lock name 1508 3242859 96267052 1467476 2 65 374553 10247= 43 /usr/src/sys/kern/kern_resource.c:1339 (sleep mutex:sleep mtxpool) The ping-pong program you can find here: http://people.freebsd.org/~pjd/misc/unixpingpong.c At the end we reduced uidinfo structure size by 8 bytes and gain no measurable performance improvements:) Yes, I wasn't able to measure anything interesting, unfortunately, but I still believe the patch should be committed, as I'm sure there are workloads that will see improvements - note that uidinfo structure is per-uid, so if there are thousands of processes running with the same uid, they all need to fight for this one lock. Not only contention is important, but also the fact that number of atomic operations in chgsbsize() and chgproccnt() functions was reduced from 2 to 1. Ok, while writting this e-mail I came up with a better benchmark: http://people.freebsd.org/~pjd/misc/unixpingpong2.c This one doesn't do ping-pong between two processes, but within one proccess only. This way we eliminate cost of context switches. I was running 8 such processes (I tested it on a 8way machine) and here are the results: x ./uidinfo1.txt + ./uidinfo2.txt +--------------------------------------------------------------------------= ----+ |x = +| |xx = ++| |xx = ++| |A| = |A| +--------------------------------------------------------------------------= ----+ N Min Max Median Avg Stddev x 5 402742 416417 406216 408269.2 5388.3485 + 5 1561566 1575987 1568964 1569767 5853.1399 Difference at 95.0% confidence 1.1615e+06 +/- 8204.54 284.493% +/- 2.00959% (Student's t, pooled s =3D 5625.55) As you can see this was just a matter of good benchmark - here we can see 284% performance improvement, yay:) --=20 Pawel Jakub Dawidek http://www.wheel.pl pjd@FreeBSD.org http://www.FreeBSD.org FreeBSD committer Am I Evil? Yes, I Am! --/9DWx/yDrRhgMJTb Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.4 (FreeBSD) iD8DBQFGxt94ForvXbEpPzQRAs2+AJ9jS36KZJYz3FT/Bi77cgpxp2KtbgCgjKQx OatG9wUb6zvM2mTPvgHyfsQ= =+fmg -----END PGP SIGNATURE----- --/9DWx/yDrRhgMJTb--