Re: vacuum as flags in PGPROC - Mailing list pgsql-patches

From Tom Lane
Subject Re: vacuum as flags in PGPROC
Date
Msg-id 2453.1193236277@sss.pgh.pa.us
Whole thread Raw
In response to Re: vacuum as flags in PGPROC  (Alvaro Herrera <alvherre@commandprompt.com>)
Responses Re: vacuum as flags in PGPROC  (Alvaro Herrera <alvherre@commandprompt.com>)
List pgsql-patches
Alvaro Herrera <alvherre@commandprompt.com> writes:
> I'm wondering if it's safe to do something like
> MyProc->vacuumFlags |= PROC_FOR_XID_WRAPAROUND
> without holding the ProcArrayLock.

This seems a bit itchy.

One thing I'd be worried about is processors that implement that by
fetching the whole word containing the field, setting the bit, and
storing back the whole word.  (I believe some RISC processors are likely
to do it like that.)  This would mean that it'd work OK only as long as
no other process was concurrently changing any field that happened to be
in the same word, which is the kind of requirement that seems horribly
fragile.  You could probably fix that by declaring the field as
sig_atomic_t.  Maybe better, just make it int.

Another problem is that if you don't take a lock then there's no memory
fence instructions executed, which would create issues around how soon
other processors would see the effects of the change.  While that might
not be critical for the vacuum flags, it still seems a bit worrisome.

Given that you're only changing these flags twice per vacuum, it doesn't
seem worth taking any risks by not taking a lock ...

            regards, tom lane

pgsql-patches by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: vacuum as flags in PGPROC
Next
From: Alvaro Herrera
Date:
Subject: Re: vacuum as flags in PGPROC