From owner-freebsd-net@FreeBSD.ORG Wed Aug 17 02:35:39 2005 Return-Path: X-Original-To: net@freebsd.org Delivered-To: freebsd-net@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 77F2C16A41F; Wed, 17 Aug 2005 02:35:39 +0000 (GMT) (envelope-from max@love2party.net) Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.186]) by mx1.FreeBSD.org (Postfix) with ESMTP id D746843D46; Wed, 17 Aug 2005 02:35:38 +0000 (GMT) (envelope-from max@love2party.net) Received: from p54A3D793.dip.t-dialin.net [84.163.215.147] (helo=donor.laier.local) by mrelayeu.kundenserver.de with ESMTP (Nemesis), id 0ML29c-1E5DmC3q09-0005Ri; Wed, 17 Aug 2005 04:35:36 +0200 From: Max Laier To: Luigi Rizzo Date: Wed, 17 Aug 2005 04:35:19 +0200 User-Agent: KMail/1.8.2 References: <20050816170519.A74422@xorpc.icir.org> In-Reply-To: <20050816170519.A74422@xorpc.icir.org> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart1156185.pn3pmraMmZ"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <200508170435.34688.max@love2party.net> X-Provags-ID: kundenserver.de abuse@kundenserver.de login:61c499deaeeba3ba5be80f48ecc83056 Cc: arch@freebsd.org, net@freebsd.org Subject: Re: duplicate read/write locks in net/pfil.c and netinet/ip_fw2.c X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Aug 2005 02:35:39 -0000 --nextPart1156185.pn3pmraMmZ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Wednesday 17 August 2005 02:05, Luigi Rizzo wrote: > [apologies for the cross post but it belongs both to arch and net.] > > I notice that net/pfil.c and netinet/ip_fw2.c have two copies of > aisimilar but slightly different implementation of > multiple-reader/single-writer locks, which brings up the question(s): > > 1. should we rather put this code in the generic kernel code so that other > subsystems could make use of it ? E.g. the routing table is certainly > a candidate, I have asked this several time on -arch and IRC, but never found anyone=20 willing to pursue it. However, the problem is ... > and especially > > 2. should we implement it right ? > > Both implementations are subject to starvation for the writers > (which is indeed a problem here, because we might want to modify > a ruleset and be prevented from doing it because of incoming traffic > that keeps readers active). > Also the PFIL_TRY_WLOCK will in fact be blocking if a writer > is already in - i have no idea how problematic is this in the > way it is actually used. =2E.. really this. I didn't find a clean way out of the starvation issue. = What=20 I do for pfil is that I set a flag and simply stop serving[2] shared reques= ts=20 once a writer waits for the lock. If a writer can't sleep[1] then we retur= n=20 EBUSY and don't. However, for pfil it's almost ever safe to assume that a= =20 write may sleep (as it is for most instances of this kind of sx-lock where= =20 you have BIGNUMxreads:1xwrite). [1] Note that there is a *big* difference between blocking and sleeping. =20 These two are usually confused. While it is almost always okay to block it= =20 is seldom okay to sleep. The existing sx(9) api has the problem that it=20 *sleeps* in the shared path which renders it unusable for this usecase (as = we=20 might be holding other locks and must not sleep in the shared path). =20 However, sleeping in the shared path is one (?the only?) way out of the=20 starvation problem - other than a problem specific as done for pfil. [2] See pfil(9) BUGS. =2D-=20 /"\ Best regards, | mlaier@freebsd.org \ / Max Laier | ICQ #67774661 X http://pf4freebsd.love2party.net/ | mlaier@EFnet / \ ASCII Ribbon Campaign | Against HTML Mail and News --nextPart1156185.pn3pmraMmZ Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (FreeBSD) iD8DBQBDAqJ2XyyEoT62BG0RAgM9AJ4kzFxHhG6gUCKDFwfaxNL4NeprdACfSzoW X33PNJnt6EzhMiEntWkt79A= =Ce2y -----END PGP SIGNATURE----- --nextPart1156185.pn3pmraMmZ--