Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1X1fuf-0004oh-ND for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Jun 2014 18:02:45 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1X1fue-0000wN-Kj for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Jun 2014 18:02:44 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1X1fmr-0000bn-Hd for pgsql-hackers@postgresql.org; Mon, 30 Jun 2014 17:54:41 +0000 Received: from mail.anarazel.de ([217.115.131.40]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1X1fmo-0006Dq-HI for pgsql-hackers@postgresql.org; Mon, 30 Jun 2014 17:54:39 +0000 Received: by mail.anarazel.de (Postfix, from userid 108) id C78F54F0006; Mon, 30 Jun 2014 19:54:37 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on mail X-Spam-Level: X-Spam-Status: No, score=-5.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from anarazel.de (p54AF441C.dip0.t-ipconnect.de [84.175.68.28]) (Authenticated sender: andres@anarazel.de) by mail.anarazel.de (Postfix) with ESMTPSA id 98C4D4F0004; Mon, 30 Jun 2014 19:54:34 +0200 (CEST) Received: by anarazel.de (Postfix, from userid 1000) id 2F93F10044F; Mon, 30 Jun 2014 19:54:34 +0200 (CEST) Date: Mon, 30 Jun 2014 19:54:34 +0200 From: Andres Freund To: Tom Lane Cc: Robert Haas , Peter Geoghegan , Pg Hackers , Ants Aasma Subject: Re: better atomics - v0.5 Message-ID: <20140630175434.GM21422@awork2.anarazel.de> References: <20140626102006.GB1926@awork2.anarazel.de> <54412.1403808435@sss.pgh.pa.us> <20140626190405.GA21422@awork2.anarazel.de> <20140627180033.GF18288@awork2.anarazel.de> <20140628082559.GB6450@awork2.anarazel.de> <11914.1404147250@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <11914.1404147250@sss.pgh.pa.us> X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 2014-06-30 12:54:10 -0400, Tom Lane wrote: > Robert Haas writes: > > ... this again is my point: why can't we make the same argument about > > two spinlocks situated on the same cache line? I don't have a bit of > > trouble believing that doing the same thing with a couple of spinlocks > > could sometimes work out well, too, but Tom is adamantly opposed to > > that. > > I think you might be overstating my position here. What I'm concerned > about is that we be sure that spinlocks are held for a sufficiently short > time that it's very unlikely that we get pre-empted while holding one. > I don't have any particular bright line about how short a time that is, > but more than "a few instructions" worries me. As you say, the Linux > kernel is a bad example to follow because it hasn't got a risk of losing > its timeslice while holding a spinlock. Well, they actually have preemptable and irq-interruptile versions for some of these locks, but whatever :). > So ISTM the question we ought to be asking is whether atomic operations > have bounded execution time, or more generally what the distribution of > execution times is likely to be. I'd be OK with an answer that includes > "sometimes it can be long" so long as "sometimes" is "pretty damn > seldom". I think it ranges from 'never' to 'sometimes, but pretty darn seldom'. Depending on the platform and emulation. And, leaving the emulation and badly written code aside, there's no issue with another backend sleeping while the atomic variable needs to be modified. > Spinlocks have a nonzero risk of taking a long time already, since we > can't entirely prevent the possibility of losing our timeslice while > holding one. The issue here is just to be sure that that happens seldom > enough that it doesn't cause performance problems. If we fail to do that > we might negate all the desired performance improvements from adopting > atomic ops in the first place. I think individual patches will have to stand up to a test like this. Modifying a atomic variable inside a spinlock is only going to be worth it if it allows to avoid spinlocks alltogether in 95%+ of the time. Greetings, Andres Freund -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers