Guido Ostkamp <postgresql@ostkamp.fastmail.fm> writes:
> Would this work or is there a special reason why the original check was
> done with lock held?
This will fail, very nastily, on multiple-CPU machines with weak memory
ordering guarantees. You can't assume you are seeing an up-to-date
value of the flag bit if you don't take the spinlock first.
There are places where we can get away with such things because a
slightly stale answer is okay, but not in BufferSync(). Failing to
include a dirty page in the checkpoint is fatal.
regards, tom lane