From owner-svn-src-all@FreeBSD.ORG Fri Jul 27 14:49:20 2012 Return-Path: Delivered-To: svn-src-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 621A1106566C; Fri, 27 Jul 2012 14:49:20 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from cell.glebius.int.ru (glebius.int.ru [81.19.64.117]) by mx1.freebsd.org (Postfix) with ESMTP id CFAE08FC0A; Fri, 27 Jul 2012 14:49:19 +0000 (UTC) Received: from cell.glebius.int.ru (localhost [127.0.0.1]) by cell.glebius.int.ru (8.14.5/8.14.5) with ESMTP id q6REnIRr036734; Fri, 27 Jul 2012 18:49:18 +0400 (MSK) (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by cell.glebius.int.ru (8.14.5/8.14.5/Submit) id q6REnIIK036733; Fri, 27 Jul 2012 18:49:18 +0400 (MSK) (envelope-from glebius@FreeBSD.org) X-Authentication-Warning: cell.glebius.int.ru: glebius set sender to glebius@FreeBSD.org using -f Date: Fri, 27 Jul 2012 18:49:18 +0400 From: Gleb Smirnoff To: Bruce Evans Message-ID: <20120727144918.GV14135@FreeBSD.org> References: <201207270916.q6R9Gm23086648@svn.freebsd.org> <20120727111237.GC2676@deviant.kiev.zoral.com.ua> <20120727111904.GQ14135@FreeBSD.org> <20120727221529.K7360@besplex.bde.org> <20120727124534.GT14135@FreeBSD.org> <20120727232757.X7759@besplex.bde.org> MIME-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline In-Reply-To: <20120727232757.X7759@besplex.bde.org> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: Konstantin Belousov , svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org Subject: Re: svn commit: r238828 - head/sys/sys X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Jul 2012 14:49:20 -0000 On Fri, Jul 27, 2012 at 11:30:58PM +1000, Bruce Evans wrote: B> > On Fri, Jul 27, 2012 at 10:32:55PM +1000, Bruce Evans wrote: B> > B> I just noticed that there is a technical problem -- the count is read B> > B> unlocked in the KASSERT. And since the comparision is for equality, B> > B> if you lose the race reading the count when it reaches the overflow B> > B> threshold, then you won't see it overflow unless it wraps again and B> > B> you win the race next time (or later). atomic_cmpset could be used B> > B> to clamp the value at the max, but that is too much for an assertion. B> > B> > We have discussed that. As alternative I proposed: B> > B> > @@ -50,8 +51,14 @@ B> > static __inline void B> > refcount_acquire(volatile u_int *count) B> > { B> > +#ifdef INVARIANTS B> > + u_int old; B> > + old = atomic_fetchadd_int(count, 1); B> > + KASSERT(old < UINT_MAX, ("refcount %p overflowed", count)); B> > +#else B> > atomic_add_acq_int(count, 1); B> > +#endif B> > } B> > B> > Konstantin didn't like that production code differs from INVARIANTS. B> > B> > So we ended with what I committed, advocating to the fact that although B> > assertion is racy and bad panics still can occur, the "good panics" B> > would occur much more often, and a single "good panic" is enough to B> > show what's going on. B> B> Yes, it is excessive. B> B> So why do people even care about this particular overflow? There are B> many integers that can overflow in the kernel. Some binary wraparounds B> are even intentional. Because "negative refcount" panic is very confusing in the case when one got overflow. http://lists.freebsd.org/pipermail/freebsd-net/2012-July/032822.html -- Totus tuus, Glebius.