43#ifdef USE_ASSERT_CHECKING
44#include "catalog/pg_tablespace_d.h"
76#define BufHdrGetBlock(bufHdr) ((Block) (BufferBlocks + ((Size) (bufHdr)->buf_id) * BLCKSZ))
77#define BufferGetLSN(bufHdr) (PageGetLSN(BufHdrGetBlock(bufHdr)))
80#define LocalBufHdrGetBlock(bufHdr) \
81 LocalBufferBlockPointers[-((bufHdr)->buf_id + 2)]
84#define BUF_WRITTEN 0x01
85#define BUF_REUSABLE 0x02
87#define RELS_BSEARCH_THRESHOLD 20
95#define BUF_DROP_FULL_SCAN_THRESHOLD (uint64) (NBuffers / 32)
133#define SH_PREFIX refcount
134#define SH_ELEMENT_TYPE PrivateRefCountEntry
135#define SH_KEY_TYPE Buffer
137#define SH_HASH_KEY(tb, key) murmurhash32((uint32) (key))
138#define SH_EQUAL(tb, a, b) ((a) == (b))
139#define SH_SCOPE static inline
145#define REFCOUNT_ARRAY_ENTRIES 8
557 return ref->data.refcount;
599#define BufferIsPinned(bufnum) \
601 !BufferIsValid(bufnum) ? \
604 BufferIsLocal(bufnum) ? \
605 (LocalRefCount[-(bufnum) - 1] > 0) \
607 (GetPrivateRefCount(bufnum) > 0) \
665#ifdef USE_ASSERT_CHECKING
793 errmsg(
"cannot access temporary tables of other sessions")));
828 int b = -recent_buffer - 1;
934 errmsg(
"cannot access temporary tables of other sessions")));
941 forkNum, blockNum,
mode, strategy);
1018 if (
bmr.relpersistence ==
'\0')
1019 bmr.relpersistence =
bmr.rel->rd_rel->relpersistence;
1051 if (
bmr.relpersistence ==
'\0')
1052 bmr.relpersistence =
bmr.rel->rd_rel->relpersistence;
1334 persistence = rel->
rd_rel->relpersistence;
1344 forkNum, blockNum, strategy, &found);
1357 operation.
smgr = smgr;
1358 operation.
rel = rel;
1450#ifdef USE_ASSERT_CHECKING
1491 elog(
DEBUG2,
"limiting nblocks at %u from %u to %u",
1503 operation->
flags = flags;
1540 operation->
nblocks = *nblocks;
1639#ifdef USE_ASSERT_CHECKING
1771 elog(
ERROR,
"waiting for read operation that didn't read");
1877 int flags = operation->
flags;
2028 for (
int i = nblocks_done + 1;
i < operation->
nblocks;
i++)
2065 blocknum + nblocks_done,
2339 elog(
ERROR,
"buffer is pinned in InvalidateBuffer");
2590#ifdef USE_ASSERT_CHECKING
2655 limit =
Max(limit, 1);
2802 errmsg(
"cannot extend relation %s beyond %u blocks",
2866 (
errmsg(
"unexpected data beyond EOF in block %u of relation \"%s\"",
3141 if (
bufHdr->tag.blockNum == blockNum &&
3151 if (
bufHdr->tag.blockNum == blockNum &&
3223 if (strategy ==
NULL)
3269 ref->data.refcount++;
3349 int wait_backend_pgprocno =
buf->wait_backend_pgprocno;
3387 ref->data.refcount--;
3388 if (
ref->data.refcount == 0)
3428 ref->data.refcount++;
3445#define ST_SORT sort_checkpoint_bufferids
3446#define ST_ELEMENT_TYPE CkptSortItem
3447#define ST_COMPARE(a, b) ckpt_buforder_comparator(a, b)
3448#define ST_SCOPE static
3504 for (buf_id = 0; buf_id <
NBuffers; buf_id++)
3538 if (num_to_scan == 0)
3561 for (
i = 0;
i < num_to_scan;
i++)
3590 memset(s, 0,
sizeof(*s));
3827 elog(
DEBUG2,
"bgwriter ahead: bgw %u-%u strategy %u-%u delta=%ld lap=%d",
3839 elog(
DEBUG2,
"bgwriter ahead: bgw %u-%u strategy %u-%u delta=%ld lap=%d",
3852 elog(
DEBUG2,
"bgwriter behind: bgw %u-%u strategy %u-%u delta=%ld",
3869 elog(
DEBUG2,
"bgwriter initializing: strategy %u-%u",
3944 elog(
DEBUG2,
"bgwriter: alloc_est=%d too small, using min=%d + reusable_est=%d",
3990 elog(
DEBUG1,
"bgwriter: recent_alloc=%u smoothed=%.2f delta=%ld ahead=%d density=%.2f reusable_est=%d upcoming_est=%d scanned=%d wrote=%d reusable=%d",
4015 elog(
DEBUG2,
"bgwriter: cleaner density alloc=%u scan=%ld density=%.2f new smoothed=%.2f",
4176#ifdef USE_ASSERT_CHECKING
4216#ifdef USE_ASSERT_CHECKING
4325 result =
psprintf(
"[%03d] (rel=%s, blockNum=%u, flags=0x%" PRIx64 ", refcount=%u %d)",
4369 return bufHdr->tag.blockNum;
4446 reln->smgr_rlocator.locator.spcOid,
4447 reln->smgr_rlocator.locator.dbOid,
4448 reln->smgr_rlocator.locator.relNumber);
4532 reln->smgr_rlocator.locator.spcOid,
4533 reln->smgr_rlocator.locator.dbOid,
4534 reln->smgr_rlocator.locator.relNumber);
4638#ifdef PG_HAVE_8BYTE_SINGLE_COPY_ATOMICITY
4853 for (
i = 0;
i < n && cached;
i++)
4880 for (
i = 0;
i < n;
i++)
4901 for (
i = 0;
i < n;
i++)
4902 locators[
i] = rels[
i]->smgr_rlocator.locator;
4930 for (
j = 0;
j < n;
j++)
4950 if (rlocator ==
NULL)
5051 if (
bufHdr->tag.dbOid != dbid)
5055 if (
bufHdr->tag.dbOid == dbid)
5181 for (
i = 0;
i < nrels;
i++)
5214 for (
j = 0;
j < nrels;
j++)
5332 for (blkno = 0; blkno < nblocks; blkno++)
5384 char relpersistence;
5389 relpersistence = permanent ?
5460 if (
bufHdr->tag.dbOid != dbid)
5468 if (
bufHdr->tag.dbOid == dbid &&
5549 ref->data.refcount++;
6038 elog(
PANIC,
"cannot wait without a PGPROC structure");
6041 elog(
PANIC,
"queueing for lock while waiting on another one");
6509 elog(
ERROR,
"incorrect local pin count: %d",
6515 elog(
ERROR,
"incorrect local pin count: %d",
6600 elog(
ERROR,
"multiple backends attempting to wait for pincount 1");
6964#ifdef USE_ASSERT_CHECKING
6969 Assert((
char *) ptr >= page && (
char *) ptr < (page +
BLCKSZ));
7227 errmsg(
"could not write block %u of %s",
7231 errdetail(
"Multiple failures --- write error might be permanent.")));
7248 errcontext(
"writing block %u of relation \"%s\"",
7263 errcontext(
"writing block %u of relation \"%s\"",
7279 if (
n1.relNumber <
n2.relNumber)
7281 else if (
n1.relNumber >
n2.relNumber)
7284 if (
n1.dbOid <
n2.dbOid)
7286 else if (
n1.dbOid >
n2.dbOid)
7289 if (
n1.spcOid <
n2.spcOid)
7291 else if (
n1.spcOid >
n2.spcOid)
7392 if (
ba->blockNum <
bb->blockNum)
7394 if (
ba->blockNum >
bb->blockNum)
7410 if (
a->tsId <
b->tsId)
7412 else if (
a->tsId >
b->tsId)
7415 if (
a->relNumber <
b->relNumber)
7417 else if (
a->relNumber >
b->relNumber)
7420 else if (
a->forkNum <
b->forkNum)
7422 else if (
a->forkNum >
b->forkNum)
7425 else if (
a->blockNum <
b->blockNum)
7427 else if (
a->blockNum >
b->blockNum)
7444 if (
sa->progress <
sb->progress)
7446 else if (
sa->progress ==
sb->progress)
7496 pending->
tag = *tag;
7508#define ST_SORT sort_pending_writebacks
7509#define ST_ELEMENT_TYPE PendingWriteback
7510#define ST_COMPARE(a, b) buffertag_comparator(&a->tag, &b->tag)
7511#define ST_SCOPE static
7575 if (
cur->tag.blockNum ==
next->tag.blockNum)
7579 if (
cur->tag.blockNum + 1 !=
next->tag.blockNum)
7790 (*buffers_evicted)++;
7795 (*buffers_flushed)++;
7852 (*buffers_evicted)++;
7857 (*buffers_flushed)++;
7870 bool result =
false;
7997 (*buffers_dirtied)++;
7999 (*buffers_already_dirty)++;
8041 (*buffers_dirtied)++;
8043 (*buffers_already_dirty)++;
8067 uint8 handle_data_len;
8076 for (
int i = 0;
i < handle_data_len;
i++)
8181#define READV_COUNT_BITS 7
8182#define READV_COUNT_MASK ((1 << READV_COUNT_BITS) - 1)
8231 "PG_IOV_MAX is bigger than reserved space for error data");
8233 "PGAIO_RESULT_ERROR_BITS is insufficient for buffer_readv");
8278#ifdef USE_ASSERT_CHECKING
8299#undef READV_COUNT_BITS
8300#undef READV_COUNT_MASK
8309 uint8 flags,
bool failed,
bool is_temp,
8324#ifdef USE_ASSERT_CHECKING
8465 uint8 handle_data_len;
8595 errmsg(
"zeroing %u page(s) and ignoring %u checksum failure(s) among blocks %u..%u of relation \"%s\"",
8598 errdetail(
"Block %u held the first zeroed page.",
8600 errhint_plural(
"See server log for details about the other %d invalid block.",
8601 "See server log for details about the other %d invalid blocks.",
8616 msg_one =
_(
"invalid page in block %u of relation \"%s\"");
8617 msg_mult =
_(
"%u invalid pages among blocks %u..%u of relation \"%s\"");
8618 det_mult =
_(
"Block %u held the first invalid page.");
8619 hint_mult =
_(
"See server log for the other %u invalid block(s).");
8624 msg_one =
_(
"invalid page in block %u of relation \"%s\"; zeroing out page");
8625 msg_mult =
_(
"zeroing out %u invalid pages among blocks %u..%u of relation \"%s\"");
8626 det_mult =
_(
"Block %u held the first zeroed page.");
8627 hint_mult =
_(
"See server log for the other %u zeroed block(s).");
8632 msg_one =
_(
"ignoring checksum failure in block %u of relation \"%s\"");
8633 msg_mult =
_(
"ignoring %u checksum failures among blocks %u..%u of relation \"%s\"");
8634 det_mult =
_(
"Block %u held the first ignored page.");
8635 hint_mult =
_(
"See server log for the other %u ignored block(s).");
bool pgaio_wref_valid(PgAioWaitRef *iow)
PgAioHandle * pgaio_io_acquire(struct ResourceOwnerData *resowner, PgAioReturn *ret)
void pgaio_wref_clear(PgAioWaitRef *iow)
void pgaio_io_get_wref(PgAioHandle *ioh, PgAioWaitRef *iow)
void pgaio_io_set_flag(PgAioHandle *ioh, PgAioHandleFlags flag)
bool pgaio_have_staged(void)
bool pgaio_wref_check_done(PgAioWaitRef *iow)
ProcNumber pgaio_io_get_owner(PgAioHandle *ioh)
void pgaio_submit_staged(void)
void pgaio_wref_wait(PgAioWaitRef *iow)
void pgaio_io_release(PgAioHandle *ioh)
PgAioHandle * pgaio_io_acquire_nb(struct ResourceOwnerData *resowner, PgAioReturn *ret)
@ PGAIO_HCB_LOCAL_BUFFER_READV
@ PGAIO_HCB_SHARED_BUFFER_READV
@ PGAIO_HF_REFERENCES_LOCAL
void pgaio_io_set_handle_data_32(PgAioHandle *ioh, uint32 *data, uint8 len)
void pgaio_io_register_callbacks(PgAioHandle *ioh, PgAioHandleCallbackID cb_id, uint8 cb_data)
uint64 * pgaio_io_get_handle_data(PgAioHandle *ioh, uint8 *len)
void pgaio_result_report(PgAioResult result, const PgAioTargetData *target_data, int elevel)
PgAioTargetData * pgaio_io_get_target_data(PgAioHandle *ioh)
#define PGAIO_RESULT_ERROR_BITS
static bool pg_atomic_compare_exchange_u64(volatile pg_atomic_uint64 *ptr, uint64 *expected, uint64 newval)
#define pg_write_barrier()
static void pg_atomic_unlocked_write_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
static uint64 pg_atomic_sub_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 sub_)
static uint64 pg_atomic_fetch_and_u64(volatile pg_atomic_uint64 *ptr, uint64 and_)
static uint64 pg_atomic_fetch_or_u64(volatile pg_atomic_uint64 *ptr, uint64 or_)
static uint64 pg_atomic_read_u64(volatile pg_atomic_uint64 *ptr)
static uint64 pg_atomic_fetch_sub_u64(volatile pg_atomic_uint64 *ptr, int64 sub_)
bool TimestampDifferenceExceeds(TimestampTz start_time, TimestampTz stop_time, int msec)
TimestampTz GetCurrentTimestamp(void)
Datum now(PG_FUNCTION_ARGS)
void binaryheap_build(binaryheap *heap)
void binaryheap_replace_first(binaryheap *heap, bh_node_type d)
bh_node_type binaryheap_first(binaryheap *heap)
bh_node_type binaryheap_remove_first(binaryheap *heap)
void binaryheap_free(binaryheap *heap)
void binaryheap_add_unordered(binaryheap *heap, bh_node_type d)
binaryheap * binaryheap_allocate(int capacity, binaryheap_comparator compare, void *arg)
#define binaryheap_empty(h)
#define InvalidBlockNumber
static bool BlockNumberIsValid(BlockNumber blockNumber)
#define BufferIsLocal(buffer)
CkptSortItem * CkptBufferIds
WritebackContext BackendWritebackContext
#define BM_MAX_USAGE_COUNT
static void InitBufferTag(BufferTag *tag, const RelFileLocator *rlocator, ForkNumber forkNum, BlockNumber blockNum)
#define BUF_USAGECOUNT_MASK
static ForkNumber BufTagGetForkNum(const BufferTag *tag)
#define BM_LOCK_VAL_SHARED
static ConditionVariable * BufferDescriptorGetIOCV(const BufferDesc *bdesc)
static uint64 UnlockBufHdrExt(BufferDesc *desc, uint64 old_buf_state, uint64 set_bits, uint64 unset_bits, int refcount_change)
static bool BufferTagsEqual(const BufferTag *tag1, const BufferTag *tag2)
static RelFileNumber BufTagGetRelNumber(const BufferTag *tag)
static void UnlockBufHdr(BufferDesc *desc)
#define BM_LOCK_VAL_EXCLUSIVE
static bool BufTagMatchesRelFileLocator(const BufferTag *tag, const RelFileLocator *rlocator)
#define BM_PIN_COUNT_WAITER
#define BM_LOCK_WAKE_IN_PROGRESS
static void ResourceOwnerRememberBufferIO(ResourceOwner owner, Buffer buffer)
#define BUF_STATE_GET_USAGECOUNT(state)
static void ResourceOwnerForgetBufferIO(ResourceOwner owner, Buffer buffer)
#define BM_IO_IN_PROGRESS
static void ClearBufferTag(BufferTag *tag)
static void ResourceOwnerRememberBuffer(ResourceOwner owner, Buffer buffer)
static void ResourceOwnerForgetBuffer(ResourceOwner owner, Buffer buffer)
#define BUF_USAGECOUNT_ONE
#define BUF_STATE_GET_REFCOUNT(state)
static LWLock * BufMappingPartitionLock(uint32 hashcode)
static RelFileLocator BufTagGetRelFileLocator(const BufferTag *tag)
#define BM_LOCK_HAS_WAITERS
static BufferDesc * GetLocalBufferDescriptor(uint32 id)
static BufferDesc * GetBufferDescriptor(uint32 id)
#define BM_LOCK_VAL_SHARE_EXCLUSIVE
static Buffer BufferDescriptorGetBuffer(const BufferDesc *bdesc)
#define BM_CHECKPOINT_NEEDED
void BufTableDelete(BufferTag *tagPtr, uint32 hashcode)
int BufTableLookup(BufferTag *tagPtr, uint32 hashcode)
uint32 BufTableHashCode(BufferTag *tagPtr)
int BufTableInsert(BufferTag *tagPtr, uint32 hashcode, int buf_id)
static void ResOwnerReleaseBuffer(Datum res)
void CheckBufferIsPinnedOnce(Buffer buffer)
void FlushRelationsAllBuffers(SMgrRelation *smgrs, int nrels)
void IncrBufferRefCount(Buffer buffer)
static void MarkSharedBufferDirtyHint(Buffer buffer, BufferDesc *bufHdr, uint64 lockstate, bool buffer_std)
void DropDatabaseBuffers(Oid dbid)
bool BufferSetHintBits16(uint16 *ptr, uint16 val, Buffer buffer)
static int ckpt_buforder_comparator(const CkptSortItem *a, const CkptSortItem *b)
static pg_attribute_always_inline PgAioResult buffer_readv_complete(PgAioHandle *ioh, PgAioResult prior_result, uint8 cb_data, bool is_temp)
BlockNumber BufferGetBlockNumber(Buffer buffer)
static PrivateRefCountEntry * NewPrivateRefCountEntry(Buffer buffer)
static Buffer PrivateRefCountArrayKeys[REFCOUNT_ARRAY_ENTRIES]
void BufferFinishSetHintBits(Buffer buffer, bool mark_dirty, bool buffer_std)
static bool ReadBuffersCanStartIO(Buffer buffer, bool nowait)
void DropRelationBuffers(SMgrRelation smgr_reln, ForkNumber *forkNum, int nforks, BlockNumber *firstDelBlock)
Buffer ReleaseAndReadBuffer(Buffer buffer, Relation relation, BlockNumber blockNum)
static int ReservedRefCountSlot
static PgAioResult shared_buffer_readv_complete_local(PgAioHandle *ioh, PgAioResult prior_result, uint8 cb_data)
static pg_attribute_always_inline bool StartReadBuffersImpl(ReadBuffersOperation *operation, Buffer *buffers, BlockNumber blockNum, int *nblocks, int flags, bool allow_forwarding)
static void CheckReadBuffersOperation(ReadBuffersOperation *operation, bool is_complete)
PrefetchBufferResult PrefetchBuffer(Relation reln, ForkNumber forkNum, BlockNumber blockNum)
static uint32 PrivateRefCountClock
static void FlushBuffer(BufferDesc *buf, SMgrRelation reln, IOObject io_object, IOContext io_context)
static void ResOwnerReleaseBufferIO(Datum res)
static PgAioResult local_buffer_readv_complete(PgAioHandle *ioh, PgAioResult prior_result, uint8 cb_data)
bool StartReadBuffers(ReadBuffersOperation *operation, Buffer *buffers, BlockNumber blockNum, int *nblocks, int flags)
void EvictAllUnpinnedBuffers(int32 *buffers_evicted, int32 *buffers_flushed, int32 *buffers_skipped)
static void FlushUnlockedBuffer(BufferDesc *buf, SMgrRelation reln, IOObject io_object, IOContext io_context)
const ResourceOwnerDesc buffer_io_resowner_desc
#define BUF_DROP_FULL_SCAN_THRESHOLD
static void PinBuffer_Locked(BufferDesc *buf)
void EvictRelUnpinnedBuffers(Relation rel, int32 *buffers_evicted, int32 *buffers_flushed, int32 *buffers_skipped)
static pg_attribute_always_inline void buffer_readv_complete_one(PgAioTargetData *td, uint8 buf_off, Buffer buffer, uint8 flags, bool failed, bool is_temp, bool *buffer_invalid, bool *failed_checksum, bool *ignored_checksum, bool *zeroed_buffer)
static char * ResOwnerPrintBuffer(Datum res)
static void BufferLockAcquire(Buffer buffer, BufferDesc *buf_hdr, BufferLockMode mode)
static bool BufferLockAttempt(BufferDesc *buf_hdr, BufferLockMode mode)
static int buffertag_comparator(const BufferTag *ba, const BufferTag *bb)
bool IsBufferCleanupOK(Buffer buffer)
#define BufferGetLSN(bufHdr)
static char * ResOwnerPrintBufferIO(Datum res)
bool BufferIsLockedByMeInMode(Buffer buffer, BufferLockMode mode)
static void BufferLockDisown(Buffer buffer, BufferDesc *buf_hdr)
Buffer ExtendBufferedRel(BufferManagerRelation bmr, ForkNumber forkNum, BufferAccessStrategy strategy, uint32 flags)
void AtEOXact_Buffers(bool isCommit)
static void AbortBufferIO(Buffer buffer)
const PgAioHandleCallbacks aio_shared_buffer_readv_cb
static void BufferLockUnlock(Buffer buffer, BufferDesc *buf_hdr)
BlockNumber ExtendBufferedRelBy(BufferManagerRelation bmr, ForkNumber fork, BufferAccessStrategy strategy, uint32 flags, uint32 extend_by, Buffer *buffers, uint32 *extended_by)
static Buffer ReadBuffer_common(Relation rel, SMgrRelation smgr, char smgr_persistence, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
static void BufferLockWakeup(BufferDesc *buf_hdr, bool unlocked)
static void ProcessReadBuffersResult(ReadBuffersOperation *operation)
pg_noinline uint64 WaitBufHdrUnlocked(BufferDesc *buf)
static void ZeroAndLockBuffer(Buffer buffer, ReadBufferMode mode, bool already_valid)
static BufferDesc * BufferAlloc(SMgrRelation smgr, char relpersistence, ForkNumber forkNum, BlockNumber blockNum, BufferAccessStrategy strategy, bool *foundPtr, IOContext io_context)
static void CheckForBufferLeaks(void)
static bool ReadBuffersCanStartIOOnce(Buffer buffer, bool nowait)
void CreateAndCopyRelationData(RelFileLocator src_rlocator, RelFileLocator dst_rlocator, bool permanent)
void DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
static void BufferLockDequeueSelf(BufferDesc *buf_hdr)
static int rlocator_comparator(const void *p1, const void *p2)
static bool BufferLockHeldByMeInMode(BufferDesc *buf_hdr, BufferLockMode mode)
Buffer ExtendBufferedRelTo(BufferManagerRelation bmr, ForkNumber fork, BufferAccessStrategy strategy, uint32 flags, BlockNumber extend_to, ReadBufferMode mode)
const PgAioHandleCallbacks aio_local_buffer_readv_cb
static bool InvalidateVictimBuffer(BufferDesc *buf_hdr)
static void AtProcExit_Buffers(int code, Datum arg)
static int ts_ckpt_progress_comparator(Datum a, Datum b, void *arg)
void BufferGetTag(Buffer buffer, RelFileLocator *rlocator, ForkNumber *forknum, BlockNumber *blknum)
#define BufHdrGetBlock(bufHdr)
static bool BufferLockConditional(Buffer buffer, BufferDesc *buf_hdr, BufferLockMode mode)
const ResourceOwnerDesc buffer_resowner_desc
static refcount_hash * PrivateRefCountHash
static pg_attribute_always_inline void buffer_stage_common(PgAioHandle *ioh, bool is_write, bool is_temp)
void UnlockBuffer(Buffer buffer)
static void local_buffer_write_error_callback(void *arg)
static void BufferSync(int flags)
static bool AsyncReadBuffers(ReadBuffersOperation *operation, int *nblocks_progress)
static void local_buffer_readv_stage(PgAioHandle *ioh, uint8 cb_data)
char * DebugPrintBufferRefcount(Buffer buffer)
void CheckPointBuffers(int flags)
bool BufferIsDirty(Buffer buffer)
static uint32 MaxProportionalPins
static void BufferLockQueueSelf(BufferDesc *buf_hdr, BufferLockMode mode)
static BlockNumber ExtendBufferedRelShared(BufferManagerRelation bmr, ForkNumber fork, BufferAccessStrategy strategy, uint32 flags, uint32 extend_by, BlockNumber extend_upto, Buffer *buffers, uint32 *extended_by)
static int BufferLockDisownInternal(Buffer buffer, BufferDesc *buf_hdr)
bool BgBufferSync(WritebackContext *wb_context)
uint64 LockBufHdr(BufferDesc *desc)
static void WakePinCountWaiter(BufferDesc *buf)
bool BufferIsPermanent(Buffer buffer)
void MarkDirtyAllUnpinnedBuffers(int32 *buffers_dirtied, int32 *buffers_already_dirty, int32 *buffers_skipped)
#define REFCOUNT_ARRAY_ENTRIES
static void shared_buffer_readv_stage(PgAioHandle *ioh, uint8 cb_data)
static void BufferLockProcessRelease(BufferDesc *buf_hdr, BufferLockMode mode, uint64 lockstate)
PrefetchBufferResult PrefetchSharedBuffer(SMgrRelation smgr_reln, ForkNumber forkNum, BlockNumber blockNum)
static PgAioResult shared_buffer_readv_complete(PgAioHandle *ioh, PgAioResult prior_result, uint8 cb_data)
static Buffer GetVictimBuffer(BufferAccessStrategy strategy, IOContext io_context)
bool ConditionalLockBuffer(Buffer buffer)
BlockNumber RelationGetNumberOfBlocksInFork(Relation relation, ForkNumber forkNum)
void ReleaseBuffer(Buffer buffer)
bool BufferIsLockedByMe(Buffer buffer)
static bool PinBuffer(BufferDesc *buf, BufferAccessStrategy strategy, bool skip_if_not_valid)
static void FindAndDropRelationBuffers(RelFileLocator rlocator, ForkNumber forkNum, BlockNumber nForkBlock, BlockNumber firstDelBlock)
XLogRecPtr BufferGetLSNAtomic(Buffer buffer)
void LockBufferInternal(Buffer buffer, BufferLockMode mode)
bool HoldingBufferPinThatDelaysRecovery(void)
bool MarkDirtyUnpinnedBuffer(Buffer buf, bool *buffer_already_dirty)
int checkpoint_flush_after
void UnlockReleaseBuffer(Buffer buffer)
static pg_attribute_always_inline Buffer PinBufferForBlock(Relation rel, SMgrRelation smgr, char persistence, ForkNumber forkNum, BlockNumber blockNum, BufferAccessStrategy strategy, bool *foundPtr)
static void UnpinBufferNoOwner(BufferDesc *buf)
static void shared_buffer_write_error_callback(void *arg)
void ScheduleBufferTagForWriteback(WritebackContext *wb_context, IOContext io_context, BufferTag *tag)
void WaitReadBuffers(ReadBuffersOperation *operation)
void WritebackContextInit(WritebackContext *context, int *max_pending)
void MarkBufferDirty(Buffer buffer)
#define BufferIsPinned(bufnum)
double bgwriter_lru_multiplier
static bool EvictUnpinnedBufferInternal(BufferDesc *desc, bool *buffer_flushed)
bool BufferBeginSetHintBits(Buffer buffer)
void LimitAdditionalPins(uint32 *additional_pins)
static void buffer_readv_report(PgAioResult result, const PgAioTargetData *td, int elevel)
static void ReservePrivateRefCountEntry(void)
static BufferDesc * PinCountWaitBuf
static pg_noinline PrivateRefCountEntry * GetPrivateRefCountEntrySlow(Buffer buffer, bool do_move)
static int32 GetPrivateRefCount(Buffer buffer)
static BlockNumber ExtendBufferedRelCommon(BufferManagerRelation bmr, ForkNumber fork, BufferAccessStrategy strategy, uint32 flags, uint32 extend_by, BlockNumber extend_upto, Buffer *buffers, uint32 *extended_by)
void LockBufferForCleanup(Buffer buffer)
static bool SharedBufferBeginSetHintBits(Buffer buffer, BufferDesc *buf_hdr, uint64 *lockstate)
void MarkBufferDirtyHint(Buffer buffer, bool buffer_std)
void FlushRelationBuffers(Relation rel)
static uint64 BufferLockReleaseSub(BufferLockMode mode)
void IssuePendingWritebacks(WritebackContext *wb_context, IOContext io_context)
static void ForgetPrivateRefCountEntry(PrivateRefCountEntry *ref)
bool EvictUnpinnedBuffer(Buffer buf, bool *buffer_flushed)
Buffer ReadBufferWithoutRelcache(RelFileLocator rlocator, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy, bool permanent)
bool ReadRecentBuffer(RelFileLocator rlocator, ForkNumber forkNum, BlockNumber blockNum, Buffer recent_buffer)
#define RELS_BSEARCH_THRESHOLD
int maintenance_io_concurrency
static void UnpinBuffer(BufferDesc *buf)
void FlushDatabaseBuffers(Oid dbid)
static void InvalidateBuffer(BufferDesc *buf)
static void RelationCopyStorageUsingBuffer(RelFileLocator srclocator, RelFileLocator dstlocator, ForkNumber forkNum, bool permanent)
int effective_io_concurrency
static PrivateRefCountEntry * GetPrivateRefCountEntry(Buffer buffer, bool do_move)
static bool BufferLockHeldByMe(BufferDesc *buf_hdr)
void TerminateBufferIO(BufferDesc *buf, bool clear_dirty, uint64 set_flag_bits, bool forget_owner, bool release_aio)
bool StartBufferIO(BufferDesc *buf, bool forInput, bool nowait)
void MarkDirtyRelUnpinnedBuffers(Relation rel, int32 *buffers_dirtied, int32 *buffers_already_dirty, int32 *buffers_skipped)
bool StartReadBuffer(ReadBuffersOperation *operation, Buffer *buffer, BlockNumber blocknum, int flags)
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
static bool MarkDirtyUnpinnedBufferInternal(Buffer buf, BufferDesc *desc, bool *buffer_already_dirty)
static struct PrivateRefCountEntry PrivateRefCountArray[REFCOUNT_ARRAY_ENTRIES]
static void buffer_readv_decode_error(PgAioResult result, bool *zeroed_any, bool *ignored_any, uint8 *zeroed_or_error_count, uint8 *checkfail_count, uint8 *first_off)
static int PrivateRefCountEntryLast
void InitBufferManagerAccess(void)
static void buffer_readv_encode_error(PgAioResult *result, bool is_temp, bool zeroed_any, bool ignored_any, uint8 error_count, uint8 zeroed_count, uint8 checkfail_count, uint8 first_error_off, uint8 first_zeroed_off, uint8 first_ignored_off)
static int SyncOneBuffer(int buf_id, bool skip_recently_used, WritebackContext *wb_context)
uint32 GetAdditionalPinLimit(void)
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
void TrackNewBufferPin(Buffer buf)
static int32 PrivateRefCountOverflowed
bool ConditionalLockBufferForCleanup(Buffer buffer)
int bgwriter_lru_maxpages
static void WaitIO(BufferDesc *buf)
void FlushOneBuffer(Buffer buffer)
#define READ_BUFFERS_ZERO_ON_ERROR
static Page BufferGetPage(Buffer buffer)
#define DEFAULT_IO_COMBINE_LIMIT
static Block BufferGetBlock(Buffer buffer)
#define READ_BUFFERS_ISSUE_ADVICE
@ BUFFER_LOCK_SHARE_EXCLUSIVE
#define MAX_IO_COMBINE_LIMIT
#define DEFAULT_EFFECTIVE_IO_CONCURRENCY
#define READ_BUFFERS_IGNORE_CHECKSUM_FAILURES
#define DEFAULT_MAINTENANCE_IO_CONCURRENCY
static void LockBuffer(Buffer buffer, BufferLockMode mode)
#define BMR_GET_SMGR(bmr)
@ EB_CREATE_FORK_IF_NEEDED
#define READ_BUFFERS_SYNCHRONOUSLY
@ RBM_ZERO_AND_CLEANUP_LOCK
static bool BufferIsValid(Buffer bufnum)
bool ignore_checksum_failure
char * PageSetChecksumCopy(Page page, BlockNumber blkno)
bool PageIsVerified(PageData *page, BlockNumber blkno, int flags, bool *checksum_failure_p)
static bool PageIsNew(const PageData *page)
static void PageSetLSN(Page page, XLogRecPtr lsn)
static XLogRecPtr PageGetLSN(const PageData *page)
#define PIV_IGNORE_CHECKSUM_FAILURE
#define PG_USED_FOR_ASSERTS_ONLY
#define Assert(condition)
#define pg_attribute_always_inline
#define MemSet(start, val, len)
#define StaticAssertDecl(condition, errmessage)
bool IsCatalogRelationOid(Oid relid)
bool IsCatalogTextUniqueIndexOid(Oid relid)
void CheckpointWriteDelay(int flags, double progress)
bool ConditionVariableCancelSleep(void)
void ConditionVariableBroadcast(ConditionVariable *cv)
void ConditionVariablePrepareToSleep(ConditionVariable *cv)
void ConditionVariableSleep(ConditionVariable *cv, uint32 wait_event_info)
ErrorContextCallback * error_context_stack
int errcode(int sqlerrcode)
int int errdetail_internal(const char *fmt,...) pg_attribute_printf(1
int int int errhint_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...) pg_attribute_printf(1
int errdetail(const char *fmt,...) pg_attribute_printf(1
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
#define ereport(elevel,...)
int int errhint_internal(const char *fmt,...) pg_attribute_printf(1
#define palloc_array(type, count)
int StrategySyncStart(uint32 *complete_passes, uint32 *num_buf_alloc)
BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype)
BufferDesc * StrategyGetBuffer(BufferAccessStrategy strategy, uint64 *buf_state, bool *from_ring)
void FreeAccessStrategy(BufferAccessStrategy strategy)
IOContext IOContextForStrategy(BufferAccessStrategy strategy)
bool StrategyRejectBuffer(BufferAccessStrategy strategy, BufferDesc *buf, bool from_ring)
volatile sig_atomic_t ProcSignalBarrierPending
BufferUsage pgBufferUsage
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
void LockRelationForExtension(Relation relation, LOCKMODE lockmode)
void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode)
void FlushLocalBuffer(BufferDesc *bufHdr, SMgrRelation reln)
void UnpinLocalBuffer(Buffer buffer)
bool StartLocalBufferIO(BufferDesc *bufHdr, bool forInput, bool nowait)
void AtEOXact_LocalBuffers(bool isCommit)
void AtProcExit_LocalBuffers(void)
bool PinLocalBuffer(BufferDesc *buf_hdr, bool adjust_usagecount)
void MarkLocalBufferDirty(Buffer buffer)
void DropRelationAllLocalBuffers(RelFileLocator rlocator)
void TerminateLocalBufferIO(BufferDesc *bufHdr, bool clear_dirty, uint64 set_flag_bits, bool release_aio)
PrefetchBufferResult PrefetchLocalBuffer(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum)
BlockNumber ExtendBufferedRelLocal(BufferManagerRelation bmr, ForkNumber fork, uint32 flags, uint32 extend_by, BlockNumber extend_upto, Buffer *buffers, uint32 *extended_by)
void UnpinLocalBufferNoOwner(Buffer buffer)
void DropRelationLocalBuffers(RelFileLocator rlocator, ForkNumber *forkNum, int nforks, BlockNumber *firstDelBlock)
BufferDesc * LocalBufferAlloc(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum, bool *foundPtr)
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
void LWLockRelease(LWLock *lock)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
MemoryContext CurrentMemoryContext
#define VALGRIND_MAKE_MEM_DEFINED(addr, size)
#define VALGRIND_MAKE_MEM_NOACCESS(addr, size)
#define RESUME_INTERRUPTS()
#define START_CRIT_SECTION()
#define CHECK_FOR_INTERRUPTS()
#define HOLD_INTERRUPTS()
#define END_CRIT_SECTION()
#define ERRCODE_DATA_CORRUPTED
static PgChecksumMode mode
static int64 current_size
#define WRITEBACK_MAX_PENDING_FLUSHES
#define DEFAULT_BACKEND_FLUSH_AFTER
#define DEFAULT_CHECKPOINT_FLUSH_AFTER
#define DEFAULT_BGWRITER_FLUSH_AFTER
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define pgstat_count_buffer_read(rel)
#define pgstat_count_buffer_hit(rel)
PgStat_BgWriterStats PendingBgWriterStats
PgStat_CheckpointerStats PendingCheckpointerStats
void pgstat_prepare_report_checksum_failure(Oid dboid)
void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount)
instr_time pgstat_prepare_io_time(bool track_io_guc)
void pgstat_count_io_op(IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt, uint64 bytes)
void pgstat_count_io_op_time(IOObject io_object, IOContext io_context, IOOp io_op, instr_time start_time, uint32 cnt, uint64 bytes)
#define qsort(a, b, c, d)
void PGSemaphoreUnlock(PGSemaphore sema)
void PGSemaphoreLock(PGSemaphore sema)
static Datum PointerGetDatum(const void *X)
static Pointer DatumGetPointer(Datum X)
static int32 DatumGetInt32(Datum X)
#define NUM_AUXILIARY_PROCS
#define GetPGProcByNumber(n)
#define proclist_delete(list, procno, link_member)
static void proclist_init(proclist_head *list)
#define proclist_push_tail(list, procno, link_member)
#define proclist_foreach_modify(iter, lhead, link_member)
static bool proclist_is_empty(const proclist_head *list)
#define INVALID_PROC_NUMBER
void ProcessProcSignalBarrier(void)
void set_ps_display_remove_suffix(void)
void set_ps_display_suffix(const char *suffix)
char * psprintf(const char *fmt,...)
ReadStream * read_stream_begin_smgr_relation(int flags, BufferAccessStrategy strategy, SMgrRelation smgr, char smgr_persistence, ForkNumber forknum, ReadStreamBlockNumberCB callback, void *callback_private_data, size_t per_buffer_data_size)
Buffer read_stream_next_buffer(ReadStream *stream, void **per_buffer_data)
void read_stream_end(ReadStream *stream)
BlockNumber block_range_read_stream_cb(ReadStream *stream, void *callback_private_data, void *per_buffer_data)
#define READ_STREAM_USE_BATCHING
static unsigned hash(unsigned *uv, int n)
static SMgrRelation RelationGetSmgr(Relation rel)
#define RelationUsesLocalBuffers(relation)
#define RELATION_IS_OTHER_TEMP(relation)
#define RelationIsValid(relation)
#define RelFileLocatorBackendIsTemp(rlocator)
#define RelFileLocatorEquals(locator1, locator2)
#define relpath(rlocator, forknum)
#define relpathbackend(rlocator, backend, forknum)
#define relpathperm(rlocator, forknum)
ResourceOwner CurrentResourceOwner
void ResourceOwnerEnlarge(ResourceOwner owner)
#define RELEASE_PRIO_BUFFER_IOS
@ RESOURCE_RELEASE_BEFORE_LOCKS
#define RELEASE_PRIO_BUFFER_PINS
void perform_spin_delay(SpinDelayStatus *status)
void finish_spin_delay(SpinDelayStatus *status)
#define init_local_spin_delay(status)
BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum)
void smgrstartreadv(PgAioHandle *ioh, SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, void **buffers, BlockNumber nblocks)
void smgrwriteback(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, BlockNumber nblocks)
SMgrRelation smgropen(RelFileLocator rlocator, ProcNumber backend)
void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo)
BlockNumber smgrnblocks_cached(SMgrRelation reln, ForkNumber forknum)
uint32 smgrmaxcombine(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum)
void smgrzeroextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nblocks, bool skipFsync)
void smgrextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void *buffer, bool skipFsync)
bool smgrexists(SMgrRelation reln, ForkNumber forknum)
bool smgrprefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nblocks)
static void smgrwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void *buffer, bool skipFsync)
void ProcSendSignal(ProcNumber procNumber)
int GetStartupBufferPinWaitBufId(void)
void SetStartupBufferPinWaitBufId(int bufid)
void ProcWaitForSignal(uint32 wait_event_info)
void ResolveRecoveryConflictWithBufferPin(void)
bool log_recovery_conflict_waits
void LogRecoveryConflict(RecoveryConflictReason reason, TimestampTz wait_start, TimestampTz now, VirtualTransactionId *wait_list, bool still_waiting)
@ RECOVERY_CONFLICT_BUFFERPIN
bool RelFileLocatorSkippingWAL(RelFileLocator rlocator)
SMgrRelation RelationCreateStorage(RelFileLocator rlocator, char relpersistence, bool register_delete)
void log_smgrcreate(const RelFileLocator *rlocator, ForkNumber forkNum)
BlockNumber last_exclusive
BlockNumber current_blocknum
int64 shared_blks_dirtied
int64 shared_blks_written
struct ErrorContextCallback * previous
void(* callback)(void *arg)
PgAioHandleCallbackStage stage
PgStat_Counter buf_written_clean
PgStat_Counter maxwritten_clean
PgStat_Counter buffers_written
BufferAccessStrategy strategy
char str[REL_PATH_STR_MAXLEN+1]
RelFileLocator rd_locator
RelFileLocatorBackend smgr_rlocator
static uint64 table_relation_size(Relation rel, ForkNumber forkNumber)
struct PgAioTargetData::@128 smgr
static void pgstat_report_wait_start(uint32 wait_event_info)
static void pgstat_report_wait_end(void)
static volatile sig_atomic_t waiting
static TimestampTz wakeup[NUM_WALRCV_WAKEUPS]
bool RecoveryInProgress(void)
bool XLogNeedsFlush(XLogRecPtr record)
CheckpointStatsData CheckpointStats
void XLogFlush(XLogRecPtr record)
#define CHECKPOINT_FLUSH_UNLOGGED
#define CHECKPOINT_END_OF_RECOVERY
#define CHECKPOINT_IS_SHUTDOWN
#define XLogHintBitIsNeeded()
#define XLogRecPtrIsValid(r)
#define InvalidXLogRecPtr
XLogRecPtr XLogSaveBufferForHint(Buffer buffer, bool buffer_std)
XLogRecPtr log_newpage_buffer(Buffer buffer, bool page_std)