39#define LocalBufHdrGetBlock(bufHdr) \
40 LocalBufferBlockPointers[-((bufHdr)->buf_id + 2)]
151 bufid = -victim_buffer - 1;
157 elog(
ERROR,
"local buffer hash table corrupted");
163 bufHdr->
tag = newTag;
217 else if (--trycounter == 0)
219 (
errcode(ERRCODE_INSUFFICIENT_RESOURCES),
220 errmsg(
"no empty local buffer available")));
261 buf_state &= ~BM_DIRTY;
277 elog(
ERROR,
"local buffer hash table corrupted");
294 if (*additional_pins <= 1)
304 if (*additional_pins >= max_pins)
305 *additional_pins = max_pins;
340 MemSet((
char *) buf_block, 0, BLCKSZ);
352 Assert(first_block <= extend_upto);
354 Assert((
uint64) first_block + extend_by <= extend_upto);
360 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
361 errmsg(
"cannot extend relation %s beyond %u blocks",
373 victim_buf_id = -buffers[
i] - 1;
397 buf_state &= ~BM_VALID;
406 victim_buf_hdr->
tag = tag;
412 hresult->
id = victim_buf_id;
422 io_start, extend_by);
437 *extended_by = extend_by;
458 fprintf(stderr,
"LB DIRTY %d\n", buffer);
508 elog(
ERROR,
"block %u of %s is still referenced (local %u)",
519 elog(
ERROR,
"local buffer hash table corrupted");
522 buf_state &= ~BUF_FLAG_MASK;
523 buf_state &= ~BUF_USAGECOUNT_MASK;
553 elog(
ERROR,
"block %u of %s is still referenced (local %u)",
563 elog(
ERROR,
"local buffer hash table corrupted");
566 buf_state &= ~BUF_FLAG_MASK;
567 buf_state &= ~BUF_USAGECOUNT_MASK;
596 (
errcode(ERRCODE_INVALID_TRANSACTION_STATE),
597 errmsg(
"cannot access temporary tables during a parallel operation")));
605 (
errcode(ERRCODE_OUT_OF_MEMORY),
606 errmsg(
"out of memory")));
611 for (
i = 0;
i < nbufs;
i++)
621 buf->buf_id = -
i - 2;
641 elog(
ERROR,
"could not initialize local buffer hash table");
659 int bufid = -buffer - 1;
666 if (adjust_usagecount &&
690 int buffid = -buffer - 1;
712 GUC_check_errdetail(
"\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
730 static char *cur_block = NULL;
731 static int next_buf_in_block = 0;
732 static int num_bufs_in_block = 0;
733 static int total_bufs_allocated = 0;
740 if (next_buf_in_block >= num_bufs_in_block)
750 if (LocalBufferContext == NULL)
753 "LocalBufferContext",
757 num_bufs =
Max(num_bufs_in_block * 2, 16);
768 next_buf_in_block = 0;
769 num_bufs_in_block = num_bufs;
773 this_buf = cur_block + next_buf_in_block * BLCKSZ;
775 total_bufs_allocated++;
777 return (
Block) this_buf;
788#ifdef USE_ASSERT_CHECKING
791 int RefCountErrors = 0;
802 elog(
WARNING,
"local buffer refcount leak: %s", s);
808 Assert(RefCountErrors == 0);
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)
#define InvalidBlockNumber
#define BufferIsLocal(buffer)
#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 bool BufferTagsEqual(const BufferTag *tag1, const BufferTag *tag2)
static bool BufTagMatchesRelFileLocator(const BufferTag *tag, const RelFileLocator *rlocator)
#define BUF_STATE_GET_USAGECOUNT(state)
static void ClearBufferTag(BufferTag *tag)
static void ResourceOwnerRememberBuffer(ResourceOwner owner, Buffer buffer)
static void ResourceOwnerForgetBuffer(ResourceOwner owner, Buffer buffer)
#define BUF_USAGECOUNT_ONE
static RelFileLocator BufTagGetRelFileLocator(const BufferTag *tag)
static BufferDesc * GetLocalBufferDescriptor(uint32 id)
static Buffer BufferDescriptorGetBuffer(const BufferDesc *bdesc)
char * DebugPrintBufferRefcount(Buffer buffer)
void PageSetChecksumInplace(Page page, BlockNumber blkno)
#define TYPEALIGN(ALIGNVAL, LEN)
#define Assert(condition)
#define MemSet(start, val, len)
#define fprintf(file, fmt, msg)
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)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define GUC_check_errdetail
#define IsParallelWorker()
BufferUsage pgBufferUsage
void UnpinLocalBuffer(Buffer buffer)
static HTAB * LocalBufHash
static int NLocalPinnedBuffers
void AtEOXact_LocalBuffers(bool isCommit)
#define LocalBufHdrGetBlock(bufHdr)
static void CheckForLocalBufferLeaks(void)
void DropRelationLocalBuffers(RelFileLocator rlocator, ForkNumber forkNum, BlockNumber firstDelBlock)
static Block GetLocalBufferStorage(void)
static int nextFreeLocalBufId
bool check_temp_buffers(int *newval, void **extra, GucSource source)
void AtProcExit_LocalBuffers(void)
bool PinLocalBuffer(BufferDesc *buf_hdr, bool adjust_usagecount)
static void InitLocalBuffers(void)
void LimitAdditionalLocalPins(uint32 *additional_pins)
static Buffer GetLocalVictimBuffer(void)
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)
Block * LocalBufferBlockPointers
void UnpinLocalBufferNoOwner(Buffer buffer)
BufferDesc * LocalBufferDescriptors
BufferDesc * LocalBufferAlloc(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum, bool *foundPtr)
void * MemoryContextAlloc(MemoryContext context, Size size)
void pfree(void *pointer)
MemoryContext TopMemoryContext
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
static rewind_source * source
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 relpath(rlocator, forknum)
#define relpathbackend(rlocator, backend, forknum)
ResourceOwner CurrentResourceOwner
void ResourceOwnerEnlarge(ResourceOwner owner)
BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum)
SMgrRelation smgropen(RelFileLocator rlocator, ProcNumber backend)
void smgrzeroextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nblocks, bool skipFsync)
bool smgrprefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nblocks)
static void smgrwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void *buffer, bool skipFsync)
struct SMgrRelationData * smgr
RelFileLocatorBackend smgr_rlocator