Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dHxBl-0004mR-QO for pgsql-hackers@arkaria.postgresql.org; Mon, 05 Jun 2017 18:57:17 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dHxBl-0005Xc-5B for pgsql-hackers@arkaria.postgresql.org; Mon, 05 Jun 2017 18:57:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dHxBk-0005VX-G8 for pgsql-hackers@postgresql.org; Mon, 05 Jun 2017 18:57:16 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dHxBh-0005bE-Cm for pgsql-hackers@postgresql.org; Mon, 05 Jun 2017 18:57:16 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v55IvAAF028315; Mon, 5 Jun 2017 14:57:10 -0400 From: Tom Lane To: Robert Haas cc: "pgsql-hackers@postgresql.org" Subject: Re: shm_toc_lookup API In-reply-to: References: <9697.1496675981@sss.pgh.pa.us> <16984.1496679541@sss.pgh.pa.us> Comments: In-reply-to Robert Haas message dated "Mon, 05 Jun 2017 13:10:44 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <28313.1496689030.1@sss.pgh.pa.us> Date: Mon, 05 Jun 2017 14:57:10 -0400 Message-ID: <28314.1496689030@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-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Robert Haas writes: > On Mon, Jun 5, 2017 at 12:19 PM, Tom Lane wrote: >> In practice it probably can't fail even if 64-bit reads aren't atomic, >> simply because we'll never have enough entries in a shm_toc to make the >> high-order half ever change. But that just begs the question why the >> field is declared Size rather than int. I think we should make it the >> latter. > Yeah. I think a shm_toc with more than 2^10 entries would probably > perform badly enough that somebody would rewrite this entire module, > so we don't really need to worry about having more than 2^31. > Changing to int (or uint32) seems fine. Done with uint32. >> I am also thinking that most of the shm_toc functions need to have the >> toc pointers declared as "volatile *", but particularly shm_toc_lookup. (actually, they do already use volatile pointers, except for shm_toc_lookup) >> That read_barrier call might prevent the hardware from reordering >> accesses, but I don't think it stops the compiler from doing so. > If it doesn't prevent both the hardware and the compiler from > reordering, it's broken. See the comments for pg_read_barrier() in > atomics.h. Meh. Without volatile, I think that the compiler would be within its rights to elide the nentry local variable and re-fetch toc->toc_nentry each time through the loop. It'd be unlikely to do so, granted, but I'm not convinced that pg_read_barrier() would prevent that. However, as long as the write barrier in shm_toc_insert does what it's supposed to, I think we'd be safe even if that happened. So probably it's a moot point. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers