I suggest using a conditional lock on the buffer, which would be more
appropriate here. Additionally, the function should return whether
the buffer is marked as dirty, the number of buffers marked as dirty.
This change would also make pg_buffercache_mark_dirty_{relation, all}
behave more consistently with pg_buffercache_evict_{relation,all}.
Lastly, `CHECK_FOR_INTERRUPTS()` should be added inside the loop over
`NBuffers` to ensure it can be interrupted during long-running
operations.
Best regards,
Yuhang Qiu