Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aYzjp-0003aK-Mh for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Feb 2016 17:30:05 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aYzjo-0002Eh-J0 for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Feb 2016 17:30:04 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aYzjo-0002Ea-0N for pgsql-bugs@postgresql.org; Thu, 25 Feb 2016 17:30:04 +0000 Received: from mail.anarazel.de ([217.115.131.40]) by makus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1aYzjl-0003Vy-7r for pgsql-bugs@postgresql.org; Thu, 25 Feb 2016 17:30:02 +0000 Received: from intern.anarazel.de (104-2-144-147.lightspeed.sntcca.sbcglobal.net [104.2.144.147]) (Authenticated sender: andres@anarazel.de) by mail.anarazel.de (Postfix) with ESMTPSA id 2F3093B2D8B; Thu, 25 Feb 2016 18:30:00 +0100 (CET) Date: Thu, 25 Feb 2016 09:29:58 -0800 From: Andres Freund To: Tom Lane Cc: "Shulgin, Oleksandr" , Alvaro Herrera , chris.tessels@inergy.nl, Pg Bugs Subject: Re: BUG #13985: Segmentation fault on PREPARE TRANSACTION Message-ID: <20160225172958.t7pdlt4puydblchx@alap3.anarazel.de> References: <20160224125824.2573.27524@wrigleys.postgresql.org> <20160224205237.GA438345@alvherre.pgsql> <20160224215221.bbbduc5nelq7tf6s@alap3.anarazel.de> <5857.1456411909@sss.pgh.pa.us> <20160225170311.qi3h6zbzf4mscdtj@alap3.anarazel.de> <29282.1456420806@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <29282.1456420806@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Hi, On 2016-02-25 12:20:06 -0500, Tom Lane wrote: > Andres Freund writes: > > On 2016-02-25 09:51:49 -0500, Tom Lane wrote: > >> Marking pgprocno volatile is silly. What *is* missing is this: > >> > >> - ProcArrayStruct *arrayP = procArray; > >> + volatile ProcArrayStruct *arrayP = procArray; > > > Well, that'll also force arrayP->numProcs to be loaded from memory every > > loop iteration. Not sure if we really want that. > > I think we do. The entire point here is not to assume that that storage > isn't changing. Well, but what does it buy us? Given there's no locks involved, the index < arrayP->numProcs check fundamentally cannot be anything than an optimization, preventing us from looking at all PGPROC/PGXACT entries, no? Reloading it at every loop iteration doesn't seem to give us anything other than some sense of false security? It's a) perfectly possible that numProcs is outdated because we're hitting a local cacheline whereas another backend has it modified locally (store buffers) b) that it's decremented after we entered the loop. > > What bothers me about this right now is that we currently write the > > pgprocno array with: > > memmove(&arrayP->pgprocnos[index + 1], &arrayP->pgprocnos[index], > > (arrayP->numProcs - index) * sizeof(int)); > > arrayP->pgprocnos[index] = proc->pgprocno; > > arrayP->numProcs++; > > afaics there's absolutely no guarantee that memmov() will only use > > aligned sizeof(int) writes. > > Ugh. That's a separate problem, but yes, it's a problem. While it's a separate bug, it seems to me that this could just as well be the reason for crashes triggering this report :/. If pgprocno points behind the end of the allPgXact array, it's quite possible that we're reading zeroes :( > Seems like we can either (1) get rid of that memmove in favor of > a handwritten loop, or (2) give up on unlocked access to the > pgprocnos array. Which performance hit would you rather take? I think 1), while it'll be noticeable, it's probably going to degrade much more gracefully. I think we additionally also should add a security check to MinimumActiveBackends that prevents a pgprocno above the max number of backends to be seen as valid. - Andres -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs