Re: [COMMITTERS] pgsql: Do all accesses to shared buffer headers through

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Neil Conway <neilc(at)samurai(dot)com>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: [COMMITTERS] pgsql: Do all accesses to shared buffer headers through
Date: 2005-10-13 18:11:59
Message-ID: 20051013181154.GB6080@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

On Wed, Oct 12, 2005 at 11:49:47PM -0400, Tom Lane wrote:
> That would certainly be better if possible, but AFAIK it's not.
> (Perhaps there is a gcc-specific hack, but certainly not one that's
> portable to all compilers. "volatile" is the only tool the C standard
> gives us.)

Indeed. The linux kernel defines the following:

/* Optimization barrier */
/* The "volatile" is due to gcc bugs */
#define barrier() __asm__ __volatile__("": : :"memory")

The memory keyword (as the gcc docs state):

> If your assembler instruction modifies memory in an unpredictable
> fashion, add 'memory' to the list of clobbered registers. This will
> cause GNU CC to not keep memory values cached in registers across the
> assembler instruction.

They use this bit in all the spinlock and other locking code
specifically for this purpose. You can do things like:

do { barrier(); } while( condition );

where condition uses any memory variable and it will reread it
everytime, just as if the variable was volatile.

> have seen the bug. Still, I think we have to do the volatile pointers
> in order to guarantee correct results on non-gcc compilers, so it's not
> clear that there's any point in pursuing the question of whether gcc by
> itself could offer a nicer solution.

Yes, we need to look for solutions for other compilers. We just need to
be careful and have people check the spinlock code carefully when they
use other compilers. Maybe in the porting guide?

--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

In response to

Browse pgsql-committers by date

  From Date Subject
Next Message User Agoldshuv 2005-10-13 18:59:31 bizgres - bizgres: When COPY fails to start, the loader will now include
Previous Message Alvaro Herrera 2005-10-13 18:06:47 Re: [COMMITTERS] pgsql: Back out this because of fear of changing error strings: This

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Fuhr 2005-10-13 18:27:53 Re: BUG #1962: ECPG and VARCHAR
Previous Message Alvaro Herrera 2005-10-13 18:06:47 Re: [COMMITTERS] pgsql: Back out this because of fear of changing error strings: This