63 #define BufHdrGetBlock(bufHdr) ((Block) (BufferBlocks + ((Size) (bufHdr)->buf_id) * BLCKSZ))
64 #define BufferGetLSN(bufHdr) (PageGetLSN(BufHdrGetBlock(bufHdr)))
67 #define LocalBufHdrGetBlock(bufHdr) \
68 LocalBufferBlockPointers[-((bufHdr)->buf_id + 2)]
71 #define BUF_WRITTEN 0x01
72 #define BUF_REUSABLE 0x02
74 #define RELS_BSEARCH_THRESHOLD 20
82 #define BUF_DROP_FULL_SCAN_THRESHOLD (uint64) (NBuffers / 32)
91 #define REFCOUNT_ARRAY_ENTRIES 8
225 .
name =
"buffer pin",
386 free->refcount =
res->refcount;
462 #define BufferIsPinned(bufnum) \
464 !BufferIsValid(bufnum) ? \
467 BufferIsLocal(bufnum) ? \
468 (LocalRefCount[-(bufnum) - 1] > 0) \
470 (GetPrivateRefCount(bufnum) > 0) \
500 static int SyncOneBuffer(
int buf_id,
bool skip_recently_used,
505 uint32 set_flag_bits,
bool forget_owner);
637 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
638 errmsg(
"cannot access temporary tables of other sessions")));
664 bool have_private_ref;
674 int b = -recent_buffer - 1;
699 if (have_private_ref)
711 if (have_private_ref)
722 if (!have_private_ref)
794 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
795 errmsg(
"cannot access temporary tables of other sessions")));
803 forkNum, blockNum,
mode, strategy, &hit);
830 RELPERSISTENCE_UNLOGGED, forkNum, blockNum,
831 mode, strategy, &hit);
882 if (bmr.
smgr == NULL)
890 buffers, extended_by);
918 if (bmr.
smgr == NULL)
974 num_pages, extend_to,
975 buffers, &extended_by);
982 if (first_block +
i != extend_to - 1)
1001 fork, extend_to - 1,
mode, strategy,
1045 forkNum, strategy, flags);
1048 TRACE_POSTGRESQL_BUFFER_READ_START(forkNum, blockNum,
1079 bufHdr =
BufferAlloc(smgr, relpersistence, forkNum, blockNum,
1080 strategy, &found, io_context);
1101 TRACE_POSTGRESQL_BUFFER_READ_DONE(forkNum, blockNum,
1138 MemSet((
char *) bufBlock, 0, BLCKSZ);
1143 smgrread(smgr, forkNum, blockNum, bufBlock);
1156 errmsg(
"invalid page in block %u of relation %s; zeroing out page",
1159 MemSet((
char *) bufBlock, 0, BLCKSZ);
1164 errmsg(
"invalid page in block %u of relation %s",
1205 TRACE_POSTGRESQL_BUFFER_READ_DONE(forkNum, blockNum,
1246 LWLock *newPartitionLock;
1247 int existing_buf_id;
1266 if (existing_buf_id >= 0)
1328 if (existing_buf_id >= 0)
1355 valid =
PinBuffer(existing_buf_hdr, strategy);
1381 return existing_buf_hdr;
1387 victim_buf_state =
LockBufHdr(victim_buf_hdr);
1393 victim_buf_hdr->
tag = newTag;
1402 if (relpersistence == RELPERSISTENCE_PERMANENT || forkNum ==
INIT_FORKNUM)
1420 return victim_buf_hdr;
1445 LWLock *oldPartitionLock;
1498 elog(
ERROR,
"buffer is pinned in InvalidateBuffer");
1687 if (strategy != NULL)
1748 #ifdef USE_ASSERT_CHECKING
1776 int max_proportional_pins;
1778 if (*additional_pins <= 1)
1782 max_proportional_pins =
NBuffers / max_backends;
1792 if (max_proportional_pins <= 0)
1793 max_proportional_pins = 1;
1795 if (*additional_pins > max_proportional_pins)
1796 *additional_pins = max_proportional_pins;
1815 TRACE_POSTGRESQL_BUFFER_EXTEND_START(fork,
1824 extend_by, extend_upto,
1825 buffers, &extend_by);
1828 extend_by, extend_upto,
1829 buffers, &extend_by);
1830 *extended_by = extend_by;
1832 TRACE_POSTGRESQL_BUFFER_EXTEND_DONE(fork,
1881 MemSet((
char *) buf_block, 0, BLCKSZ);
1914 uint32 orig_extend_by = extend_by;
1916 if (first_block > extend_upto)
1918 else if ((uint64) first_block + extend_by > extend_upto)
1919 extend_by = extend_upto - first_block;
1921 for (
uint32 i = extend_by;
i < orig_extend_by;
i++)
1937 *extended_by = extend_by;
1945 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1946 errmsg(
"cannot extend relation %s beyond %u blocks",
1958 Buffer victim_buf = buffers[
i];
1991 if (existing_id >= 0)
2001 valid =
PinBuffer(existing_hdr, strategy);
2017 (
errmsg(
"unexpected data beyond EOF in block %u of relation %s",
2019 errhint(
"This has been seen to occur with buggy kernels; consider updating your system.")));
2049 victim_buf_hdr->
tag = tag;
2089 io_start, extend_by);
2103 if (first_block +
i + 1 == extend_upto)
2115 *extended_by = extend_by;
2216 buf_state = old_buf_state;
2334 buf_state = old_buf_state;
2339 if (strategy == NULL)
2358 result = (buf_state &
BM_VALID) != 0;
2509 buf_state = old_buf_state;
2534 int wait_backend_pgprocno =
buf->wait_backend_pgprocno;
2547 #define ST_SORT sort_checkpoint_bufferids
2548 #define ST_ELEMENT_TYPE CkptSortItem
2549 #define ST_COMPARE(a, b) ckpt_buforder_comparator(a, b)
2550 #define ST_SCOPE static
2606 for (buf_id = 0; buf_id <
NBuffers; buf_id++)
2616 if ((buf_state & mask) == mask)
2637 if (num_to_scan == 0)
2642 TRACE_POSTGRESQL_BUFFER_SYNC_START(
NBuffers, num_to_scan);
2660 for (
i = 0;
i < num_to_scan;
i++)
2671 if (last_tsid ==
InvalidOid || last_tsid != cur_tsid)
2683 if (per_ts_stat == NULL)
2688 s = &per_ts_stat[num_spaces - 1];
2689 memset(s, 0,
sizeof(*s));
2704 last_tsid = cur_tsid;
2708 s = &per_ts_stat[num_spaces - 1];
2729 for (
i = 0;
i < num_spaces;
i++)
2777 TRACE_POSTGRESQL_BUFFER_SYNC_WRITTEN(buf_id);
2826 TRACE_POSTGRESQL_BUFFER_SYNC_DONE(
NBuffers, num_written, num_to_scan);
2844 int strategy_buf_id;
2852 static bool saved_info_valid =
false;
2853 static int prev_strategy_buf_id;
2854 static uint32 prev_strategy_passes;
2855 static int next_to_clean;
2856 static uint32 next_passes;
2859 static float smoothed_alloc = 0;
2860 static float smoothed_density = 10.0;
2863 float smoothing_samples = 16;
2864 float scan_whole_pool_milliseconds = 120000.0;
2867 long strategy_delta;
2870 float scans_per_alloc;
2871 int reusable_buffers_est;
2872 int upcoming_alloc_est;
2873 int min_scan_buffers;
2878 int reusable_buffers;
2881 long new_strategy_delta;
2900 saved_info_valid =
false;
2912 if (saved_info_valid)
2914 int32 passes_delta = strategy_passes - prev_strategy_passes;
2916 strategy_delta = strategy_buf_id - prev_strategy_buf_id;
2917 strategy_delta += (long) passes_delta *
NBuffers;
2919 Assert(strategy_delta >= 0);
2921 if ((
int32) (next_passes - strategy_passes) > 0)
2924 bufs_to_lap = strategy_buf_id - next_to_clean;
2926 elog(
DEBUG2,
"bgwriter ahead: bgw %u-%u strategy %u-%u delta=%ld lap=%d",
2927 next_passes, next_to_clean,
2928 strategy_passes, strategy_buf_id,
2929 strategy_delta, bufs_to_lap);
2932 else if (next_passes == strategy_passes &&
2933 next_to_clean >= strategy_buf_id)
2936 bufs_to_lap =
NBuffers - (next_to_clean - strategy_buf_id);
2938 elog(
DEBUG2,
"bgwriter ahead: bgw %u-%u strategy %u-%u delta=%ld lap=%d",
2939 next_passes, next_to_clean,
2940 strategy_passes, strategy_buf_id,
2941 strategy_delta, bufs_to_lap);
2951 elog(
DEBUG2,
"bgwriter behind: bgw %u-%u strategy %u-%u delta=%ld",
2952 next_passes, next_to_clean,
2953 strategy_passes, strategy_buf_id,
2956 next_to_clean = strategy_buf_id;
2957 next_passes = strategy_passes;
2968 elog(
DEBUG2,
"bgwriter initializing: strategy %u-%u",
2969 strategy_passes, strategy_buf_id);
2972 next_to_clean = strategy_buf_id;
2973 next_passes = strategy_passes;
2978 prev_strategy_buf_id = strategy_buf_id;
2979 prev_strategy_passes = strategy_passes;
2980 saved_info_valid =
true;
2988 if (strategy_delta > 0 && recent_alloc > 0)
2990 scans_per_alloc = (float) strategy_delta / (
float) recent_alloc;
2991 smoothed_density += (scans_per_alloc - smoothed_density) /
3000 bufs_ahead =
NBuffers - bufs_to_lap;
3001 reusable_buffers_est = (float) bufs_ahead / smoothed_density;
3008 if (smoothed_alloc <= (
float) recent_alloc)
3009 smoothed_alloc = recent_alloc;
3011 smoothed_alloc += ((float) recent_alloc - smoothed_alloc) /
3025 if (upcoming_alloc_est == 0)
3040 if (upcoming_alloc_est < (min_scan_buffers + reusable_buffers_est))
3043 elog(
DEBUG2,
"bgwriter: alloc_est=%d too small, using min=%d + reusable_est=%d",
3044 upcoming_alloc_est, min_scan_buffers, reusable_buffers_est);
3046 upcoming_alloc_est = min_scan_buffers + reusable_buffers_est;
3056 num_to_scan = bufs_to_lap;
3058 reusable_buffers = reusable_buffers_est;
3061 while (num_to_scan > 0 && reusable_buffers < upcoming_alloc_est)
3089 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",
3090 recent_alloc, smoothed_alloc, strategy_delta, bufs_ahead,
3091 smoothed_density, reusable_buffers_est, upcoming_alloc_est,
3092 bufs_to_lap - num_to_scan,
3094 reusable_buffers - reusable_buffers_est);
3105 new_strategy_delta = bufs_to_lap - num_to_scan;
3106 new_recent_alloc = reusable_buffers - reusable_buffers_est;
3107 if (new_strategy_delta > 0 && new_recent_alloc > 0)
3109 scans_per_alloc = (float) new_strategy_delta / (
float) new_recent_alloc;
3110 smoothed_density += (scans_per_alloc - smoothed_density) /
3114 elog(
DEBUG2,
"bgwriter: cleaner density alloc=%u scan=%ld density=%.2f new smoothed=%.2f",
3115 new_recent_alloc, new_strategy_delta,
3116 scans_per_alloc, smoothed_density);
3121 return (bufs_to_lap == 0 && recent_alloc == 0);
3166 else if (skip_recently_used)
3274 #ifdef USE_ASSERT_CHECKING
3275 int RefCountErrors = 0;
3310 Assert(RefCountErrors == 0);
3346 result =
psprintf(
"[%03d] (rel=%s, blockNum=%u, flags=0x%x, refcount=%u %d)",
3457 errcallback.
arg = (
void *)
buf;
3578 if (RELKIND_HAS_TABLE_AM(relation->
rd_rel->relkind))
3590 return (szbytes + (BLCKSZ - 1)) / BLCKSZ;
3592 else if (RELKIND_HAS_STORAGE(relation->
rd_rel->relkind))
3691 uint64 nBlocksToInvalidate = 0;
3700 for (
j = 0;
j < nforks;
j++)
3729 for (
i = 0;
i < nforks;
i++)
3741 nBlocksToInvalidate += (nForkBlock[
i] - firstDelBlock[
i]);
3751 for (
j = 0;
j < nforks;
j++)
3753 nForkBlock[
j], firstDelBlock[
j]);
3783 for (
j = 0;
j < nforks;
j++)
3813 uint64 nBlocksToInvalidate = 0;
3824 for (
i = 0;
i < nlocators;
i++)
3832 rels[n++] = smgr_reln[
i];
3856 for (
i = 0;
i < n && cached;
i++)
3873 nBlocksToInvalidate += block[
i][
j];
3883 for (
i = 0;
i < n;
i++)
3904 for (
i = 0;
i < n;
i++)
3905 locators[
i] = rels[
i]->smgr_rlocator.locator;
3934 for (
j = 0;
j < n;
j++)
3938 rlocator = &locators[
j];
3948 rlocator = bsearch((
const void *) &(locator),
3954 if (rlocator == NULL)
3984 for (curBlock = firstDelBlock; curBlock < nForkBlock; curBlock++)
3988 LWLock *bufPartitionLock;
4077 PrintBufferDescs(
void)
4088 "[%02d] (freeNext=%d, rel=%s, "
4089 "blockNum=%u, flags=0x%x, refcount=%u %d)",
4093 buf->tag.blockNum,
buf->flags,
4101 PrintPinnedBufs(
void)
4114 "[%02d] (freeNext=%d, rel=%s, "
4115 "blockNum=%u, flags=0x%x, refcount=%u %d)",
4119 buf->tag.blockNum,
buf->flags,
4170 errcallback.
arg = (
void *) bufHdr;
4255 for (
i = 0;
i < nrels;
i++)
4260 srels[
i].
srel = smgrs[
i];
4288 for (
j = 0;
j < nrels;
j++)
4292 srelent = &srels[
j];
4302 srelent = bsearch((
const void *) &(rlocator),
4308 if (srelent == NULL)
4377 memset(
buf.data, 0, BLCKSZ);
4386 for (blkno = 0; blkno < nblocks; blkno++)
4405 memcpy(dstPage, srcPage, BLCKSZ);
4437 char relpersistence;
4442 relpersistence = permanent ?
4443 RELPERSISTENCE_PERMANENT : RELPERSISTENCE_UNLOGGED;
4659 bool dirtied =
false;
4660 bool delayChkptFlags =
false;
4712 delayChkptFlags =
true;
4744 if (delayChkptFlags)
4847 elog(
ERROR,
"incorrect local pin count: %d",
4853 elog(
ERROR,
"incorrect local pin count: %d",
4880 bool logged_recovery_conflict =
false;
4912 if (logged_recovery_conflict)
4930 elog(
ERROR,
"multiple backends attempting to wait for pincount 1");
4956 if (waitStart != 0 && !logged_recovery_conflict)
4964 waitStart,
now, NULL,
true);
4965 logged_recovery_conflict =
true;
5257 buf_state |= set_flag_bits;
5309 errmsg(
"could not write block %u of %s",
5311 errdetail(
"Multiple failures --- write error might be permanent.")));
5333 errcontext(
"writing block %u of relation %s",
5353 errcontext(
"writing block %u of relation %s",
5481 if (
a->tsId <
b->tsId)
5483 else if (
a->tsId >
b->tsId)
5486 if (
a->relNumber <
b->relNumber)
5488 else if (
a->relNumber >
b->relNumber)
5491 else if (
a->forkNum <
b->forkNum)
5493 else if (
a->forkNum >
b->forkNum)
5496 else if (
a->blockNum <
b->blockNum)
5498 else if (
a->blockNum >
b->blockNum)
5562 pending->
tag = *tag;
5574 #define ST_SORT sort_pending_writebacks
5575 #define ST_ELEMENT_TYPE PendingWriteback
5576 #define ST_COMPARE(a, b) buffertag_comparator(&a->tag, &b->tag)
5577 #define ST_SCOPE static
5629 for (ahead = 0;
i + ahead + 1 < wb_context->
nr_pending; ahead++)
5641 if (
cur->tag.blockNum ==
next->tag.blockNum)
5645 if (
cur->tag.blockNum + 1 !=
next->tag.blockNum)
static bool pg_atomic_compare_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 *expected, uint32 newval)
static uint32 pg_atomic_fetch_or_u32(volatile pg_atomic_uint32 *ptr, uint32 or_)
static void pg_atomic_unlocked_write_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
static uint32 pg_atomic_read_u32(volatile pg_atomic_uint32 *ptr)
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)
binaryheap * binaryheap_allocate(int capacity, binaryheap_comparator compare, void *arg)
void binaryheap_free(binaryheap *heap)
void binaryheap_add_unordered(binaryheap *heap, bh_node_type d)
#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)
static BufferDesc * GetLocalBufferDescriptor(uint32 id)
static BufferDesc * GetBufferDescriptor(uint32 id)
static void UnlockBufHdr(BufferDesc *desc, uint32 buf_state)
static bool BufferTagsEqual(const BufferTag *tag1, const BufferTag *tag2)
static RelFileNumber BufTagGetRelNumber(const BufferTag *tag)
static bool BufTagMatchesRelFileLocator(const BufferTag *tag, const RelFileLocator *rlocator)
static LWLock * BufMappingPartitionLock(uint32 hashcode)
#define BM_PIN_COUNT_WAITER
#define BUF_STATE_GET_USAGECOUNT(state)
#define BM_IO_IN_PROGRESS
static void ClearBufferTag(BufferTag *tag)
static ConditionVariable * BufferDescriptorGetIOCV(const BufferDesc *bdesc)
#define BUF_USAGECOUNT_ONE
#define BUF_STATE_GET_REFCOUNT(state)
static RelFileLocator BufTagGetRelFileLocator(const BufferTag *tag)
static Buffer BufferDescriptorGetBuffer(const BufferDesc *bdesc)
#define BM_CHECKPOINT_NEEDED
static LWLock * BufferDescriptorGetContentLock(const BufferDesc *bdesc)
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)
void CheckBufferIsPinnedOnce(Buffer buffer)
void FlushRelationsAllBuffers(SMgrRelation *smgrs, int nrels)
void IncrBufferRefCount(Buffer buffer)
void DropDatabaseBuffers(Oid dbid)
static int ckpt_buforder_comparator(const CkptSortItem *a, const CkptSortItem *b)
bool BufferIsExclusiveLocked(Buffer buffer)
const ResourceOwnerDesc buffer_pin_resowner_desc
BlockNumber BufferGetBlockNumber(Buffer buffer)
static PrivateRefCountEntry * NewPrivateRefCountEntry(Buffer buffer)
void DropRelationBuffers(SMgrRelation smgr_reln, ForkNumber *forkNum, int nforks, BlockNumber *firstDelBlock)
Buffer ReleaseAndReadBuffer(Buffer buffer, Relation relation, BlockNumber blockNum)
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 bool PinBuffer(BufferDesc *buf, BufferAccessStrategy strategy)
const ResourceOwnerDesc buffer_io_resowner_desc
#define BUF_DROP_FULL_SCAN_THRESHOLD
static void PinBuffer_Locked(BufferDesc *buf)
static uint32 WaitBufHdrUnlocked(BufferDesc *buf)
static int buffertag_comparator(const BufferTag *ba, const BufferTag *bb)
#define LocalBufHdrGetBlock(bufHdr)
bool IsBufferCleanupOK(Buffer buffer)
#define BufferGetLSN(bufHdr)
static void TerminateBufferIO(BufferDesc *buf, bool clear_dirty, uint32 set_flag_bits, bool forget_owner)
static char * ResOwnerPrintBufferIO(Datum res)
static BufferDesc * BufferAlloc(SMgrRelation smgr, char relpersistence, ForkNumber forkNum, BlockNumber blockNum, BufferAccessStrategy strategy, bool *foundPtr, IOContext io_context)
Buffer ExtendBufferedRel(BufferManagerRelation bmr, ForkNumber forkNum, BufferAccessStrategy strategy, uint32 flags)
void AtEOXact_Buffers(bool isCommit)
char * DebugPrintBufferRefcount(Buffer buffer)
static void AbortBufferIO(Buffer buffer)
BlockNumber ExtendBufferedRelBy(BufferManagerRelation bmr, ForkNumber fork, BufferAccessStrategy strategy, uint32 flags, uint32 extend_by, Buffer *buffers, uint32 *extended_by)
static void CheckForBufferLeaks(void)
void CreateAndCopyRelationData(RelFileLocator src_rlocator, RelFileLocator dst_rlocator, bool permanent)
void DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
static int rlocator_comparator(const void *p1, const void *p2)
Buffer ExtendBufferedRelTo(BufferManagerRelation bmr, ForkNumber fork, BufferAccessStrategy strategy, uint32 flags, BlockNumber extend_to, ReadBufferMode mode)
struct SMgrSortArray SMgrSortArray
static bool InvalidateVictimBuffer(BufferDesc *buf_hdr)
static void LimitAdditionalPins(uint32 *additional_pins)
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 void local_buffer_write_error_callback(void *arg)
static void BufferSync(int flags)
static char * ResOwnerPrintBufferPin(Datum res)
void CheckPointBuffers(int flags)
bool BufferIsDirty(Buffer buffer)
static BlockNumber ExtendBufferedRelShared(BufferManagerRelation bmr, ForkNumber fork, BufferAccessStrategy strategy, uint32 flags, uint32 extend_by, BlockNumber extend_upto, Buffer *buffers, uint32 *extended_by)
bool BgBufferSync(WritebackContext *wb_context)
bool BufferIsPermanent(Buffer buffer)
#define REFCOUNT_ARRAY_ENTRIES
PrefetchBufferResult PrefetchSharedBuffer(SMgrRelation smgr_reln, ForkNumber forkNum, BlockNumber blockNum)
static Buffer GetVictimBuffer(BufferAccessStrategy strategy, IOContext io_context)
bool ConditionalLockBuffer(Buffer buffer)
static bool StartBufferIO(BufferDesc *buf, bool forInput)
BlockNumber RelationGetNumberOfBlocksInFork(Relation relation, ForkNumber forkNum)
void ReleaseBuffer(Buffer buffer)
static void FindAndDropRelationBuffers(RelFileLocator rlocator, ForkNumber forkNum, BlockNumber nForkBlock, BlockNumber firstDelBlock)
XLogRecPtr BufferGetLSNAtomic(Buffer buffer)
bool HoldingBufferPinThatDelaysRecovery(void)
int checkpoint_flush_after
void UnlockReleaseBuffer(Buffer buffer)
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 WritebackContextInit(WritebackContext *context, int *max_pending)
void MarkBufferDirty(Buffer buffer)
void InitBufferPoolAccess(void)
#define BufferIsPinned(bufnum)
double bgwriter_lru_multiplier
static void ReservePrivateRefCountEntry(void)
static BufferDesc * PinCountWaitBuf
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)
void LockBuffer(Buffer buffer, int mode)
static PrivateRefCountEntry * ReservedRefCountEntry
void MarkBufferDirtyHint(Buffer buffer, bool buffer_std)
void FlushRelationBuffers(Relation rel)
void IssuePendingWritebacks(WritebackContext *wb_context, IOContext io_context)
static void ForgetPrivateRefCountEntry(PrivateRefCountEntry *ref)
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 Buffer ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy, bool *hit)
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)
struct PrivateRefCountEntry PrivateRefCountEntry
struct CkptTsStatus CkptTsStatus
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
uint32 LockBufHdr(BufferDesc *desc)
static void ResOwnerReleaseBufferPin(Datum res)
static struct PrivateRefCountEntry PrivateRefCountArray[REFCOUNT_ARRAY_ENTRIES]
static int SyncOneBuffer(int buf_id, bool skip_recently_used, WritebackContext *wb_context)
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
static HTAB * PrivateRefCountHash
static int32 PrivateRefCountOverflowed
bool ConditionalLockBufferForCleanup(Buffer buffer)
int bgwriter_lru_maxpages
static void WaitIO(BufferDesc *buf)
void FlushOneBuffer(Buffer buffer)
#define BUFFER_LOCK_UNLOCK
#define BUFFER_LOCK_SHARE
static Page BufferGetPage(Buffer buffer)
#define DEFAULT_EFFECTIVE_IO_CONCURRENCY
#define BMR_SMGR(p_smgr, p_relpersistence)
#define DEFAULT_MAINTENANCE_IO_CONCURRENCY
@ EB_CREATE_FORK_IF_NEEDED
#define BUFFER_LOCK_EXCLUSIVE
@ RBM_ZERO_AND_CLEANUP_LOCK
static bool BufferIsValid(Buffer bufnum)
bool PageIsVerifiedExtended(Page page, BlockNumber blkno, int flags)
void PageSetChecksumInplace(Page page, BlockNumber blkno)
char * PageSetChecksumCopy(Page page, BlockNumber blkno)
static bool PageIsNew(Page page)
static void PageSetLSN(Page page, XLogRecPtr lsn)
static XLogRecPtr PageGetLSN(Page page)
#define MemSet(start, val, len)
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)
static void PGresult const char * p2
static void PGresult * res
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
void * hash_seq_search(HASH_SEQ_STATUS *status)
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
int errdetail(const char *fmt,...)
ErrorContextCallback * error_context_stack
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
int StrategySyncStart(uint32 *complete_passes, uint32 *num_buf_alloc)
BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype)
BufferDesc * StrategyGetBuffer(BufferAccessStrategy strategy, uint32 *buf_state, bool *from_ring)
void FreeAccessStrategy(BufferAccessStrategy strategy)
IOContext IOContextForStrategy(BufferAccessStrategy strategy)
void StrategyFreeBuffer(BufferDesc *buf)
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)
if(TABLE==NULL||TABLE_index==NULL)
static volatile sig_atomic_t waiting
Assert(fmt[strlen(fmt) - 1] !='\n')
void LockRelationForExtension(Relation relation, LOCKMODE lockmode)
void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode)
void UnpinLocalBuffer(Buffer buffer)
BufferDesc * LocalBufferAlloc(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum, bool *foundPtr)
void AtEOXact_LocalBuffers(bool isCommit)
void DropRelationLocalBuffers(RelFileLocator rlocator, ForkNumber forkNum, BlockNumber firstDelBlock)
void AtProcExit_LocalBuffers(void)
bool PinLocalBuffer(BufferDesc *buf_hdr, bool adjust_usagecount)
void MarkLocalBufferDirty(Buffer buffer)
void DropRelationAllLocalBuffers(RelFileLocator rlocator)
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)
bool LWLockHeldByMe(LWLock *lock)
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
bool LWLockHeldByMeInMode(LWLock *lock, LWLockMode mode)
void LWLockRelease(LWLock *lock)
bool LWLockConditionalAcquire(LWLock *lock, LWLockMode mode)
void pfree(void *pointer)
void * repalloc(void *pointer, Size size)
#define VALGRIND_MAKE_MEM_DEFINED(addr, size)
#define VALGRIND_MAKE_MEM_NOACCESS(addr, size)
#define START_CRIT_SECTION()
#define CHECK_FOR_INTERRUPTS()
#define END_CRIT_SECTION()
#define ERRCODE_DATA_CORRUPTED
static PgChecksumMode mode
#define WRITEBACK_MAX_PENDING_FLUSHES
#define DEFAULT_BACKEND_FLUSH_AFTER
#define DEFAULT_CHECKPOINT_FLUSH_AFTER
#define DEFAULT_BGWRITER_FLUSH_AFTER
#define pgstat_count_buffer_read(rel)
#define pgstat_count_buffer_hit(rel)
PgStat_BgWriterStats PendingBgWriterStats
PgStat_CheckpointerStats PendingCheckpointerStats
instr_time pgstat_prepare_io_time(bool track_io_guc)
void pgstat_count_io_op_time(IOObject io_object, IOContext io_context, IOOp io_op, instr_time start_time, uint32 cnt)
void pgstat_count_io_op(IOObject io_object, IOContext io_context, IOOp io_op)
#define qsort(a, b, c, d)
static Datum PointerGetDatum(const void *X)
static Pointer DatumGetPointer(Datum X)
static int32 DatumGetInt32(Datum X)
#define NUM_AUXILIARY_PROCS
#define DELAY_CHKPT_START
#define INVALID_PROC_NUMBER
void ProcessProcSignalBarrier(void)
@ PROCSIG_RECOVERY_CONFLICT_BUFFERPIN
void set_ps_display_remove_suffix(void)
void set_ps_display_suffix(const char *suffix)
char * psprintf(const char *fmt,...)
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 ResourceOwnerForgetBufferIO(ResourceOwner owner, Buffer buffer)
void ResourceOwnerForgetBuffer(ResourceOwner owner, Buffer buffer)
void ResourceOwnerRememberBuffer(ResourceOwner owner, Buffer buffer)
void ResourceOwnerRememberBufferIO(ResourceOwner owner, Buffer buffer)
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 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)
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)
static void smgrread(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, void *buffer)
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(ProcSignalReason reason, TimestampTz wait_start, TimestampTz now, VirtualTransactionId *wait_list, bool still_waiting)
bool RelFileLocatorSkippingWAL(RelFileLocator rlocator)
SMgrRelation RelationCreateStorage(RelFileLocator rlocator, char relpersistence, bool register_delete)
void log_smgrcreate(const RelFileLocator *rlocator, ForkNumber forkNum)
int wait_backend_pgprocno
struct SMgrRelationData * smgr
int64 shared_blks_dirtied
int64 shared_blks_written
struct ErrorContextCallback * previous
void(* callback)(void *arg)
PgStat_Counter buf_written_clean
PgStat_Counter maxwritten_clean
PgStat_Counter buffers_written
RelFileLocator rd_locator
BlockNumber smgr_cached_nblocks[MAX_FORKNUM+1]
RelFileLocatorBackend smgr_rlocator
PendingWriteback pending_writebacks[WRITEBACK_MAX_PENDING_FLUSHES]
static uint64 table_relation_size(Relation rel, ForkNumber forkNumber)
bool RecoveryInProgress(void)
bool XLogNeedsFlush(XLogRecPtr record)
CheckpointStatsData CheckpointStats
void XLogFlush(XLogRecPtr record)
#define CHECKPOINT_END_OF_RECOVERY
#define CHECKPOINT_FLUSH_ALL
#define CHECKPOINT_IS_SHUTDOWN
#define XLogHintBitIsNeeded()
#define XLogRecPtrIsInvalid(r)
#define InvalidXLogRecPtr
XLogRecPtr XLogSaveBufferForHint(Buffer buffer, bool buffer_std)
XLogRecPtr log_newpage_buffer(Buffer buffer, bool page_std)